diff --git a/app/cron_business_metrics.py b/app/cron_business_metrics.py index bc969bf..e30d95a 100644 --- a/app/cron_business_metrics.py +++ b/app/cron_business_metrics.py @@ -374,7 +374,7 @@ def run(symbol): revenue_sources = [] geography_sources = [] - filings = Company(symbol).get_filings(form=["10-Q"]).latest(20) + filings = Company(symbol).get_filings(form=["10-Q","10-K"]).latest(20) #print(filings[0].xbrl()) for i in range(0,17): @@ -423,7 +423,7 @@ def run(symbol): for old, new in replacements.items(): name = name.replace(old, new) # Determine the target list and the name transformation logic - if symbol in ['NFLX','LLY','MSFT','META','NVDA','AAPL','GME']: + if symbol in ['SAVE','BA','NFLX','LLY','MSFT','META','NVDA','AAPL','GME']: column_list = ["srt:ProductOrServiceAxis"] else: column_list = ["srt:ProductOrServiceAxis", "us-gaap:StatementBusinessSegmentsAxis"] @@ -448,16 +448,7 @@ def run(symbol): ujson.dump(final_dataset, file) if __name__ == "__main__": - ''' - custom_order = { - 'HardwareAndAccessories': 4, - 'Software': 3, - 'Collectibles': 2, - } - run('GME', custom_order) - ''' - - for symbol in ['ADBE']: #['NFLX','PLTR','MSFT','META','TSLA','NVDA','AAPL','GME']: - #for AMD we need 10-K form to get geography revenue - run(symbol) + for symbol in []: #['SAVE','BA','ADBE','NFLX','PLTR','MSFT','META','TSLA','NVDA','AAPL','GME']: + #for AMD, SAVE we need 10-K form to get geography revenue + run(symbol) \ No newline at end of file diff --git a/app/cron_dashboard.py b/app/cron_dashboard.py index bc33144..4e93fa3 100644 --- a/app/cron_dashboard.py +++ b/app/cron_dashboard.py @@ -182,41 +182,47 @@ async def get_upcoming_earnings(session): async def get_recent_earnings(session): url = "https://api.benzinga.com/api/v2.1/calendar/earnings" res_list = [] - querystring = {"token": benzinga_api_key,"parameters[date_from]":yesterday,"parameters[date_to]":today,"parameters[date_sort]":"date"} - try: - async with session.get(url, params=querystring, headers=headers) as response: - res = ujson.loads(await response.text())['earnings'] - for item in res: - try: - symbol = item['ticker'] - name = item['name'] - time = item['time'] - eps_prior = float(item['eps_prior']) if item['eps_prior'] != '' else 0 - eps_surprise = float(item['eps_surprise']) if item['eps_surprise'] != '' else 0 - eps = float(item['eps']) if item['eps'] != '' else 0 - revenue_prior = float(item['revenue_prior']) if item['revenue_prior'] != '' else 0 - revenue_surprise = float(item['revenue_surprise']) if item['revenue_surprise'] != '' else 0 - revenue = float(item['revenue']) if item['revenue'] != '' else 0 - if symbol in stock_symbols and revenue != 0 and revenue_prior != 0 and eps_prior != 0 and eps != 0 and revenue_surprise != 0 and eps_surprise != 0: - df = pd.read_sql_query(query_template, con, params=(symbol,)) - market_cap = float(df['marketCap'].iloc[0]) if df['marketCap'].iloc[0] != '' else 0 - res_list.append({ - 'symbol': symbol, - 'name': name, - 'time': time, - 'marketCap': market_cap, - 'epsPrior':eps_prior, - 'epsSurprise': eps_surprise, - 'eps': eps, - 'revenuePrior': revenue_prior, - 'revenueSurprise': revenue_surprise, - 'revenue': revenue - }) - except Exception as e: - print('Recent Earnings:', e) - pass - except Exception as e: - pass + + importance_list = ["1","2","3","4","5"] + res_list = [] + for importance in importance_list: + + querystring = {"token": benzinga_api_key,"parameters[importance]":importance, "parameters[date_from]":yesterday,"parameters[date_to]":today,"parameters[date_sort]":"date"} + try: + async with session.get(url, params=querystring, headers=headers) as response: + res = ujson.loads(await response.text())['earnings'] + for item in res: + try: + symbol = item['ticker'] + name = item['name'] + time = item['time'] + eps_prior = float(item['eps_prior']) if item['eps_prior'] != '' else 0 + eps_surprise = float(item['eps_surprise']) if item['eps_surprise'] != '' else 0 + eps = float(item['eps']) if item['eps'] != '' else 0 + revenue_prior = float(item['revenue_prior']) if item['revenue_prior'] != '' else 0 + revenue_surprise = float(item['revenue_surprise']) if item['revenue_surprise'] != '' else 0 + revenue = float(item['revenue']) if item['revenue'] != '' else 0 + if symbol in stock_symbols and revenue != 0 and revenue_prior != 0 and eps_prior != 0 and eps != 0 and revenue_surprise != 0 and eps_surprise != 0: + df = pd.read_sql_query(query_template, con, params=(symbol,)) + market_cap = float(df['marketCap'].iloc[0]) if df['marketCap'].iloc[0] != '' else 0 + res_list.append({ + 'symbol': symbol, + 'name': name, + 'time': time, + 'marketCap': market_cap, + 'epsPrior':eps_prior, + 'epsSurprise': eps_surprise, + 'eps': eps, + 'revenuePrior': revenue_prior, + 'revenueSurprise': revenue_surprise, + 'revenue': revenue + }) + except Exception as e: + print('Recent Earnings:', e) + pass + except Exception as e: + pass + res_list = remove_duplicates(res_list) #res_list.sort(key=lambda x: x['marketCap'], reverse=True) res_list.sort(key=lambda x: (-parse_time(x['time']).timestamp(), -x['marketCap']))