bugfixing: consider only symbol that exist in db

This commit is contained in:
MuslemRahimi 2024-07-05 12:27:03 +02:00
parent fd6e850f89
commit 7598913cb3

View File

@ -2,6 +2,8 @@ import ujson
import asyncio
import aiohttp
import os
import sqlite3
from tqdm import tqdm
from dotenv import load_dotenv
import requests
@ -30,6 +32,13 @@ async def get_quote_of_stocks(ticker):
return {}
async def get_data():
con = sqlite3.connect('stocks.db')
cursor = con.cursor()
cursor.execute("PRAGMA journal_mode = wal")
cursor.execute("SELECT DISTINCT symbol FROM stocks")
stock_symbols = [row[0] for row in cursor.fetchall()]
con.close()
try:
response = requests.request("GET", url, headers=headers, params=querystring)
data = ujson.loads(response.text)['fda']
@ -37,9 +46,10 @@ async def get_data():
extracted_data = []
# Iterate over the original data to extract required fields
for entry in data:
for entry in tqdm(data):
try:
symbol = entry['companies'][0]['securities'][0]['symbol']
if symbol in stock_symbols:
name = entry['companies'][0]['name']
drug_name = entry['drug']['name'].capitalize()
indication = entry['drug']['indication_symptom']