Skip to content

Commit

Permalink
fix: parse companies every hour properly
Browse files Browse the repository at this point in the history
  • Loading branch information
proffapt committed Nov 27, 2024
1 parent 73a87bf commit d206ab4
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions mftp/mftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import requests
import argparse
from datetime import datetime
import iitkgp_erp_login.erp as erp
from datetime import datetime, timedelta

headers = {
'timeout': '20',
Expand All @@ -24,10 +24,6 @@
parser.add_argument('--cron', action="store_true", help='Act as cronjob, bypass the continuous loop', required=False)
args = parser.parse_args()

# Initialize the last execution time for companies email logic
# Set it to run immediately on the first iteration
last_companies_email_time = datetime.now() - timedelta(hours=1)

while True:
now = datetime.now()
print(f"================ <<: {now.strftime('%H:%M:%S %d-%m-%Y')} :>> ================", flush=True)
Expand All @@ -36,12 +32,11 @@
_, ssoToken = erp.login(headers, session, ERPCREDS=env, OTP_CHECK_INTERVAL=2, LOGGING=True, SESSION_STORAGE_FILE='.session')

if args.gmail_api or args.smtp:
if now - last_companies_email_time >= timedelta(hours=1):
if now.minute == 0:
companies = company.fetch(session, headers, ssoToken)
open_not_applied_companies = company.filter(companies, "OPEN_N")
companies_update_mail = mail.format_companies(session.cookies.get('ssoToken'), open_not_applied_companies)
mail.send_companies(companies_update_mail, args.gmail_api, args.smtp)
last_companies_email_time = now

notice_db = db.NoticeDB(config={
'uri': env.MONGO_URI,
Expand Down

0 comments on commit d206ab4

Please sign in to comment.