bugfixing: consider only symbol that exist in db
This commit is contained in:
parent
fd6e850f89
commit
7598913cb3
@ -2,6 +2,8 @@ import ujson
|
|||||||
import asyncio
|
import asyncio
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import os
|
import os
|
||||||
|
import sqlite3
|
||||||
|
from tqdm import tqdm
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
@ -30,6 +32,13 @@ async def get_quote_of_stocks(ticker):
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
async def get_data():
|
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:
|
try:
|
||||||
response = requests.request("GET", url, headers=headers, params=querystring)
|
response = requests.request("GET", url, headers=headers, params=querystring)
|
||||||
data = ujson.loads(response.text)['fda']
|
data = ujson.loads(response.text)['fda']
|
||||||
@ -37,9 +46,10 @@ async def get_data():
|
|||||||
extracted_data = []
|
extracted_data = []
|
||||||
|
|
||||||
# Iterate over the original data to extract required fields
|
# Iterate over the original data to extract required fields
|
||||||
for entry in data:
|
for entry in tqdm(data):
|
||||||
try:
|
try:
|
||||||
symbol = entry['companies'][0]['securities'][0]['symbol']
|
symbol = entry['companies'][0]['securities'][0]['symbol']
|
||||||
|
if symbol in stock_symbols:
|
||||||
name = entry['companies'][0]['name']
|
name = entry['companies'][0]['name']
|
||||||
drug_name = entry['drug']['name'].capitalize()
|
drug_name = entry['drug']['name'].capitalize()
|
||||||
indication = entry['drug']['indication_symptom']
|
indication = entry['drug']['indication_symptom']
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user