Skip to content

Commit

Permalink
buh
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarreddypatil committed Jan 24, 2025
1 parent bf20576 commit 98eb168
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Dockerfile
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"]
58 changes: 58 additions & 0 deletions app.py
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)
29 changes: 29 additions & 0 deletions encode.py
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)
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"beautifulsoup4>=4.12.3",
"flask>=3.1.0",
"ics>=0.7.2",
"python-dotenv>=1.0.1",
"requests>=2.32.3",
Expand Down
119 changes: 119 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 98eb168

Please sign in to comment.