Skip to content

Instantly share code, notes, and snippets.

@glader
Last active March 27, 2018 07:01
Show Gist options
  • Save glader/27ebc4ac684158909b5ec8088f66ebc3 to your computer and use it in GitHub Desktop.
Save glader/27ebc4ac684158909b5ec8088f66ebc3 to your computer and use it in GitHub Desktop.
import requests
from urllib import urlencode
token = 'AQAA...'
ids = (
(554433, 'site1.ru'),
(334455, 'site2.ru'),
(443356, 'site3.ru'),
)
params = (
('oauth_token', token),
('metrics', 'ym:s:visits'),
('dimensions', 'ym:s:month'),
('date1', '2018-02-01'),
('date2', '2018-02-28'),
)
for i, host in ids:
p = list(params)
p.append(['ids', i])
url = 'https://api-metrika.yandex.ru/stat/v1/data?' + urlencode(p)
print host,
response = requests.get(url)
print response.json()['totals'][0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment