bugfixing
This commit is contained in:
parent
8734217115
commit
e2a5667f81
@ -218,7 +218,7 @@ class StockDatabase:
|
|||||||
ticker_type = stock.get('type', '')
|
ticker_type = stock.get('type', '')
|
||||||
if exchange_short_name in ['XETRA','NYSE', 'NASDAQ','AMEX', 'PNK','EURONEXT'] and ticker_type in ['stock']:
|
if exchange_short_name in ['XETRA','NYSE', 'NASDAQ','AMEX', 'PNK','EURONEXT'] and ticker_type in ['stock']:
|
||||||
symbol = stock.get('symbol', '')
|
symbol = stock.get('symbol', '')
|
||||||
if exchange_short_name == 'PNK' and symbol not in ['DRSHF','NTDOY','OTGLF','TCEHY', 'KRKNF','BYDDY','XIACY','NSRGY','TLPFY','TLPFF']:
|
if exchange_short_name == 'PNK' and symbol not in ['TSSI','DRSHF','NTDOY','OTGLF','TCEHY', 'KRKNF','BYDDY','XIACY','NSRGY','TLPFY','TLPFF']:
|
||||||
pass
|
pass
|
||||||
elif exchange_short_name == 'EURONEXT' and symbol not in ['ALEUP.PA','ALNEV.PA','ALGAU.PA','ALDRV.PA','ALHYG.PA','ALVMG.PA','TEP.PA']:
|
elif exchange_short_name == 'EURONEXT' and symbol not in ['ALEUP.PA','ALNEV.PA','ALGAU.PA','ALDRV.PA','ALHYG.PA','ALVMG.PA','TEP.PA']:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import time
|
|||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
date_format = "%a, %d %b %Y %H:%M:%S %z"
|
date_format = "%a, %d %b %Y %H:%M:%S %z"
|
||||||
|
|
||||||
@ -67,32 +68,38 @@ async def get_endpoint(session, symbol, con):
|
|||||||
res = ujson.loads(await response.text())
|
res = ujson.loads(await response.text())
|
||||||
|
|
||||||
for item in res:
|
for item in res:
|
||||||
date_obj = datetime.strptime(item['created'], date_format)
|
|
||||||
date_obj_utc = date_obj.astimezone(pytz.utc)
|
|
||||||
|
|
||||||
new_date_obj_utc = date_obj_utc
|
|
||||||
|
|
||||||
start_date_obj_utc = correct_weekday(date_obj_utc)
|
|
||||||
|
|
||||||
start_date = start_date_obj_utc.strftime("%Y-%m-%d")
|
|
||||||
end_date = new_date_obj_utc.strftime("%Y-%m-%d")
|
|
||||||
|
|
||||||
new_date_str = new_date_obj_utc.strftime("%b %d, %Y")
|
|
||||||
query = query_template.format(symbol=symbol)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
df = pd.read_sql_query(query,con, params=(start_date, end_date))
|
date_obj = datetime.strptime(item['created'], date_format)
|
||||||
if not df.empty:
|
date_obj_utc = date_obj.astimezone(pytz.utc)
|
||||||
change_percent = round((df['close'].iloc[1]/df['close'].iloc[0] -1)*100,2)
|
|
||||||
else:
|
new_date_obj_utc = date_obj_utc
|
||||||
change_percent = '-'
|
|
||||||
except Exception as e:
|
start_date_obj_utc = correct_weekday(date_obj_utc)
|
||||||
change_percent = '-'
|
|
||||||
|
|
||||||
res_list.append({'date': new_date_str, 'text': item['title'], 'changesPercentage': change_percent})
|
start_date = start_date_obj_utc.strftime("%Y-%m-%d")
|
||||||
with open(f"json/wiim/company/{symbol}.json", 'w') as file:
|
end_date = new_date_obj_utc.strftime("%Y-%m-%d")
|
||||||
|
|
||||||
|
new_date_str = new_date_obj_utc.strftime("%b %d, %Y")
|
||||||
|
query = query_template.format(symbol=symbol)
|
||||||
|
|
||||||
|
try:
|
||||||
|
df = pd.read_sql_query(query,con, params=(start_date, end_date))
|
||||||
|
if not df.empty:
|
||||||
|
change_percent = round((df['close'].iloc[1]/df['close'].iloc[0] -1)*100,2)
|
||||||
|
else:
|
||||||
|
change_percent = '-'
|
||||||
|
except Exception as e:
|
||||||
|
change_percent = '-'
|
||||||
|
res_list.append({'date': new_date_str, 'text': item['title'], 'changesPercentage': change_percent})
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
if len(res_list) > 0:
|
||||||
|
with open(f"json/wiim/company/{symbol}.json", 'w') as file:
|
||||||
ujson.dump(res_list, file)
|
ujson.dump(res_list, file)
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
current_date = datetime.now(pytz.utc)
|
current_date = datetime.now(pytz.utc)
|
||||||
date_difference = current_date - new_date_obj_utc
|
date_difference = current_date - new_date_obj_utc
|
||||||
@ -144,11 +151,10 @@ async def run():
|
|||||||
etf_cursor.execute("PRAGMA journal_mode = wal")
|
etf_cursor.execute("PRAGMA journal_mode = wal")
|
||||||
etf_cursor.execute("SELECT DISTINCT symbol FROM etfs")
|
etf_cursor.execute("SELECT DISTINCT symbol FROM etfs")
|
||||||
etf_symbols = [row[0] for row in etf_cursor.fetchall()]
|
etf_symbols = [row[0] for row in etf_cursor.fetchall()]
|
||||||
|
|
||||||
|
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
await get_latest_wiim(session, stock_symbols, etf_symbols)
|
#await get_latest_wiim(session, stock_symbols, etf_symbols)
|
||||||
await asyncio.gather(*(get_endpoint(session, symbol, con) for symbol in stock_symbols))
|
await asyncio.gather(*(get_endpoint(session, symbol, con) for symbol in tqdm(stock_symbols)))
|
||||||
await asyncio.gather(*(get_endpoint(session, symbol, etf_con) for symbol in etf_symbols))
|
await asyncio.gather(*(get_endpoint(session, symbol, etf_con) for symbol in etf_symbols))
|
||||||
|
|
||||||
con.close()
|
con.close()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user