-
Notifications
You must be signed in to change notification settings - Fork 42
/
mftp.py
46 lines (37 loc) · 1.63 KB
/
mftp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import env
import mail
import time
import notice
import requests
import argparse
import ntfy
from datetime import datetime
import iitkgp_erp_login.erp as erp
lsnif = ".lsnif"
headers = {
'timeout': '20',
'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',
}
session = requests.Session()
parser = argparse.ArgumentParser(description='One stop mailing solution for CDC NoticeBoard at IIT KGP')
parser.add_argument('--smtp', action="store_true", help='Use SMTP for sending the mails', required=False)
parser.add_argument('--gmail-api', action="store_true", help='Use GMAIL API for sending the mails', required=False)
parser.add_argument('--ntfy', action="store_true", help='Use NTFY to broadcast notifications', required=False)
parser.add_argument('--cron', action="store_true", help='Act as cronjob, bypass the continuous loop', required=False)
args = parser.parse_args()
while True:
now = datetime.now()
print(f"================ <<: {now.strftime('%H:%M:%S %d-%m-%Y')} :>> ================", flush=True)
print('[ERP LOGIN]', flush=True)
_, ssoToken = erp.login(headers, session, ERPCREDS=env, OTP_CHECK_INTERVAL=2, LOGGING=True, SESSION_STORAGE_FILE='.session')
notices = notice.fetch(headers, session, ssoToken, lsnif)
if args.ntfy:
notifications = ntfy.format_notice(notices, session)
ntfy.send(notifications, lsnif, notices)
else:
mails = mail.format_notice(notices, session)
mail.send(mails, args.smtp, args.gmail_api, lsnif, notices)
if args.cron:
break
print("[PAUSED FOR 2 MINUTES]", flush=True)
time.sleep(120)