From ffe407515746bcaec73f3eec7ebe856b1c12a888 Mon Sep 17 00:00:00 2001 From: ACM Date: Tue, 4 Jan 2022 18:22:23 -0500 Subject: [PATCH] u --- .gitignore | 2 ++ admin/__init__.py | 44 +++++++++++++++++++++++++++++++++++++++++ flask_app.py | 20 +++++++++++++------ manage_waitlist | 15 ++++++++++++++ manage_waitlist.py | 10 +++++++--- templates/home | 2 +- templates/register.html | 1 + 7 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 admin/__init__.py create mode 100755 manage_waitlist diff --git a/.gitignore b/.gitignore index 2457203..b5a8ea2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ resumes*/ resumes*.zip config_hackWPI.py config.py +admin/*.json +admin/*.csv # Created by https://www.gitignore.io/api/web,vim,git,macos,linux,bower,grunt,python,pycharm,windows,eclipse,webstorm,intellij,jetbrains,virtualenv,visualstudio,visualstudiocode # Dev ENV Stuff diff --git a/admin/__init__.py b/admin/__init__.py new file mode 100644 index 0000000..9070551 --- /dev/null +++ b/admin/__init__.py @@ -0,0 +1,44 @@ +import json +import csv +from io import StringIO + + +def json_to_csv(data): + # Opening JSON file and loading the data + # into the variable data + + json_data=[] + if(type(data) is json): + json_data=data + elif(type(data) is str): + json_data=json.loads(data) + else: + json_data = json.loads(json.dumps(data)) + # now we will open a file for writing + csv_out = StringIO("") + + # create the csv writer object + csv_writer = csv.writer(csv_out) + + # Counter variable used for writing + # headers to the CSV file + count = 0 + + for e in json_data: + if count == 0: + + # Writing headers of CSV file + header = e.keys() + csv_writer.writerow(header) + count += 1 + + # Writing data of CSV file + csv_writer.writerow(e.values()) + csv_out.seek(0) + return csv_out.read() + +if __name__=="__main__": + with open('hack22.json') as f: + j = json.load(f)['data'] + print(type(j)) + print(json_to_csv(j)) \ No newline at end of file diff --git a/flask_app.py b/flask_app.py index d2f494d..4935331 100644 --- a/flask_app.py +++ b/flask_app.py @@ -545,21 +545,29 @@ def send_email(to, subject, body): body += 'To update your status, you can go to hack.wpi.edu/dashboard\n' body += '\nAll the best!\nThe Hack@WPI Team' - server = smtplib.SMTP('smtp.gmail.com', 587) - server.starttls() - sender = api_keys['smtp_email']['user'] - server.login(sender, api_keys['smtp_email']['pass']) + smtp_server = api_keys['smtp_email']['smtp_server'] + smtp_port = api_keys['smtp_email']['smtp_port'] + server = smtplib.SMTP(smtp_server, smtp_port) + # Enable TLS if we're using secure SMTP + if(smtp_port > 25): + server.starttls() + user = api_keys['smtp_email']['user'] + sender = api_keys['smtp_email']['sender'] + # Login if we're using server with auth + if ('pass' in api_keys['smtp_email']): + server.login(user, api_keys['smtp_email']['pass']) - msg = _create_MIMEMultipart(subject, sender, to, body) + msg = _create_MIMEMultipart(subject, sender, to, body, user) server.send_message(msg) print("Sucess! (Email to " + to) -def _create_MIMEMultipart(subject, sender, to, body): +def _create_MIMEMultipart(subject, sender, to, body, user=None): msg = MIMEMultipart() msg['Subject'] = subject msg['From'] = sender + msg.add_header('reply-to', user) if type(to) == list: msg['To'] = ", ".join(to) else: diff --git a/manage_waitlist b/manage_waitlist new file mode 100755 index 0000000..22022a9 --- /dev/null +++ b/manage_waitlist @@ -0,0 +1,15 @@ +#!/bin/bash +# cd to script dir +SCRIPT_RELATIVE_DIR=$(dirname "${BASH_SOURCE[0]}") +cd $SCRIPT_RELATIVE_DIR + +# enable python venv +source ./venv/bin/activate + +echo `which python` + +# noot +python ./manage_waitlist.py + +# disable venv +deactivate \ No newline at end of file diff --git a/manage_waitlist.py b/manage_waitlist.py index 9e7dcd3..26b269c 100644 --- a/manage_waitlist.py +++ b/manage_waitlist.py @@ -1,6 +1,6 @@ import requests from flask_app import db, Hacker, send_email, gen_new_auto_promote_keys -from config_hackWPI import WAITLIST_LIMIT +from config_hackWPI import WAITLIST_LIMIT, WEBHOOK_URL num_attendees = db.session.query(Hacker).filter(Hacker.waitlisted == False).count() num_waitlisted = db.session.query(Hacker).filter(Hacker.waitlisted == True).count() @@ -52,5 +52,9 @@ msg += ' ' + str(errs) + '\n' print(msg) -#send_email('hack@wpi.edu', 'HackWPI - Daily Waitlist Report!', msg) -send_email('bkayastha@wpi.edu', 'HackWPI - Daily Waitlist Report!', msg) +# requests.post(WEBHOOK_URL, { +# "content": msg +# }) + +# send_email('hack@wpi.edu', 'HackWPI - Daily Waitlist Report!', msg) +send_email('mikel@wpi.edu', 'HackWPI - Daily Waitlist Report!', msg) diff --git a/templates/home b/templates/home index 6a02304..bfb9d77 160000 --- a/templates/home +++ b/templates/home @@ -1 +1 @@ -Subproject commit 6a023042c9f337071b701fbff228581b0a1e6e14 +Subproject commit bfb9d7799fbb8630f4351f043a05aa617964becf diff --git a/templates/register.html b/templates/register.html index d52ca9c..bcd68eb 100644 --- a/templates/register.html +++ b/templates/register.html @@ -59,6 +59,7 @@ +