-
Notifications
You must be signed in to change notification settings - Fork 2
/
processSheet.py
68 lines (56 loc) · 2.6 KB
/
processSheet.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
## need to import the relevant files
import argparse
import yaml
from src import handle_files, process_data, make_requests
import sys
import string
with open("config.yml", 'r') as stream:
config = yaml.safe_load(stream)
def processArgs():
try:
parser = argparse.ArgumentParser()
parser.add_argument('--itemFile', required=True, help='File you want to process')
parser.add_argument('--operation', required=True, choices=['getCurrentOCLCNumbers', 'retrieveMergedOCLCNumbers', 'setHoldingsbyOCLCNumber', 'deleteHoldingsbyOCLCNumber', 'addLBDs', 'getLatestEdition'], help='Operation to run: getCurrentOCLCNumbers, retrieveMergedOCLCNumbers, setHoldingsbyOCLCNumber, deleteHoldingsbyOCLCNumber, addLBDs')
parser.add_argument('--outputDir', required=True, help='Directory to save output to')
args = parser.parse_args()
except SystemExit:
raise
def process(args):
item_file = handle_files.readFileFromLocal(args.itemFile)
operation = args.operation
output_dir = args.outputDir
# get a token
scope = ['WorldCatMetadataAPI']
try:
oauth_session = make_requests.createOAuthSession(config, scope)
config.update({"oauth-session": oauth_session})
processConfig = config
csv_read = handle_files.loadCSV(item_file)
if operation == "getCurrentOCLCNumbers":
csv_read = process_data.retrieveCurrentOCLCNumbers(processConfig, csv_read)
elif operation == "retrieveMergedOCLCNumbers":
csv_read = process_data.retrieveMergedOCLCNumbers(processConfig, csv_read)
elif operation == "setHoldingsbyOCLCNumber":
csv_read = process_data.setHoldingsbyOCLCNumber(processConfig, csv_read)
elif operation == "deleteHoldingsbyOCLCNumber":
csv_read = process_data.deleteHoldingsbyOCLCNumber(processConfig, csv_read)
elif operation == "addLBDs":
csv_read = process_data.addLBDs(processConfig, csv_read)
elif operation == "getLatestEdition":
csv_read = process_data.getLatestEdition(processConfig, csv_read)
return handle_files.saveFileLocal(csv_read, output_dir)
except BaseException as err:
result = 'no access token ' + str(err)
return result
if __name__ == '__processSheet__':
try:
args = processArgs()
print(process(args))
except SystemExit:
print("Invalid Operation specified")
else:
try:
args = processArgs()
print(process(args))
except SystemExit:
print("Invalid Operation specified")