-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch.py
42 lines (29 loc) · 999 Bytes
/
fetch.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
from requests import Request, Session
import json
url = "https://pro-api.coinmarketcap.com/v2/cryptocurrency/quotes/latest"
currencies = ['ethereum','solana','polygon']
id = {
'ethereum' : '1027',
'solana' : '5426',
'polygon' : '3890'
}
headers = {
"Accepts" : "application/json",
'X-CMC_PRO_API_KEY' : 'f65ee482-05fa-43ac-857b-a1d6b3590e68'
}
from pyodide.http import pyfetch
import asyncio
response = pyfetch(url=url, method="GET",headers=headers,params=parameters)
output = f"GET request=> status:{response.status}, json:{response.json()}"
# for currency in currencies:
# session = Session()
# session.headers.update(headers)
# parameters = {
# 'slug' : currency,
# 'convert' : 'INR'
# }
# response = session.get(url,params=parameters)
# data = json.loads(response.text)
# # print(data)
# val = round(data['data'][id[currency]]['quote']['INR']['price'],2)
# print(f"{currency}'s price in INR : {val}")