A barebones python tool to fix the inconvenient and incorrect iCal format of the UQ timetable while still allowing subscription and auto-updating of events
https://topost.net/calfix
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.8 KiB
72 lines
1.8 KiB
3 years ago
|
from flask import Flask, flash, request, redirect, make_response
|
||
|
|
||
|
from config import Config
|
||
|
|
||
|
from flask_wtf import FlaskForm
|
||
|
from wtforms import StringField, PasswordField, BooleanField, SubmitField
|
||
|
from wtforms.validators import DataRequired
|
||
|
|
||
|
app = Flask(__name__)
|
||
|
app.config.from_object(Config)
|
||
|
|
||
|
from flask_wtf import FlaskForm
|
||
|
from wtforms import StringField, PasswordField, BooleanField, SubmitField
|
||
|
from wtforms.validators import DataRequired
|
||
|
|
||
|
class URLForm(FlaskForm):
|
||
|
urlfield = StringField('urlfield', validators=[DataRequired()])
|
||
|
submit = SubmitField('Go')
|
||
|
|
||
|
from flask import render_template
|
||
|
|
||
|
import requests
|
||
|
import re
|
||
|
|
||
|
from reform import reformat_cal
|
||
|
|
||
|
TIMETABLEURL = "https://timetable.my.uq.edu.au:443/even/rest/calendar/ical/"
|
||
|
|
||
|
@app.route('/update', methods=['GET'])
|
||
|
def get_cal():
|
||
|
cd = request.args.get('code')
|
||
|
|
||
|
if (cd != None):
|
||
|
print(cd)
|
||
|
url = TIMETABLEURL + cd
|
||
|
try:
|
||
|
cal = reformat_cal(url)
|
||
|
except:
|
||
|
return redirect("/?error=fail")
|
||
|
|
||
|
resp = make_response(cal)
|
||
|
resp.headers["Content-Type"] = "text/calendar; charset=utf-8"
|
||
|
return resp
|
||
|
else:
|
||
|
return redirect("/?error=fail")
|
||
|
|
||
|
@app.route('/', methods=['GET', 'POST'])
|
||
|
def hello():
|
||
|
form = URLForm()
|
||
|
if form.validate_on_submit():
|
||
|
url = form.urlfield.data
|
||
|
code = url.split("/")[-1]
|
||
|
rdr = f"/calfix/update?code={code}"
|
||
|
try:
|
||
|
cal = reformat_cal(TIMETABLEURL + code)
|
||
|
print(cal)
|
||
|
flash("Download/Subscribe link")
|
||
|
flash(rdr)
|
||
|
except:
|
||
|
flash("Invalid calendar link")
|
||
|
flash("/")
|
||
|
|
||
|
# return redirect(rdr)
|
||
|
|
||
|
# print('url', url)
|
||
|
# newcal = reformat_cal(url)
|
||
|
|
||
|
return render_template('index.html', title='cal rewrite', form=form)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
app.run(port=25565)
|