|
13 | 13 | import iitkgp_erp_login.erp as erp |
14 | 14 |
|
15 | 15 | 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", |
18 | 18 | } |
19 | 19 | session = requests.Session() |
20 | 20 |
|
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 | +) |
26 | 45 | args = parser.parse_args() |
27 | 46 |
|
28 | 47 | 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 | + ) |
31 | 53 |
|
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 | + ) |
34 | 63 |
|
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) |
37 | 66 |
|
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 | + ) |
46 | 79 |
|
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 | + ) |
53 | 88 |
|
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]") |
60 | 97 |
|
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() |
66 | 103 |
|
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) |
73 | 114 | 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) |
79 | 116 |
|
80 | | - if args.cron: |
81 | | - break |
| 117 | + if args.cron: |
| 118 | + break |
82 | 119 |
|
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