-
Notifications
You must be signed in to change notification settings - Fork 1
/
atomtest.py
75 lines (59 loc) · 2.44 KB
/
atomtest.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
import requests
import csv
def fcnparse_opendays(stringopendays):
print(stringopendays)
def fcnparse_siteaddress(full_address):
tmp = full_address.split(', ')
address = full_address#tmp[0]
city = ""#tmp[1]
tmp2 = ""#tmp[2].split(' ')
state = ""#tmp2[0]
zipcode = ""#tmp2[1]
return address, city, state, zipcode
def fcnparse_opendays(attributesOPENDAYS):
return ["Monday","Tuesday","Thursday"]
import requests
import csv
post_url_services = 'https://api.airtable.com/v0/applQOkth8R2ns3qo/services'
post_url_organizations = 'https://api.airtable.com/v0/applQOkth8R2ns3qo/organizations'
post_url_address = 'https://api.airtable.com/v0/applQOkth8R2ns3qo/address'
post_url_schedule = 'https://api.airtable.com/v0/applQOkth8R2ns3qo/schedule'
post_headers = {
'Authorization' : 'Bearer keyFaCMgt8zX71GnJ',
'Content-Type': 'application/json'
}
f = open('/Users/Ashwin/Documents/BAC/20200919cfsj/Santa Clara Scrape 10_1 - Food School Meal Sites .csv')
csv_f = csv.reader(f)
#Skip header row
count = 1
for row in csv_f:
if count == 1:
break
count = 1
for row in csv_f:
#print(row)
rowcount = 0
for elem in row:
print(rowcount, elem)
rowcount = rowcount+1
#Parse attributes.SITESCHOOLDISTRICT
attributesSITESCHOOLDISTRICT = row[4]
airtableSITESCHOOLDISTRICT = {"fields": {"name": attributesSITESCHOOLDISTRICT}}
print((requests.post(post_url_organizations, headers = post_headers, json = airtableSITESCHOOLDISTRICT)).status_code)
#Parse attributes.SITENAME
attributesSITENAME = row[5]
airtableSITENAME = {"fields": {"Name": attributesSITENAME}}
print((requests.post(post_url_services, headers = post_headers, json = airtableSITENAME)).status_code)
#Parse attributes.SITEADDRESS
attributesSITEADDRESS = row[5]
address, city, state, zipcode = fcnparse_siteaddress(attributesSITEADDRESS)
print(address, city, state, zipcode)
airtableSITEADDRESS = {"fields": {"address_1": address,"city": city,"State": state,"Zip Code": zipcode}}
print((requests.post(post_url_address, headers = post_headers, json = airtableSITEADDRESS)).status_code)
#Parse attributes.OPENDAYS
attributesOPENDAYS = row[6]
opendays = fcnparse_opendays(attributesOPENDAYS)
airtableOPENDAYS = {"fields": {"weekday": opendays}}
print((requests.post(post_url_schedule, headers = post_headers, json = airtableOPENDAYS)).status_code)
if count == 1:
break