bugfixing congress

This commit is contained in:
MuslemRahimi 2024-11-19 07:49:34 +01:00
parent f5dc885817
commit 32ce0e4565

View File

@ -239,34 +239,38 @@ def create_politician_db(data, stock_symbols, stock_raw_data, etf_symbols, etf_r
# Convert defaultdict to list # Convert defaultdict to list
grouped_data_list = list(grouped_data.values()) grouped_data_list = list(grouped_data.values())
keys_to_keep = {'dateRecieved', 'id', 'transactionDate', 'representative', 'assetType', 'type', 'disclosureDate', 'symbol', 'name', 'amount'} #keys_to_keep = {'dateRecieved', 'id', 'transactionDate', 'representative', 'assetType', 'type', 'disclosureDate', 'symbol', 'name', 'amount'}
for item in tqdm(grouped_data_list): for item in tqdm(grouped_data_list):
try: try:
item = [{key: entry[key] for key in entry if key in keys_to_keep} for entry in item] #item = [{key: entry[key] for key in entry if key in keys_to_keep} for entry in item]
# Sort items by 'transactionDate' # Sort items by 'transactionDate'
item = sorted(item, key=lambda x: x['transactionDate'], reverse=True) item = sorted(item, key=lambda x: x['transactionDate'], reverse=True)
# Calculate top sectors # Calculate top sectors
sector_list = [] sector_list = []
industry_list = [] industry_list = []
for holding in item: for item2 in item:
try: try:
symbol = holding['symbol'] # Try to get 'symbol' first; if it doesn't exist, use 'ticker'
symbol = item2.get('symbol') or item2.get('ticker')
if not symbol:
continue # Skip if neither 'symbol' nor 'ticker' is present
ticker_data = stock_screener_data_dict.get(symbol, {}) ticker_data = stock_screener_data_dict.get(symbol, {})
# Extract specified columns data for each ticker # Extract specified columns data for each ticker
sector = ticker_data.get('sector',None) sector = ticker_data.get('sector', None)
industry = ticker_data.get('industry',None) industry = ticker_data.get('industry', None)
except:
sector = None
industry = None
if sector:
sector_list.append(sector)
if industry:
industry_list.append(industry)
# Append data to relevant lists if values are present
if sector:
sector_list.append(sector)
if industry:
industry_list.append(industry)
except Exception as e:
print(e)
# Get the top 3 most common sectors and industries # Get the top 3 most common sectors and industries
sector_counts = Counter(sector_list) sector_counts = Counter(sector_list)
@ -386,6 +390,7 @@ async def run():
return return
try: try:
connector = aiohttp.TCPConnector(limit=100) # Adjust the limit as needed connector = aiohttp.TCPConnector(limit=100) # Adjust the limit as needed
async with aiohttp.ClientSession(connector=connector) as session: async with aiohttp.ClientSession(connector=connector) as session:
for i in tqdm(range(0, len(total_symbols), chunk_size)): for i in tqdm(range(0, len(total_symbols), chunk_size)):