-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcrypto_list.py
37 lines (25 loc) · 954 Bytes
/
crypto_list.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
import requests #uvoz biblioteke
import config as cfg #uvoz configuracijskog filea
def punjenje_popisa():
popis= {}
API_KEY = cfg.api['API_KEY_COINRANKING']# api key iz cfg
url ="https://api.coinranking.com/v2/coins"#url endpointa
headers= {
'x-access-token': API_KEY #postavljanje api keya u header requesta
}
response = requests.request("GET", url, headers=headers)
data=response.json()
if response.status_code == 200:#print poruke
print('Success!')
elif response.status_code == 404:
print('Not found.')
else:
print('Error ', response.status_code)
for coin in data["data"]["coins"]: #parsiranje potrebnih podataka
new = {"id":coin["uuid"],
"name":coin["name"],
"marketCap": coin["marketCap"]
}
popis.setdefault(coin["symbol"],new)
# print(popis)
return popis