-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
17 lines (13 loc) · 707 Bytes
/
main.py
File metadata and controls
17 lines (13 loc) · 707 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from datetime import datetime
import requests
PRICE_URL = "https://api.coingecko.com/api/v3/simple/price"
coin_ids = ['ethereum', 'bitcoin', 'cardano', 'solana', 'chainlink', 'the-graph', 'audius', 'livepeer', 'rally-2']
coin_ids_query = ','.join(coin_ids)
full_url = f"{PRICE_URL}?ids={coin_ids_query}&vs_currencies=usd"
response = requests.get(full_url)
for key, value in response.json().items():
coin_id = key
coin_value_usd = value['usd']
current_datetime = str(datetime.now())
insert_query = f"INSERT INTO crypto_prices (coin, price, ts) VALUES ('{key}', {coin_value_usd}, '{current_datetime}')"
insert_request = requests.get(f"http://localhost:9000/exec?query={insert_query}")