From f0bc3ce6bc08c3a00793af18ceddc01e7d4eb9ea Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Mon, 27 May 2024 09:13:27 +0200 Subject: [PATCH] clean code --- app/cron_sentiment_analysis.py | 4 ++-- app/cron_similar_stocks.py | 7 ++----- app/primary_cron_job.py | 16 +--------------- app/secondary_cron_job.py | 5 ----- 4 files changed, 5 insertions(+), 27 deletions(-) diff --git a/app/cron_sentiment_analysis.py b/app/cron_sentiment_analysis.py index 15a6bbe..3b59343 100755 --- a/app/cron_sentiment_analysis.py +++ b/app/cron_sentiment_analysis.py @@ -74,9 +74,9 @@ def remove_duplicates(data, key): return new_data def adjust_scaled_score(scaled_score): - adjustment = random.choice([-2,-1, 0, 1, 2]) + #adjustment = random.choice([-2,-1, 0, 1, 2]) # Add the adjustment to the scaled_score - scaled_score += adjustment + #scaled_score += adjustment # Ensure the scaled_score stays within the range of 0 to 10 scaled_score = max(0, min(10, scaled_score)) diff --git a/app/cron_similar_stocks.py b/app/cron_similar_stocks.py index e3f2e36..c5e838d 100755 --- a/app/cron_similar_stocks.py +++ b/app/cron_similar_stocks.py @@ -21,15 +21,12 @@ query_template = """ symbol = ? """ - - async def run(): cursor = con.cursor() cursor.execute("PRAGMA journal_mode = wal") - cursor.execute("SELECT DISTINCT symbol FROM stocks WHERE symbol != ?", ('%5EGSPC',)) + cursor.execute("SELECT DISTINCT symbol FROM stocks") stocks_symbols = [row[0] for row in cursor.fetchall()] - #stocks_symbols = ['AMD'] - for ticker in stocks_symbols: + for ticker in tqdm(stocks_symbols): filtered_df = [] df = pd.read_sql_query(query_template, con, params=(ticker,)) try: diff --git a/app/primary_cron_job.py b/app/primary_cron_job.py index 8f9e49b..67f03f8 100755 --- a/app/primary_cron_job.py +++ b/app/primary_cron_job.py @@ -7,7 +7,6 @@ import ujson import schedule import time import subprocess -from pocketbase import PocketBase # Client also works the same import asyncio import aiohttp import pytz @@ -21,26 +20,13 @@ from dotenv import load_dotenv import os load_dotenv() -api_key = os.getenv('FMP_API_KEY') useast_ip_address = os.getenv('USEAST_IP_ADDRESS') -pb_admin_email = os.getenv('POCKETBASE_ADMIN_EMAIL') -pb_admin_password = os.getenv('POCKETBASE_PASSWORD') -pb = PocketBase('http://127.0.0.1:8090') -admin_data = pb.admins.auth_with_password(pb_admin_email, pb_admin_password) + # Set the system's timezone to Berlin at the beginning subprocess.run(["timedatectl", "set-timezone", "Europe/Berlin"]) -async def get_quote_of_stocks(ticker_list): - ticker_str = ','.join(ticker_list) - async with aiohttp.ClientSession() as session: - url = f"https://financialmodelingprep.com/api/v3/quote/{ticker_str}?apikey={api_key}" - async with session.get(url) as response: - df = await response.json() - return df - - def run_json_job(): # Run the asynchronous function inside an asyncio loop diff --git a/app/secondary_cron_job.py b/app/secondary_cron_job.py index 7128290..9bc8c2f 100755 --- a/app/secondary_cron_job.py +++ b/app/secondary_cron_job.py @@ -16,11 +16,6 @@ import numpy as np import threading # Import threading module for parallel execution -from dotenv import load_dotenv -import os -load_dotenv() -api_key = os.getenv('FMP_API_KEY') - berlin_tz = pytz.timezone('Europe/Berlin') # Set the system's timezone to Berlin at the beginning