Last active
December 20, 2018 09:33
-
-
Save raecoo/931474f794990d1bf63a67d16cb5949e to your computer and use it in GitHub Desktop.
checkpoint.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: UTF-8 -*- | |
import requests | |
import json | |
def generate_header(url): | |
import hashlib | |
hash_object = hashlib.sha1(url + 'conviva95a') | |
return {'Authorization': 'Bearer ' + hash_object.hexdigest()} | |
stages = { | |
# 'local': 'http://localhost:5000/v%(version)s/customers/%(customer)s', | |
'dev': 'https://5twvbk64l3.execute-api.us-east-1.amazonaws.com/%(stage)s/v%(' | |
'version)s/customers/%(customer)s', | |
# 'staging': 'https://7vwpr392j1.execute-api.us-east-1.amazonaws.com/', | |
} | |
# segment isn’t in here until the segment feature released | |
target_fields = ['brand', 'day_part', 'content_type', 'segment_name', 'device', 'dma', | |
'country', 'day_of_week', 'content'] | |
# target_fields = ['brand'] | |
associate_fields = { | |
'turner_tbs_tnt': { | |
'state': { | |
'associate_key': 'country', | |
'associate_value': 'united%20states', | |
}, | |
'custom_tag_value': { | |
'associate_key': 'custom_tag_name', | |
'associate_value': 'freeview', | |
} | |
}, | |
'hulu': { | |
'state': { | |
'associate_key': 'country', | |
'associate_value': 'united%20states', | |
}, | |
'custom_tag_value': { | |
'associate_key': 'custom_tag_name', | |
'associate_value': 'isLiveSubscriber', | |
} | |
}, | |
} | |
dev_endpoint_base_url = "/%(customer)s/suggestions/%(field)s" % { | |
'customer': 'hulu', 'field': 'test', 'other': 'ss'} | |
customer_with_params = { | |
'turner_tbs_tnt': {'customer': 'turner_tbs_tnt'}, | |
'hulu': {'customer': 'hulu', 'custom_tag_name': ''}, | |
} | |
api_endpoints = ['/suggestions/'] | |
for stage, base_url in stages.items(): | |
for customer, params in customer_with_params.items(): | |
for field in target_fields: | |
for api in api_endpoints: | |
params['stage'] = stage | |
params['version'] = 1 | |
request_url = (base_url + api + field) % params | |
headers = generate_header(request_url) | |
resp = requests.get(url=request_url, headers=headers) | |
curl_params = {'url': request_url, 'token': headers.get('Authorization')} | |
print('\n') | |
print "CMD: curl -X GET \"%(url)s\" -H 'Authorization: %(token)s'" % curl_params | |
if resp.status_code == 200: | |
print(json.dumps(resp.json(), sort_keys=True, indent=2)) | |
else: | |
print resp.status_code, resp.json() |
Author
raecoo
commented
Dec 20, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment