· 5 years ago · Oct 14, 2019, 05:32 PM
1import requests
2import json
3import pandas as pd
4import numpy as np
5from pandas import Series,DataFrame
6
7import sys
8
9if sys.version_info < (3,):
10 def u(x):
11 try:
12 return x.encode("utf8")
13 except UnicodeDecodeError:
14 return x
15else:
16 def u(x):
17 if type(x) == type(b''):
18 return x.decode('utf8')
19 else:
20 return x
21
22token = 'AQAAAAABICwvAADtAOwL0hPVsU1um5erAMR73nI'
23
24fromDate = '8-09-2019'
25toDate = '10-09-2019'
26
27url = 'https://api.partner.market.yandex.ru/v2/campaigns/21131205/stats/main.json?fromDate=' + fromDate + '&toDate=' + toDate
28
29client_id = '61a29aeaecb74f7cb3fbc5cb65e92b4b'
30
31headers = {
32 'Authorization': 'OAuth oauth_token=' + token + ', oauth_client_id=' + client_id,
33 }
34
35r = requests.get(url, headers=headers)
36
37
38
39data = r.text
40
41df = pd.read_json(data)
42
43print(df)