-
Notifications
You must be signed in to change notification settings - Fork 0
/
stocks.py
29 lines (24 loc) · 1.02 KB
/
stocks.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
import requests
from db import INSERT
from util import progressbar
def get_data(url: str) -> list:
res = requests.get(url)
return res.json()
def main(url: str, exchange: str) -> None:
json = get_data(url)
progressbar(0, len(json), f"Inserting stocks from {exchange}: ")
for i, object in enumerate(json):
INSERT.stock(
symbol=object["symbol"],
title=object["name"],
exchange=exchange
)
progressbar(i + 1, len(json), None)
if __name__ == "__main__":
stock_data = [
{ "url": "https://raw.githubusercontent.com/rreichel3/US-Stock-Symbols/main/amex/amex_full_tickers.json", "exchange": "amex" },
{ "url": "https://raw.githubusercontent.com/rreichel3/US-Stock-Symbols/main/nasdaq/nasdaq_full_tickers.json", "exchange": "nasdaq" },
{ "url": "https://raw.githubusercontent.com/rreichel3/US-Stock-Symbols/main/nyse/nyse_full_tickers.json", "exchange": "nyse"}
]
for data in stock_data:
main(data["url"], data["exchange"])