-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.py
71 lines (53 loc) · 2.2 KB
/
task.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
##############################
#### QR Code URL Hydrator ####
##############################
## Goes through all records in airtable & picks URL per template ##
## Will expand as more services are added ##
##############
## Ticket: https://www.notion.so/automedia/QR-Code-Hydration-Service-46e18bcb859f4a9d9a83393b634087d1
#############
## Declarations
import os
from airtable import Airtable
# Airtable settings
base_key = os.environ.get("PRIVATE_BASE_KEY")
table_name_producer = os.environ.get("PRIVATE_TABLE_NAME_PRODUCER")
table_name_jasp = os.environ.get("PRIVATE_TABLE_NAME_JASP")
api_key = os.environ.get("PRIVATE_API_KEY")
airtable_producer = Airtable(base_key, table_name_producer, api_key) #For production env
airtable_jasp = Airtable(base_key, table_name_jasp, api_key) #For production env
#Airtable variables so if name changes will be easy to update here
URLColumnSourceCard = "Sourcecard_URL"
URLColumnJasp = "jasp_info_url"
# Individual functions for each service type
def url_amEmbed(airtableRow):
payload = airtableRow["fields"]["payload"]
return payload
def url_amJasp(airtableRow):
jaspRecID = airtableRow["fields"]["JASP_payload"][0]
jaspPayload = airtable_jasp.get(jaspRecID)["fields"][URLColumnJasp]
return jaspPayload
def url_amData(airtableRow):
dataURL = 'https://www.worldometers.info/coronavirus/' #Hard coded for now
return dataURL
# Main loop that runs through all records
def updateLoop(colToUpdate = URLColumnSourceCard):
allRecords = airtable_producer.get_all() #get all data
for i in allRecords:
if "Prod_Ready" in i["fields"]: #Only working on prod ready ie checkboxed
service = i["fields"]["am_Service"][0].lower() #Gives first service ie data pull
rec_ofAsked = i["id"]
# Getting different URLs per template type
if service == 'am_embed':
urlToUpdate = url_amEmbed(i)
elif service == 'am_jasp':
urlToUpdate = url_amJasp(i)
elif service == 'am_data':
urlToUpdate = url_amData(i)
# else:
# urlToUpdate = '' #Need some error raising here later
# Preparing to upload
# print('URL to update', urlToUpdate)
fields = {colToUpdate: urlToUpdate}
airtable_producer.update(rec_ofAsked, fields)
updateLoop()