-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAioCentralBankRuApi.py
44 lines (37 loc) · 1.19 KB
/
AioCentralBankRuApi.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
36
37
38
39
40
41
42
43
44
import aiohttp
from typing import Dict
class CenterBankApi:
"""
class implements api cbr
"""
def __init__(self, session: aiohttp.ClientSession) -> None:
self.link = "https://www.cbr-xml-daily.ru/daily_json.js"
self.obj = dict()
self.date: str = ""
self.session: aiohttp.ClientSession = session
async def get_json(self) -> Dict[str, Dict[str, str]]:
"""
get json from https://www.cbr-xml-daily.ru/daily_json.js
:return:
"""
async with self.session.get(self.link) as response:
return await response.json(content_type=None, encoding="utf-8")
async def build_list_coin(self) -> Dict[str, Dict[str, str]]:
"""
build dict from json
:return:
"""
response: Dict[str, Dict[str, str]] = await self.get_json()
self.date: str = response['Date']
for i in response["Valute"].items():
self.obj[i[0]] = {
"name": i[1]["Name"],
"valvue": i[1]["Value"]
}
return self.obj
def __len__(self) -> int:
"""
return len available coin
:return:
"""
return len(self.obj)