diff --git a/Flask.yaml b/Flask.yaml deleted file mode 100644 index 425b0d4..0000000 --- a/Flask.yaml +++ /dev/null @@ -1,20 +0,0 @@ -session_name: '0' -windows: -- focus: 'true' - layout: e90b,204x63,0,0[204x46,0,0,0,204x16,0,47{36x16,0,47,2,84x16,37,47,3,82x16,122,47,4}] - options: {} - panes: - - shell_command: - - cd /Users/normrasmussen/Documents/Projects/CSM_webapp - - nvim - - shell_command: - - cd /Users/normrasmussen - - cmatrix - - focus: 'true' - shell_command: - - cd /Users/normrasmussen/Documents/Projects/CSM_webapp - - Python - - shell_command: - - cd /Users/normrasmussen/Documents/Projects/CSM_webapp/app/static/files - - zsh - window_name: flask main diff --git a/app/__pycache__/routes.cpython-311.pyc b/app/__pycache__/routes.cpython-311.pyc index 3e28cd7..2a5d796 100644 Binary files a/app/__pycache__/routes.cpython-311.pyc and b/app/__pycache__/routes.cpython-311.pyc differ diff --git a/app/routes.py b/app/routes.py index 69cec2e..86b2b9a 100644 --- a/app/routes.py +++ b/app/routes.py @@ -5,7 +5,10 @@ import re import os import csv import glob +import time +import pandas as pd from datetime import datetime, timezone, timedelta +from pathlib import Path from functools import wraps import flask from flask import ( @@ -39,7 +42,7 @@ app.permanent_session_lifetime = timedelta(minutes=30) specials = '"!@#$%^&*()-+?_=,<>/"' url = "https://api.northpass.com/" - +@app.route("/downloadcsv", methods=["GET", "POST"]) def download_csv(): if request.method == "GET": download = make_response(session["dfcsv"]) @@ -47,6 +50,12 @@ def download_csv(): download.headers["Content-Type"] = "text/csv" return download +@app.route("/send_to_admin") +def send_to_admin(): + if request.method == "GET": + url = f"https://app.northpass.com/app/admin/{session['admin_id']}" + return redirect(url) + def key_response(response): if "402" in str(response): @@ -62,6 +71,7 @@ def correct_key(response): data = response.json() session["raw_school"] = data["data"]["attributes"]["properties"]["name"] session["sani_school"] = session["raw_school"].replace("[", "").replace("]", "") + session["admin_id"] = data["data"]["id"] session["client_path"] = os.path.join(TEMPLATES_FOLDER, session["sani_school"]) return render_template("home.html", title="Active Session") @@ -174,7 +184,7 @@ def divide_values(file): for item in file[1:]: emails.append(item[0]) groups.append(item[1:]) -# FEAT: These two extract the groups and emails into two lists + # FEAT: These two extract the groups and emails into two lists groups = [item for group in groups for item in group] groups = list(set(groups)) return api_csv_parse(emails, groups) @@ -183,7 +193,7 @@ def divide_values(file): elif selection == "some-groups": submissions = [] for item in file[1:]: -# FEAT: This extracts each row as a list. Perfect for Learners in Specific Groups. + # FEAT: This extracts each row as a list. Perfect for Learners in Specific Groups. submissions.append(item) for item in submissions: emails.append(item[0]) @@ -437,20 +447,111 @@ def download_templates(): os.chdir = session["client_path"] file_path = session["client_path"] zipped_path = os.path.join(TEMPLATES_FOLDER, zipped_file) - download = shutil.make_archive(zipped_path, 'zip', file_path) - + download = shutil.make_archive(zipped_path, "zip", file_path) + delete_zip() return send_file(download, as_attachment=True) -@app.after_request -def delete_zip(response): + +def delete_zip(): + print("Sleeping...") + time.sleep(5) zipped_path = TEMPLATES_FOLDER - wildcard = glob.glob(zipped_path + ".zip") - for zipfile in wildcard: + wildcard = glob.glob(zipped_path + "*.zip") + wildcard = str(wildcard) + wildzip = wildcard[-5:-2] + if wildzip == "zip": try: - shutil.rmtree(zipfile) + path = Path(wildcard) + print(path) + shutil.rmtree(path) except OSError: print(OSError) - return response + return + + +@app.route("/get_info", methods=["GET", "POST"]) +@key_required +def get_info(): + return render_template("get_info.html", title="Get Customer Information") + + +@app.route("/get_info/", methods=["GET", "POST"]) +@key_required +def get_courses(variable): + count = 0 + courses = [] + cats = [] + course_dict = {} + if request.method == "POST": + while True: + count += 1 + url = f"https://api.northpass.com/v2/courses?page={count}" + headers = {"accept": "application/json", "X-Api-Key": session["key"]} + response = requests.get(url, headers=headers) + data = response.json() + + for response in data["data"]: + status = response["attributes"]["status"] + uuid = response["id"] + name = response["attributes"]["name"] + ecount = response["attributes"]["enrollments_count"] + created = response["attributes"]["created_at"] + update = response["attributes"]["updated_at"] + unpub = response["attributes"]["unpublished_changes"] + course_dict = { + "Id": uuid, + "Name": name, + "Status": status, + "Enrollments": ecount, + "Created At": created, + "Last Updated": update, + "Unpublished Changes?": unpub, + } + cat_id = response["relationships"]["categories"]["data"] + headers = {"accept": "application/json", "X-Api-Key": session["key"]} + cats = [] + if len(cat_id) == 0: + pass + elif len(cat_id) == 1: + categoryid = cat_id[0]["id"] + url = f"https://api.northpass.com/v2/categories/{categoryid}" + cat_resp = requests.get(url, headers=headers) + cat_data = cat_resp.json() + cat_name = cat_data["data"]["attributes"]["name"] + cats.append(cat_name) + course_dict.update({"Categories": cats}) + else: + for item in cat_id: + categoryid = item["id"] + url = f"https://api.northpass.com/v2/categories/{categoryid}" + cat_resp = requests.get(url, headers=headers) + cat_data = cat_resp.json() + cat_name = cat_data["data"]["attributes"]["name"] + cats.append(cat_name) + course_dict.update({"Categories": cats}) + + try: + courses.append(course_dict) + except TypeError as e: + print(f"Error: {e}") + finally: + pd.set_option("display.max_colwidth", 30) + df = pd.DataFrame.from_records(courses) + df.iloc[-1] = df.iloc[-1].astype(str).str.replace("[\]\[]",'') + df.fillna('', inplace=True) + table = df.to_html() + session["dfcsv"] = df.to_csv() + + if data["data"] == []: + break + + return render_template("get_info.html", + title="Course Information", + table=table) + + return "You didn't post up" + + @app.route("/undo_template", methods=["POST"]) @key_required @@ -459,6 +560,7 @@ def undo_template(): if request.form["undo_templates"]: pass + @app.route("/stop", methods=["POST"]) def stop(): print("stopping") diff --git a/app/static/css/styles.css b/app/static/css/styles.css index aeba292..7ff5a52 100644 --- a/app/static/css/styles.css +++ b/app/static/css/styles.css @@ -187,6 +187,11 @@ justify-content: space-evenly; justify-content: space-around; } +.get_opts{ + display:flex; + justify-content: space-evenly; +} + #templates { width: 75%; } @@ -228,7 +233,7 @@ ul { text-align: center; } -/* + @-webkit-keyframes come-in { 0% { -webkit-transform: translatey(100px); @@ -268,7 +273,16 @@ ul { transform: translatey(0px) scale(1); opacity: 1; } -}*/ +} +* { + margin: 0; + padding: 0; +} + +html, body { + background: #eaedf2; + font-family: 'Roboto', sans-serif; +} .floating-container { position: fixed; @@ -279,7 +293,7 @@ ul { margin: 35px 25px; } .floating-container:hover { - height: 300px; + height: 200px; } .floating-container:hover .floating-button { box-shadow: 0 10px 25px rgba(44, 179, 240, 0.6); @@ -311,7 +325,7 @@ ul { right: 0; margin: auto; color: white; - line-height: 70px; + line-height: 65px; text-align: center; font-size: 23px; z-index: 100; @@ -320,11 +334,6 @@ ul { -webkit-transition: all 0.3s; transition: all 0.3s; } -.material-icons{ - line-height: 0; - color: white; -} -/* .floating-container .float-element { position: relative; display: block; @@ -356,4 +365,4 @@ ul { .floating-container .float-element:nth-child(3) { background: #FF9800; box-shadow: 0 20px 20px -10px rgba(255, 152, 0, 0.5); -}*/ +} diff --git a/app/templates/footer_button.html b/app/templates/footer_button.html new file mode 100644 index 0000000..c8450eb --- /dev/null +++ b/app/templates/footer_button.html @@ -0,0 +1,17 @@ + +
+
+
+ +
diff --git a/app/templates/get_courses.html b/app/templates/get_courses.html new file mode 100644 index 0000000..e3878a1 --- /dev/null +++ b/app/templates/get_courses.html @@ -0,0 +1,8 @@ + +{% include 'head.html' %} +{% include 'header.html' %} +{% include 'logo.html' %} +{% include 'subheader.html' %} +{% block content %} +{% include 'table.html' %} +{% endblock %} diff --git a/app/templates/get_info.html b/app/templates/get_info.html new file mode 100644 index 0000000..1e0182f --- /dev/null +++ b/app/templates/get_info.html @@ -0,0 +1,10 @@ + +{% include 'head.html' %} +{% include 'header.html' %} +{% include 'logo.html' %} +{% include 'subheader.html' %} +{% block content %} +{% if table %} +{% include 'table.html' %} +{% endif %} +{% endblock %} diff --git a/app/templates/head.html b/app/templates/head.html index adb798c..4e063b3 100644 --- a/app/templates/head.html +++ b/app/templates/head.html @@ -24,6 +24,7 @@ {% block content %} {% endblock %} +{% include 'footer_button.html'%} + {% include 'footer_button.html'%}