-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
28 lines (25 loc) · 947 Bytes
/
utils.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
import urllib
import logging
import json
import requests
import os
if 'HEROKU' not in os.environ:
# authentication data
with open('auth_data.json', 'r') as fh:
auth_data = json.loads(fh.read())
client_auth_data = auth_data["client_auth_data"]
else:
client_auth_data = {}
client_auth_data['client_id'] = os.environ['CLIENT_ID']
client_auth_data['client_secret'] = os.environ['CLIENT_SECRET']
def authed_fetch(url, headers={}):
headers.update({'X-Admin-Contact': '[email protected]'})
url += '?' + urllib.parse.urlencode(client_auth_data)
r = requests.get(url=url, headers=headers)
if 'x-ratelimit-remaining' in r.headers.keys():
logging.info('{} requests remaining for this hour.'.format(
r.headers['x-ratelimit-remaining']))
else:
logging.info('Request remaing for hour could not determined')
logging.info(r.content)
return r