Skip to content

Commit

Permalink
bugfixing
Browse files Browse the repository at this point in the history
  • Loading branch information
MuslemRahimi committed Dec 9, 2024
1 parent 02f836f commit 71af512
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions app/cron_earnings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@
today = datetime.now(ny_tz).replace(hour=0, minute=0, second=0, microsecond=0)
N_days_ago = today - timedelta(days=10)

# Function to delete all files in a directory
def delete_files_in_directory(directory):
for filename in os.listdir(directory):
file_path = os.path.join(directory, filename)
try:
if os.path.isfile(file_path):
os.remove(file_path)
except Exception as e:
print(f"Failed to delete {file_path}. Reason: {e}")


def check_existing_file(ticker, folder_name):
file_path = f"json/earnings/{folder_name}/{ticker}.json"
Expand All @@ -41,10 +31,10 @@ def check_existing_file(ticker, folder_name):
date_obj = date_obj.replace(tzinfo=pytz.UTC)

if folder_name == 'surprise':
if date_obj >= N_days_ago:
if date_obj+timedelta(1) >= N_days_ago:
still_new = True
elif folder_name == 'next':
if date_obj >= today:
if date_obj+timedelta(1) >= today:
still_new = True

if still_new == False:
Expand All @@ -64,7 +54,6 @@ async def get_data(session, ticker):
try:
async with session.get(url, params=querystring, headers=headers) as response:
data = ujson.loads(await response.text())['earnings']

# Filter for future earnings
future_dates = [item for item in data if ny_tz.localize(datetime.strptime(item["date"], "%Y-%m-%d")) >= today]
if future_dates:
Expand All @@ -77,7 +66,7 @@ async def get_data(session, ticker):
eps_est = float(nearest_future['eps_est']) if nearest_future['eps_est'] else 0
revenue_est = float(nearest_future['revenue_est']) if nearest_future['revenue_est'] else 0
revenue_prior = float(nearest_future['revenue_prior']) if nearest_future['revenue_prior'] else 0
if revenue_est and revenue_prior and eps_prior and eps_est:
if revenue_est is not None and revenue_prior is not None and eps_prior is not None and eps_est is not None:
res_list = {
'date': date,
'time': time,
Expand Down

0 comments on commit 71af512

Please sign in to comment.