From 40e2f5c82d7caa3374af7c6fb9cffdea2acd6a1b Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Wed, 16 Apr 2025 15:21:56 +0200 Subject: [PATCH] update cron job --- app/cron_discord_bot.py | 98 +++++++++++++++++++++++++++++++++++++++++ app/primary_cron_job.py | 3 +- 2 files changed, 99 insertions(+), 2 deletions(-) diff --git a/app/cron_discord_bot.py b/app/cron_discord_bot.py index cbc4dad..58d7609 100644 --- a/app/cron_discord_bot.py +++ b/app/cron_discord_bot.py @@ -27,6 +27,7 @@ RECENT_EARNINGS_WEBHOOK_URL = os.getenv("DISCORD_RECENT_EARNINGS_WEBHOOK") EXECUTIVE_ORDER_WEBHOOK_URL = os.getenv("DISCORD_EXECUTIVE_ORDER_WEBHOOK") ANALYST_REPORT_WEBHOOK_URL = os.getenv("DISCORD_ANALYST_REPORT_WEBHOOK") WIIM_WEBHOOK_URL = os.getenv('DISCORD_WIIM_WEBHOOK') +CONGRESS_TRADING_WEBHOOK_URL = os.getenv("DISCORD_CONGRESS_TRADING_WEBHOOK") BENZINGA_API_KEY = os.getenv('BENZINGA_API_KEY') @@ -669,6 +670,103 @@ def wiim(): print(e) +def congress_trading(): + try: + with open(f"json/discord/wiim.json", "r") as file: + seen_list = orjson.loads(file.read()) + seen_list = [item for item in seen_list if datetime.fromisoformat(item['date']).date() == today] + except: + seen_list = [] + + with open(f"json/dashboard/data.json", 'rb') as file: + data = orjson.loads(file.read())['wiim'] + data = [item for item in data if datetime.fromisoformat(item['date']).date() == today] + + res_list = [] + for item in data: + try: + with open(f"json/quote/{item['ticker']}.json","r") as file: + quote_data = orjson.loads(file.read()) + + item['price'] = round(quote_data.get('price',0),2) + item['changesPercentage'] = round(quote_data.get('changesPercentage',0),2) + item['marketCap'] = quote_data.get('marketCap',0) + item['eps'] = round(quote_data.get('eps',0),2) + + unique_str = f"{item['date']}-{item['ticker']}-{item.get('text','')}" + item['id'] = hashlib.md5(unique_str.encode()).hexdigest() + + if item['marketCap'] > 1E9: + res_list.append(item) + except: + pass + + if res_list: + + if seen_list: + seen_ids = {item['id'] for item in seen_list} + else: + seen_ids = {} + + for item in res_list: + try: + if item != None and item['id'] not in seen_ids and item['marketCap']: + symbol = item['ticker'] + price = item['price'] + changes_percentage = round(item['changesPercentage'],2) + eps = item['eps'] + market_cap = abbreviate_number(item['marketCap']) + description = item['text'] + message_timestamp = int((datetime.now() - timedelta(minutes=0)).timestamp()) + + color = 0x39FF14 if 'higher' in description else 0xFF0000 if 'lower' in description else 0xFFFFFF + + embed = { + "color": color, + "thumbnail": {"url": "https://stocknear.com/pwa-64x64.png"}, + "title": "Why Priced Moved", + "fields": [ + {"name": "Symbol", "value": symbol, "inline": True}, + {"name": "", "value": "", "inline": True}, + {"name": "Market Cap", "value": market_cap, "inline": True}, + {"name": "Price", "value": str(price), "inline": True}, + {"name": "", "value": "", "inline": True}, + {"name": "% Change", "value": str(changes_percentage)+"%", "inline": True}, + {"name": "", "value": "", "inline": False}, + {"name": f"{description}", "value": "", "inline": False}, + {"name": f"Data by Stocknear - ", "value": "", "inline": False}, + ], + "footer": {"text": ""} + } + + payload = { + "content": "", + "embeds": [embed] + } + + response = requests.post(WIIM_WEBHOOK_URL, json=payload) + + if response.status_code in (200, 204): + seen_list.append({'date': item['date'], 'id': item['id'], 'symbol': symbol}) + print("Embed sent successfully!") + + else: + print(f"Failed to send embed. Status code: {response.status_code}") + print("Response content:", response.text) + + else: + print("Earnings already sent!") + + + except Exception as e: + print(e) + try: + with open("json/discord/wiim.json","wb") as file: + file.write(orjson.dumps(seen_list)) + except Exception as e: + print(e) + + if __name__ == "__main__": options_flow() dark_pool_flow() diff --git a/app/primary_cron_job.py b/app/primary_cron_job.py index 920d9a5..6a28539 100755 --- a/app/primary_cron_job.py +++ b/app/primary_cron_job.py @@ -164,7 +164,6 @@ def run_share_statistics(): if week <= 4: run_command(["python3", "cron_share_statistics.py"]) - def run_cron_market_news(): week = datetime.today().weekday() if week <= 4: @@ -383,6 +382,7 @@ schedule.every().day.at("08:00").do(run_threaded, run_cron_insider_trading).tag( schedule.every().day.at("08:30").do(run_threaded, run_dividends).tag('dividends_job') schedule.every().day.at("09:00").do(run_threaded, run_shareholders).tag('shareholders_job') schedule.every().day.at("09:30").do(run_threaded, run_profile).tag('profile_job') +schedule.every().day.at("10:00").do(run_threaded, run_share_statistics).tag('share_statistics_job') @@ -417,7 +417,6 @@ schedule.every(20).minutes.do(run_threaded, run_tracker).tag('tracker_job') schedule.every(10).minutes.do(run_threaded, run_market_moods).tag('market_moods_job') schedule.every(10).minutes.do(run_threaded, run_earnings).tag('earnings_job') -#schedule.every(4).hours.do(run_threaded, run_share_statistics).tag('share_statistics_job') schedule.every(2).hours.do(run_threaded, run_analyst_rating).tag('analyst_job') schedule.every(1).hours.do(run_threaded, run_company_news).tag('company_news_job')