Skip to content

Instantly share code, notes, and snippets.

@schunlee
Created January 31, 2019 03:27
Show Gist options
  • Save schunlee/793e30ab57d889e39cd789f8db231df7 to your computer and use it in GitHub Desktop.
Save schunlee/793e30ab57d889e39cd789f8db231df7 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import requests
__author__ = "bill.li"
def login(username, password):
auth_url = "https://dashapi.chartboost.com/v3/login"
session = requests.Session()
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "Mozilla/5.0 (Linux; U; Android 8.0.0; zh-cn; LLD-AL00 Build/HONORLLD-AL00) AppleWebKit/537.36 (KHTML, like Gecko) MQQBrowser/7.3 Chrome/37.0.0.0 Mobile Safari/537.36"}
payload = {"email": username,
"password": password,
}
session.request('POST', auth_url, data=payload, headers=headers).json()
cookie_obj = session.cookies
cookie_list = list()
for key, value in requests.utils.dict_from_cookiejar(cookie_obj).iteritems():
cookie_list.append('{}={}'.format(key, value))
cookie = '; '.join(cookie_list)
headers.update({"Cookie": cookie,
})
return headers
if __name__ == '__main__':
# login
headers = login("", "")
# test
resp = requests.get(
"https://analytics.chartboost.com/v3/metrics/company?aggregate=daily&groupBy=date&dateMinWord=lastmonth&dateMaxWord=today&dateMin=2018-12-31&dateMax=2019-01-30",
headers=headers).json()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment