-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathread_batch.py
44 lines (38 loc) · 1.34 KB
/
read_batch.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
import requests
import pandas as pd
from pprint import pprint
from class_token import JWEToken, BearerToken
jwe = JWEToken()
jwe.import_local('jwe.json')
bearer = BearerToken()
bearer.import_local('bearer.json')
def get_batches():
url = 'https://www.connectedcooking.com/api/haccps'
token = bearer.token
scope = bearer.scope
headers = {'Authorization': 'Bearer ' + token,
'scope': scope}
parameters = {'finished': 'true',
'sort': 'startDate,desc',
'page': 0}
with requests.Session() as sess:
sess.headers.update(headers)
r = requests.Request(method='GET',
url=url,
data=parameters)
prepped = sess.prepare_request(r)
response = sess.send(prepped)
return {'response': response.status_code,
'details': {'url': url,
'request_headers': dict(prepped.headers),
'request_body': prepped.body},
'batches': response.json()}
if __name__ == '__main__':
batches = get_batches()
pprint(batches.get('request_headers'))
pprint(batches.get('request_body'))
print(batches.get('response'))
test = pd.DataFrame(batches.get('batches'))
print(test.shape)
print(test.head())
test.to_csv('test_csv.csv', index=False)