From f2f734194c03dfff2024cf417c502515ddb7a855 Mon Sep 17 00:00:00 2001 From: jwansek Date: Sat, 21 May 2022 22:38:52 +0100 Subject: Added running as an API --- Smarker/database.py | 17 ++++++++++++----- Smarker/requirements.txt | 2 -- Smarker/smarker.conf | 24 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 Smarker/smarker.conf (limited to 'Smarker') diff --git a/Smarker/database.py b/Smarker/database.py index 37a44db..a3f77af 100644 --- a/Smarker/database.py +++ b/Smarker/database.py @@ -1,5 +1,6 @@ from dataclasses import dataclass import pymysql +import secrets import yaml @dataclass @@ -54,7 +55,8 @@ class SmarkerDatabase: CREATE TABLE students( student_no VARCHAR(10) PRIMARY KEY NOT NULL, name TEXT NOT NULL, - email VARCHAR(50) NOT NULL + email VARCHAR(50) NOT NULL, + apikey VARCHAR(64) NOT NULL ); """) cursor.execute(""" @@ -175,8 +177,8 @@ class SmarkerDatabase: email (str): Student's email """ with self.__connection.cursor() as cursor: - cursor.execute("INSERT INTO students VALUES (%s, %s, %s);", - (student_id, name, email)) + cursor.execute("INSERT INTO students VALUES (%s, %s, %s, %s);", + (student_id, name, email, secrets.token_urlsafe(32))) self.__connection.commit() def add_submission(self, student_id, assessment_name, report_yaml, files): @@ -198,9 +200,9 @@ class SmarkerDatabase: cursor.execute(""" INSERT INTO submitted_files (submission_id, file_id, file_text) - VALUES (%s, (SELECT file_id FROM assessment_file WHERE file_name = %s), %s); + VALUES (%s, (SELECT file_id FROM assessment_file WHERE file_name = %s AND assessment_name = %s), %s); """, ( - submission_id, file_name, file_contents + submission_id, file_name, assessment_name, file_contents )) self.__connection.commit() @@ -240,6 +242,11 @@ class SmarkerDatabase: cursor.execute("SELECT file_name FROM assessment_file WHERE assessment_name = %s;", (assessment_name, )) return [i[0] for i in cursor.fetchall()] + def valid_apikey(self, key): + with self.__connection.cursor() as cursor: + cursor.execute("SELECT apikey FROM students WHERE apikey = %s", (key, )) + return key in [i[0] for i in cursor.fetchall()] + if __name__ == "__main__": with SmarkerDatabase(host = "vps.eda.gay", user="root", passwd=input("Input password: "), db="Smarker", port=3307) as db: # print(db.get_assessments_required_files("example")) diff --git a/Smarker/requirements.txt b/Smarker/requirements.txt index 3be9c36..af89c27 100644 --- a/Smarker/requirements.txt +++ b/Smarker/requirements.txt @@ -1,5 +1,3 @@ -# sudo apt-get install wkhtmltopdf -# https://github.com/olivierverdier/python-latex-highlighting Jinja2==3.0.3 misaka==2.1.1 Pygments==2.10.0 diff --git a/Smarker/smarker.conf b/Smarker/smarker.conf new file mode 100644 index 0000000..3416564 --- /dev/null +++ b/Smarker/smarker.conf @@ -0,0 +1,24 @@ +[mysql] +host = vps.eda.gay +port = 3307 +user = root +passwd = ************ + +[tex] +columns = 1 +show_full_docs = True +show_source = True +show_all_regex_occurrences = True +show_all_run_output = True + +[md] +show_full_docs = False +show_source = False +show_all_regex_occurrences = True +show_all_run_output = False + +[txt] +show_full_docs = True +show_source = True +show_all_regex_occurrences = True +show_all_run_output = True \ No newline at end of file -- cgit v1.2.3