Skip to content

Instantly share code, notes, and snippets.

@bunyk
Created October 31, 2017 15:08
Show Gist options
  • Save bunyk/b696bcde8d13bc467766586e4077c586 to your computer and use it in GitHub Desktop.
Save bunyk/b696bcde8d13bc467766586e4077c586 to your computer and use it in GitHub Desktop.
import requests
import json
events = [{
"timestamp": "0",
"type": "show",
"version": "v1",
"payload": {
"id": "556caec66b66d16536079e43",
"action": "make",
"clientAttributes": {
"browser": {
"name": "Python",
"version": "3.5",
},
"device": {
"brand": "string;required",
"manufacturer": "string;required",
"model": "string;required",
"version": "string;required",
},
"os": {
"name": "android",
"version": "16.04",
},
"type": "string;required",
"id": "string",
"advertisingId": "string",
"userId": "string",
},
"productAttributes": {
"name": "velgo",
"version": "string;required",
"buildNumber": "string;required",
},
}
}]
print(json.dumps(events))
# curl -D - "https://login.discovery.com.qa-bunyk.i.dsc.tv/v1/oauth2/authorize?client_id=client2&state=something&redirect_uri=https://api.discovery.com.qa-bunyk.i.dsc.tv&response_type=anonymous" | grep "access_token"
r = requests.get(
"https://login.discovery.com.qa-bunyk.i.dsc.tv/v1/oauth2/authorize/",
params=dict(
client_id='client2',
state='something',
redirect_uri='https://api.discovery.com.qa-bunyk.i.dsc.tv',
response_type='anonymous',
),
allow_redirects=False
)
redirect = r.headers['Location']
h = redirect.split('#')[1]
params = dict(i.split('=') for i in h.split('&'))
token = params['access_token']
# curl -X POST -H "Content-Type: application/json" -g -d '<events>' -H "Authorization: Bearer <access_token>" http://qa-bunyk.i.dsc.tv:1187/v1/events
r = requests.post(
'http://qa-bunyk.i.dsc.tv:1187/v1/events',
json=events,
headers={
'Authorization': 'Bearer %s' % token
}
)
print(r.text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment