Created
March 1, 2019 19:15
-
-
Save supsailor/bd7fce6e981de48f670efb7297faba90 to your computer and use it in GitHub Desktop.
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
| import requests | |
| app_id = '3d344fd907f547d0b3d34014bfd7659b' | |
| app_password = '3a7cd5e6ca8545d29f37ad94ab8408de' | |
| oauth_token = 'AQAAAAAo4ZEPAAVUTiN9vwEfPEzGoaWgy2SU2i0' | |
| counter_id = '46337109' # ID счетчика | |
| url = "https://api-metrika.yandex.net/stat/v1/data" | |
| querystring = {"ids": "46337109", "metrics": "ym:s:users,ym:s:ecommercePurchases,ym:s:ecommerceRevenue", | |
| "dimensions": "ym:s:UTMSource", "date1": "yesterday", "date2": "yesterday", "group": "day", | |
| "pretty": "true", "filters": "ym:s:UTMSource=='mindbox'"} | |
| payload = "" | |
| headers = { | |
| 'Authorization': "Bearer AQAAAAAo4ZEPAAVUTiN9vwEfPEzGoaWgy2SU2i0", | |
| 'cache-control': "no-cache", | |
| 'Postman-Token': "978bd224-5113-4e52-87ca-6dd1053a9364" | |
| } | |
| response = requests.request("GET", url, data=payload, headers=headers, params=querystring) | |
| data = response.json() | |
| line = data.get('data') | |
| key = 'metrics' | |
| for key in line: | |
| metrics = key['metrics'] | |
| traffic = metrics[0] | |
| orders = metrics[1] | |
| revenue = metrics[2] | |
| print(response.text) | |
| f = open('log.txt', 'a', encoding='utf-8') | |
| f.write(str(line) + '\n') | |
| f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment