Skip to content

Commit 6d6fcaa

Browse files
committed
fix: indentation
1 parent 82bd004 commit 6d6fcaa

File tree

1 file changed

+90
-53
lines changed

1 file changed

+90
-53
lines changed

mftp/mftp.py

Lines changed: 90 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -13,72 +13,109 @@
1313
import iitkgp_erp_login.erp as erp
1414

1515
headers = {
16-
'timeout': '20',
17-
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/51.0.2704.79 Chrome/51.0.2704.79 Safari/537.36',
16+
"timeout": "20",
17+
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/51.0.2704.79 Chrome/51.0.2704.79 Safari/537.36",
1818
}
1919
session = requests.Session()
2020

21-
parser = argparse.ArgumentParser(description='One stop mailing solution for CDC NoticeBoard at IIT KGP')
22-
parser.add_argument('--smtp', action="store_true", help='Use SMTP for sending the mails', required=False)
23-
parser.add_argument('--gmail-api', action="store_true", help='Use GMAIL API for sending the mails', required=False)
24-
parser.add_argument('--ntfy', action="store_true", help='Use NTFY to broadcast notifications', required=False)
25-
parser.add_argument('--cron', action="store_true", help='Act as cronjob, bypass the continuous loop', required=False)
21+
parser = argparse.ArgumentParser(
22+
description="One stop mailing solution for CDC NoticeBoard at IIT KGP"
23+
)
24+
parser.add_argument(
25+
"--smtp", action="store_true", help="Use SMTP for sending the mails", required=False
26+
)
27+
parser.add_argument(
28+
"--gmail-api",
29+
action="store_true",
30+
help="Use GMAIL API for sending the mails",
31+
required=False,
32+
)
33+
parser.add_argument(
34+
"--ntfy",
35+
action="store_true",
36+
help="Use NTFY to broadcast notifications",
37+
required=False,
38+
)
39+
parser.add_argument(
40+
"--cron",
41+
action="store_true",
42+
help="Act as cronjob, bypass the continuous loop",
43+
required=False,
44+
)
2645
args = parser.parse_args()
2746

2847
while True:
29-
now = datetime.now()
30-
print(f"================ <<: {now.strftime('%H:%M:%S %d-%m-%Y')} :>> ================", flush=True)
48+
now = datetime.now()
49+
print(
50+
f"================ <<: {now.strftime('%H:%M:%S %d-%m-%Y')} :>> ================",
51+
flush=True,
52+
)
3153

32-
print('[ERP LOGIN]', flush=True)
33-
_, ssoToken = erp.login(headers, session, ERPCREDS=env, OTP_CHECK_INTERVAL=2, LOGGING=True, SESSION_STORAGE_FILE='.session')
54+
print("[ERP LOGIN]", flush=True)
55+
_, ssoToken = erp.login(
56+
headers,
57+
session,
58+
ERPCREDS=env,
59+
OTP_CHECK_INTERVAL=2,
60+
LOGGING=True,
61+
SESSION_STORAGE_FILE=".session",
62+
)
3463

35-
if args.gmail_api or args.smtp:
36-
_, new, modified = company.fetch(session, headers, ssoToken)
64+
if args.gmail_api or args.smtp:
65+
_, new, modified = company.fetch(session, headers, ssoToken)
3766

38-
if new:
39-
print('[NEW COMPANIES]', flush=True)
40-
for com in new:
41-
logging.info(f' {com["Name"]} | {com["Role"]} | {com["CTC"]} | {com["End_Date"]} | {com["Interview_Date"]}')
42-
if modified:
43-
print('[MODIFIED COMPANIES]', flush=True)
44-
for com in modified:
45-
logging.info(f' {com["Name"]} | {com["Role"]} | {com["CTC"]} | {com["End_Date"]} | {com["Interview_Date"]}')
67+
if new:
68+
print("[NEW COMPANIES]", flush=True)
69+
for com in new:
70+
logging.info(
71+
f" {com['Name']} | {com['Role']} | {com['CTC']} | {com['End_Date']} | {com['Interview_Date']}"
72+
)
73+
if modified:
74+
print("[MODIFIED COMPANIES]", flush=True)
75+
for com in modified:
76+
logging.info(
77+
f" {com['Name']} | {com['Role']} | {com['CTC']} | {com['End_Date']} | {com['Interview_Date']}"
78+
)
4679

47-
filtered = []
48-
if new + modified:
49-
filtered = company.filter(new + modified, "OPEN_N")
50-
if filtered:
51-
for com in filtered:
52-
logging.info(f' {com["Name"]} | {com["Role"]} | {com["CTC"]} | {com["End_Date"]} | {com["Interview_Date"]}')
80+
filtered = []
81+
if new + modified:
82+
filtered = company.filter(new + modified, "OPEN_N")
83+
if filtered:
84+
for com in filtered:
85+
logging.info(
86+
f" {com['Name']} | {com['Role']} | {com['CTC']} | {com['End_Date']} | {com['Interview_Date']}"
87+
)
5388

54-
latest_ssoToken = session.cookies.get('ssoToken')
55-
mail_subject = "APPLY NOW! New companies opened"
56-
companies_mail = mail.format_companies(latest_ssoToken, filtered, mail_subject)
57-
mail.send_companies(companies_mail, args.gmail_api, args.smtp)
58-
else:
59-
print("[NO NEW COMPANIES]")
89+
latest_ssoToken = session.cookies.get("ssoToken")
90+
mail_subject = "APPLY NOW! New companies opened"
91+
companies_mail = mail.format_companies(
92+
latest_ssoToken, filtered, mail_subject
93+
)
94+
mail.send_companies(companies_mail, args.gmail_api, args.smtp)
95+
else:
96+
print("[NO NEW COMPANIES]")
6097

61-
notice_db = db.NoticeDB(config={
62-
'uri': env.MONGO_URI,
63-
'db_name': env.MONGO_DATABASE
64-
}, collection_name=env.MONGO_COLLECTION)
65-
notice_db.connect()
98+
notice_db = db.NoticeDB(
99+
config={"uri": env.MONGO_URI, "db_name": env.MONGO_DATABASE},
100+
collection_name=env.MONGO_COLLECTION,
101+
)
102+
notice_db.connect()
66103

67-
notices = notice.fetch(headers, session, ssoToken, notice_db)
68-
if notices:
69-
if args.ntfy:
70-
notifications = ntfy.format_notices(notices)
71-
if notifications:
72-
ntfy.send_notices(notifications, notice_db)
104+
notices = notice.fetch(headers, session, ssoToken, notice_db)
105+
if notices:
106+
if args.ntfy:
107+
notifications = ntfy.format_notices(notices)
108+
if notifications:
109+
ntfy.send_notices(notifications, notice_db)
110+
else:
111+
mails = mail.format_notices(notices)
112+
if mails:
113+
mail.send_notices(mails, args.smtp, args.gmail_api, notice_db)
73114
else:
74-
mails = mail.format_notices(notices)
75-
if mails:
76-
mail.send_notices(mails, args.smtp, args.gmail_api, notice_db)
77-
else:
78-
print('[NO NEW NOTICES]', flush=True)
115+
print("[NO NEW NOTICES]", flush=True)
79116

80-
if args.cron:
81-
break
117+
if args.cron:
118+
break
82119

83-
print('[PAUSED FOR 2 MINUTES]', flush=True)
84-
time.sleep(120)
120+
print("[PAUSED FOR 2 MINUTES]", flush=True)
121+
time.sleep(120)

0 commit comments

Comments
 (0)