forked from apozharski/gradescope-api
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bf20576
commit 98eb168
Showing
5 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM ghcr.io/astral-sh/uv:python3.12-alpine | ||
|
||
ADD . /app | ||
|
||
WORKDIR /app | ||
RUN uv sync --frozen | ||
|
||
EXPOSE 5000 | ||
CMD ["uv", "run", "flask", "run", "--host=0.0.0.0"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from main import do_the_thing | ||
from flask import Flask, request, send_file | ||
import json | ||
import base64 | ||
from typing import Callable, Dict, Any | ||
from io import BytesIO | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route('/gradescope.ics') | ||
def gradescope_calendar(): | ||
try: | ||
# Get the base64 encoded query parameter | ||
encoded_data = request.args.get('data') | ||
if not encoded_data: | ||
return 'Missing data parameter', 400 | ||
|
||
# Decode base64 to JSON string | ||
try: | ||
json_str = base64.b64decode(encoded_data).decode('utf-8') | ||
except Exception as e: | ||
return f'Invalid base64 encoding: {str(e)}', 400 | ||
|
||
# Parse JSON | ||
try: | ||
data: Dict[str, Any] = json.loads(json_str) | ||
except json.JSONDecodeError as e: | ||
return f'Invalid JSON: {str(e)}', 400 | ||
|
||
# Validate required fields | ||
required_fields = ['email', 'pwd', 'sem'] | ||
for field in required_fields: | ||
if field not in data: | ||
return f'Missing required field: {field}', 400 | ||
|
||
# Call do_the_thing with the parameters | ||
file_data = do_the_thing( | ||
email=data['email'], | ||
pwd=data['pwd'], | ||
sem=data['sem'] | ||
) | ||
|
||
file_str = "".join(file_data) | ||
file_io = BytesIO(file_str.encode('utf-8')) | ||
|
||
# Send the file | ||
return send_file( | ||
file_io, | ||
mimetype='text/calendar', | ||
as_attachment=True, | ||
download_name='gradescope.ics' | ||
) | ||
|
||
except Exception as e: | ||
return f'Server error: {str(e)}', 500 | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
import json | ||
import base64 | ||
import dotenv | ||
dotenv.load_dotenv() | ||
|
||
if __name__ == "__main__": | ||
email = os.environ.get("GS_EMAIL") | ||
pwd = os.environ.get("GS_PWD") | ||
sem = os.environ.get("GS_SEM") | ||
|
||
# Login | ||
if email is None: | ||
email = input("Email: ") | ||
if pwd is None: | ||
pwd = input("Password: ") | ||
if sem is None: | ||
sem = input("Semester: ") | ||
|
||
json_data = { | ||
"email": email, | ||
"pwd": pwd, | ||
"sem": sem | ||
} | ||
|
||
json_str = json.dumps(json_data) | ||
encoded = base64.b64encode(json_str.encode('utf-8')).decode('utf-8') | ||
|
||
print(encoded) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.