-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
35 lines (23 loc) 路 937 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from fastapi import FastAPI
from requests_html import HTMLSession
app = FastAPI()
@app.get("/yandex_metric_last_week_visits")
async def yandex_metric_last_week_visits(metric_access_token, metric_app_id):
"""
:param metric_access_token: user oauth Yandex Metric token
:param metric_app_id: counter id
:return: json with information about visits on last week
"""
session = HTMLSession()
metrika_headers = {
'GET': '/management/v1/counters HTTP/1.1',
'Host': 'api-metrika.yandex.net',
'Authorization': metric_access_token,
'Content-Type': 'application/x-yametrika+json'
}
metrika_url = f'https://api-metrika.yandex.net/stat/v1/data?metrics=ym:s:visits&id={metric_app_id}'
json_content_response = session.get(metrika_url, headers=metrika_headers).json()
return json_content_response
@app.get("/")
async def root():
return {"message": "Hello World"}