Alan
3 years ago
commit
9abf46002b
27 changed files with 267 additions and 0 deletions
@ -0,0 +1,6 @@ |
|||||||
|
# Course reserves cleanup script |
||||||
|
|
||||||
|
This python script ingests a CSV file as formatted by the LibWizard survey output from the current (12/01/2021) course reserves request survey. It takes the ingested data and splits up the requests to include only one item per row while maintaining the data of the item's requestor. Columns are also added for human post-processing of the data. |
||||||
|
|
||||||
|
The current version of the script does not allow for flexible outputs, nor does it have a GUI. |
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,103 @@ |
|||||||
|
import csv |
||||||
|
import re |
||||||
|
|
||||||
|
# current working script, runs from command line only |
||||||
|
|
||||||
|
def create_row(raw_input_row_list, extra_item_number, extra_item_index_dict, course_info_list, output_csv_list): |
||||||
|
# creates new row for extra items |
||||||
|
|
||||||
|
new_row = course_info_list.copy() |
||||||
|
# print(course_info_list) |
||||||
|
# print(extra_item_index_dict[extra_item_number + 1]) |
||||||
|
for index in extra_item_index_dict[extra_item_number + 1]: |
||||||
|
|
||||||
|
# print(index) |
||||||
|
# print(new_row) |
||||||
|
item = raw_input_row_list[index] |
||||||
|
# print(item) |
||||||
|
new_row.append(item) |
||||||
|
# print(new_row) |
||||||
|
output_csv_list.append(new_row) |
||||||
|
|
||||||
|
with open ('./report.csv', encoding="utf8") as input_csv: |
||||||
|
input_reader = csv.reader(input_csv, delimiter=',') |
||||||
|
data = list(input_reader) |
||||||
|
|
||||||
|
heading_row = data[0] |
||||||
|
|
||||||
|
extra_item_index_list = [] |
||||||
|
for index, heading in enumerate(data[0]): |
||||||
|
if "Another" in heading: |
||||||
|
extra_item_index_list.append(index) |
||||||
|
|
||||||
|
empty_column_headers = ["Status", "File Name", "Notes"] |
||||||
|
|
||||||
|
course_details_list = ["Length of Reserve", "Full Name", "Course Number", "Course Title"] |
||||||
|
|
||||||
|
item_details = ["Material", "Author", "Title:", "Page", "Chapter"] |
||||||
|
|
||||||
|
course_details_index_list = [] |
||||||
|
|
||||||
|
|
||||||
|
for course_detail in course_details_list: |
||||||
|
for index, heading in enumerate(data[0]): |
||||||
|
if (re.search(course_detail, heading) and (index not in course_details_index_list)): |
||||||
|
course_details_index_list.append(index) |
||||||
|
break |
||||||
|
|
||||||
|
extra_item_index_dict = {} |
||||||
|
item_details_index_list = [] |
||||||
|
|
||||||
|
# need to split up item headings by item number |
||||||
|
# |
||||||
|
for index, heading in enumerate(data[0]): |
||||||
|
for item_detail in item_details: |
||||||
|
# needs handling for #10 |
||||||
|
if (re.search("[1-9]*" + item_detail, heading) and (index not in item_details_index_list) and (index not in course_details_index_list) and ("Journal" not in heading)): |
||||||
|
item_details_index_list.append(index) |
||||||
|
# break |
||||||
|
# extra_item_index_dict.update() |
||||||
|
|
||||||
|
|
||||||
|
# split extra item index ref list into chunks by item and add to dictionary |
||||||
|
x = 0 |
||||||
|
item_number = 1 |
||||||
|
for i in range(x,len(item_details_index_list),len(item_details)): |
||||||
|
x = i |
||||||
|
extra_item_index_dict.update({item_number:item_details_index_list[x:x+5]}) |
||||||
|
item_number += 1 |
||||||
|
|
||||||
|
|
||||||
|
output_csv_list = [] |
||||||
|
output_csv_list.append(empty_column_headers + course_details_list + item_details) |
||||||
|
|
||||||
|
# need to create function for new row/item creation. func must take in course row data along with indices of the next item info and/or the item data in a list. row parsing could be separate from new row creation? |
||||||
|
for row in data[1:]: |
||||||
|
course_info = [] |
||||||
|
new_row_first = [] |
||||||
|
for item in empty_column_headers: |
||||||
|
new_row_first.append("") |
||||||
|
course_info.append("") |
||||||
|
for index in course_details_index_list: |
||||||
|
course_detail = row[index] |
||||||
|
course_info.append(course_detail) |
||||||
|
new_row_first.append(course_detail) |
||||||
|
# for index in extra_item_index_dict[1]: |
||||||
|
# new_row_first.append(row[index]) |
||||||
|
# print(new_row_first) |
||||||
|
for extra_item_number, extra_item in enumerate(extra_item_index_list): |
||||||
|
if row[extra_item] == "Yes": |
||||||
|
# print(extra_item_number) |
||||||
|
create_row(row, extra_item_number, extra_item_index_dict, course_info, output_csv_list) |
||||||
|
else: |
||||||
|
break |
||||||
|
# output_csv_list.append(new_row) |
||||||
|
# output_csv_list.append(new_row_first) |
||||||
|
|
||||||
|
# for i in item_details_index_list: |
||||||
|
# print(data[0][i]) |
||||||
|
|
||||||
|
|
||||||
|
with open("./output.csv", "w", encoding="utf8", newline='') as output_file: |
||||||
|
write = csv.writer(output_file) |
||||||
|
write.writerows(output_csv_list) |
@ -0,0 +1,44 @@ |
|||||||
|
# -*- mode: python ; coding: utf-8 -*- |
||||||
|
|
||||||
|
|
||||||
|
block_cipher = None |
||||||
|
|
||||||
|
|
||||||
|
a = Analysis(['version_1.py'], |
||||||
|
pathex=[], |
||||||
|
binaries=[], |
||||||
|
datas=[], |
||||||
|
hiddenimports=[], |
||||||
|
hookspath=[], |
||||||
|
hooksconfig={}, |
||||||
|
runtime_hooks=[], |
||||||
|
excludes=[], |
||||||
|
win_no_prefer_redirects=False, |
||||||
|
win_private_assemblies=False, |
||||||
|
cipher=block_cipher, |
||||||
|
noarchive=False) |
||||||
|
pyz = PYZ(a.pure, a.zipped_data, |
||||||
|
cipher=block_cipher) |
||||||
|
|
||||||
|
exe = EXE(pyz, |
||||||
|
a.scripts, |
||||||
|
[], |
||||||
|
exclude_binaries=True, |
||||||
|
name='version_1', |
||||||
|
debug=False, |
||||||
|
bootloader_ignore_signals=False, |
||||||
|
strip=False, |
||||||
|
upx=True, |
||||||
|
console=True, |
||||||
|
disable_windowed_traceback=False, |
||||||
|
target_arch=None, |
||||||
|
codesign_identity=None, |
||||||
|
entitlements_file=None ) |
||||||
|
coll = COLLECT(exe, |
||||||
|
a.binaries, |
||||||
|
a.zipfiles, |
||||||
|
a.datas, |
||||||
|
strip=False, |
||||||
|
upx=True, |
||||||
|
upx_exclude=[], |
||||||
|
name='version_1') |
@ -0,0 +1,112 @@ |
|||||||
|
import csv |
||||||
|
import re |
||||||
|
import kivy |
||||||
|
kivy.require('2.0.0') |
||||||
|
from kivy.app import App |
||||||
|
from kivy.uix.label import Label |
||||||
|
from kivy.uix.gridlayout import GridLayout |
||||||
|
from kivy.uix.textinput import TextInput |
||||||
|
|
||||||
|
# dirty start to adding a GUI using kivy |
||||||
|
|
||||||
|
class LoginScreen(GridLayout): |
||||||
|
def __init__(self, **kwargs): |
||||||
|
super(LoginScreen, self).__init__(**kwargs) |
||||||
|
self.cols = 2 |
||||||
|
self.add_widget(Label(text='User Name')) |
||||||
|
self.username = TextInput(multiline=False) |
||||||
|
self.add_widget(self.username) |
||||||
|
self.add_widget(Label(text='password')) |
||||||
|
self.password = TextInput(password=True, multiline=False) |
||||||
|
self.add_widget(self.password) |
||||||
|
|
||||||
|
class csv_cleaner(App): |
||||||
|
|
||||||
|
def build(self): |
||||||
|
return LoginScreen() |
||||||
|
|
||||||
|
|
||||||
|
def create_row(raw_input_row_list, extra_item_number, extra_item_index_dict, course_info_list, output_csv_list): |
||||||
|
# creates new row for extra items |
||||||
|
new_row = course_info_list.copy() |
||||||
|
for index in extra_item_index_dict[extra_item_number + 1]: |
||||||
|
item = raw_input_row_list[index] |
||||||
|
new_row.append(item) |
||||||
|
output_csv_list.append(new_row) |
||||||
|
|
||||||
|
with open ('./LWZ_export.csv', encoding="utf8") as input_csv: |
||||||
|
input_reader = csv.reader(input_csv, delimiter=',') |
||||||
|
data = list(input_reader) |
||||||
|
|
||||||
|
heading_row = data[0] |
||||||
|
|
||||||
|
extra_item_index_list = [] |
||||||
|
for index, heading in enumerate(data[0]): |
||||||
|
if "Another" in heading: |
||||||
|
extra_item_index_list.append(index) |
||||||
|
|
||||||
|
empty_column_headers = ["Status", "File Name", "Notes"] |
||||||
|
|
||||||
|
course_details_list = ["Length of Reserve", "Full Name", "Course Number", "Course Title"] |
||||||
|
|
||||||
|
item_details = ["Material", "Author", "Title:", "Page", "Chapter"] |
||||||
|
|
||||||
|
course_details_index_list = [] |
||||||
|
|
||||||
|
|
||||||
|
for course_detail in course_details_list: |
||||||
|
for index, heading in enumerate(data[0]): |
||||||
|
if (re.search(course_detail, heading) and (index not in course_details_index_list)): |
||||||
|
course_details_index_list.append(index) |
||||||
|
break |
||||||
|
|
||||||
|
extra_item_index_dict = {} |
||||||
|
item_details_index_list = [] |
||||||
|
|
||||||
|
# need to split up item headings by item number |
||||||
|
# |
||||||
|
for index, heading in enumerate(data[0]): |
||||||
|
for item_detail in item_details: |
||||||
|
# needs handling for #10 |
||||||
|
if (re.search("[1-9]*" + item_detail, heading) and (index not in item_details_index_list) and (index not in course_details_index_list) and ("Journal" not in heading)): |
||||||
|
item_details_index_list.append(index) |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# split extra item index ref list into chunks by item and add to dictionary |
||||||
|
x = 0 |
||||||
|
item_number = 1 |
||||||
|
for i in range(x,len(item_details_index_list),len(item_details)): |
||||||
|
x = i |
||||||
|
extra_item_index_dict.update({item_number:item_details_index_list[x:x+5]}) |
||||||
|
item_number += 1 |
||||||
|
|
||||||
|
|
||||||
|
output_csv_list = [] |
||||||
|
output_csv_list.append(empty_column_headers + course_details_list + item_details) |
||||||
|
|
||||||
|
# need to create function for new row/item creation. func must take in course row data along with indices of the next item info and/or the item data in a list. row parsing could be separate from new row creation? |
||||||
|
for row in data[1:]: |
||||||
|
course_info = [] |
||||||
|
new_row_first = [] |
||||||
|
for item in empty_column_headers: |
||||||
|
new_row_first.append("") |
||||||
|
course_info.append("") |
||||||
|
for index in course_details_index_list: |
||||||
|
course_detail = row[index] |
||||||
|
course_info.append(course_detail) |
||||||
|
new_row_first.append(course_detail) |
||||||
|
for extra_item_number, extra_item in enumerate(extra_item_index_list): |
||||||
|
if row[extra_item] == "Yes": |
||||||
|
create_row(row, extra_item_number, extra_item_index_dict, course_info, output_csv_list) |
||||||
|
|
||||||
|
else: |
||||||
|
break |
||||||
|
|
||||||
|
with open("./output.csv", "w", encoding="utf8") as output_file: |
||||||
|
write = csv.writer(output_file) |
||||||
|
write.writerows(output_csv_list) |
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__': |
||||||
|
csv_cleaner().run() |
Loading…
Reference in new issue