-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2ProcessOverlapAnalysis.py
103 lines (71 loc) · 2.91 KB
/
2ProcessOverlapAnalysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import pandas as pd
# from tkinter import Tk
# from tkinter.filedialog import askopenfilename
import requests
import sys
sys.path.append('config/')
import secrets_local
import glob
import json
import re
import os
import sys
# # Initialize Tkinter and hide the main window
# Tk().withdraw()
bnf_files = glob.glob("Overlap Analysis Input Directory/*", recursive = True)
bAndN_filename = bnf_files[0]
barnes_and_noble_df_input = pd.read_excel(bAndN_filename, dtype={"ISBN": "str", "ISBN(Matching Identifier)": "str", "ISBN(13)": "str", "MMS ID": "str"}, engine='openpyxl')
courses_url = "https://api-na.hosted.exlibrisgroup.com/almaws/v1/courses?"
api_key = secrets_local.prod_courses_api_key
barnes_and_noble_df_input['course_code'] = ""
barnes_and_noble_df_input['section'] = ""
barnes_and_noble_df_input['course_name'] = ""
barnes_and_noble_df_input['processing_department'] = ""
barnes_and_noble_df = barnes_and_noble_df_input.copy()
for column in barnes_and_noble_df.columns:
barnes_and_noble_df[column] = barnes_and_noble_df[column].astype(str)
#if barnes_and_noble_df[column].dtype == "object":
barnes_and_noble_df[column] = barnes_and_noble_df[column].apply(lambda x: x.replace('"', ''))
#print(barnes_and_noble_df)
x = 0
for index, row in barnes_and_noble_df.iterrows():
# if x == 100:
# break
# print(row)
#
# sys.exit()
semester = row['Term']
if 'F' in semester:
semester = semester.replace('F', 'Fa')
elif 'W' in semester:
semester = semester.replace('W', 'Sp')
request_url = courses_url + "apikey=" + api_key + "&q=name~" + semester + "*" + row['Dept'] + "*" + row['Course'] + "*" + row['Sec'] + "&format=json"
#print(request_url)
response = requests.get(request_url).json()
#print(str(index) + "\t-" + request_url)
try:
course_code = response['course'][0]['code']
except:
course_code = "Error finding course" + json.dumps(response)
try:
section = response['course'][0]['section']
except:
section = "Error finding course" + json.dumps(response)
try:
course_name = response['course'][0]['name']
except:
course_name = "Error finding course" + json.dumps(response)
try:
course_processing_department = response['course'][0]['processing_department']['desc']
except:
course_processing_department = "Error finding processing department: " + json.dumps(response)
barnes_and_noble_df.loc[index, 'course_code'] = course_code
barnes_and_noble_df.loc[index, 'section'] = section
barnes_and_noble_df.loc[index, 'course_name'] = course_name
barnes_and_noble_df.loc[index, 'processing_department'] = course_processing_department
x += 1
oDir = "Barnes and Noble Parsed"
if not os.path.isdir(oDir) or not os.path.exists(oDir):
os.makedirs(oDir)
barnes_and_noble_df.to_excel('Barnes and Noble Parsed/Updated Barnes and Noble.xlsx', index=False)
sys.exit()