-
Notifications
You must be signed in to change notification settings - Fork 2
/
handler.py
60 lines (46 loc) · 2.56 KB
/
handler.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
import yaml
import os
from src import handle_files, process_data, make_requests
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
# load key/secret config info
# read a configuration file
with open("config.yml", 'r') as stream:
config = yaml.safe_load(stream)
# get a token
scope = ['WorldCatMetadataAPI']
oauth_session = make_requests.createOAuthSession(config, scope)
processConfig = config.update({"oauth-session": oauth_session})
def getCurrentOCLCNumbers(event, context):
item_file = handle_files.readFilesFromBucket(event)
csv_read = handle_files.loadCSV(item_file)
csv_read = process_data.retrieveCurrentOCLCNumbers(processConfig, csv_read)
handle_files.saveFileToBucket(fileInfo['bucket'], fileInfo['key'] + "_updated", csv_read)
def getMergedOCLCNumbers(event, context):
item_file = handle_files.readFilesFromBucket(event)
csv_read = handle_files.loadCSV(item_file)
csv_read = process_data.retrieveMergedOCLCNumbers(processConfig, csv_read)
handle_files.saveFileToBucket(fileInfo['bucket'], fileInfo['key'] + "_updated", csv_read)
def setHoldingsbyOCLCNumber(event, context):
item_file = handle_files.readFilesFromBucket(event)
csv_read = handle_files.loadCSV(item_file)
csv_read = process_data.setHoldingsbyOCLCNumber(processConfig, csv_read)
handle_files.saveFileToBucket(fileInfo['bucket'], fileInfo['key'] + "_updated", csv_read)
return saveFile(bucket, key + "_updated", csv_read)
def deleteHoldingsbyOCLCNumber(event, context):
item_file = handle_files.readFilesFromBucket(event)
csv_read = handle_files.loadCSV(item_file)
csv_read = process_data.deleteHoldingsbyOCLCNumber(processConfig, csv_read)
handle_files.saveFileToBucket(fileInfo['bucket'], fileInfo['key'] + "_updated", csv_read)
return saveFile(bucket, key + "_updated", csv_read)
def addLBDs(event, context):
item_file = handle_files.readFilesFromBucket(event)
csv_read = handle_files.loadCSV(item_file)
csv_read = process_data.addLBDs(processConfig, csv_read)
handle_files.saveFileToBucket(fileInfo['bucket'], fileInfo['key'] + "_updated", csv_read)
return saveFile(bucket, key + "_updated", csv_read)
def getLatestEdition(event, context):
item_file = handle_files.readFilesFromBucket(event)
csv_read = handle_files.loadCSV(item_file)
csv_read = process_data.getLatestEdition(processConfig, csv_read)
handle_files.saveFileToBucket(fileInfo['bucket'], fileInfo['key'] + "_updated", csv_read)
return saveFile(bucket, key + "_updated", csv_read)