-
Notifications
You must be signed in to change notification settings - Fork 12
/
scheduleformatter.py
119 lines (106 loc) · 4.3 KB
/
scheduleformatter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
'''
Copyright (C) 2014 Muhd Amirul Ashraf bin Mohd Fauzi <[email protected]>
This file is part of Automatic IIUM Schedule Formatter.
Automatic IIUM Schedule Formatter is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Automatic IIUM Schedule Formatter is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Automatic IIUM Schedule Formatter. If not, see <http://www.gnu.org/licenses/>.
'''
import hashlib
import os
from datetime import datetime,timedelta
import re
try:
import JSON
except ImportError:
import json as JSON
from staticsettings import DEFAULTDATA
from models import SavedSchedule, ErrorLog
from flask import Flask, render_template, request, g
import logging
from bootstrap import app
from staticsettings import RECAPTCHA_KEY,RECAPTCHA_PUBLIC_KEY,DEBUG,DEFAULTDATA
@app.route('/scheduleformatter/',methods=['GET','POST'])
def schedule_formatter():
if(request.method=='GET'):
dtype=request.args.get("dtype","unformatted")
if(dtype=="completeschedule"):
token=request.args.get("token",None)
if(not token):
return
else:
theinstance=SavedSchedule.get_by_key_name(token)
if(theinstance==None):
return "Sorry, the requested schedule is no longer in the database. You should save it on your computer earlier."
data=theinstance.data
return data
return
token=request.args.get("token",None)
if(not token):
data=DEFAULTDATA
else:
theinstance=SavedSchedule.get_by_key_name(token)
if(theinstance==None):
return "Sorry, the requested schedule is no longer in the database. You should save it on your computer earlier."
data=theinstance.data
arg={}
arg["RECAPTCHA_PUBLIC_KEY"]=RECAPTCHA_PUBLIC_KEY
arg["RECAPTCHA_KEY"]=RECAPTCHA_KEY
arg["data"]=data
text=render_template('scheduleformatterpage.html', **arg)
header={"Access-Control-Allow-Origin":"http://my.iium.edu.my"}
return text,200,header
else:
thedata=request.form.get("data")
customtoken=request.form.get("custom",False)
if not customtoken:
token=str(hashlib.md5(str(os.urandom(4))).hexdigest())
else:
token=request.form.get("ctoken")
theschedule=SavedSchedule(token=token)
theschedule.data=thedata
theschedule.createddate=datetime.now()
if(request.form.get("no_post_process","0")!="1"):
theschedule.post_process()
theschedule.put()
header={"Access-Control-Allow-Origin":"http://my.iium.edu.my"}
return token,200,header
@app.route('/scheduleloader/')
def schedule_loader():
token=request.args.get("ctoken")
isfacebook=request.args.get("facebook",False)
if(request.args.get("test")):
theinstance=SavedSchedule.get_by_key_name(token)
if(theinstance):
return "true"
else:
return "false"
if(isfacebook):
path = 'facebookloader.html'
else:
path = 'scheduleloader.html'
return render_template(path,token=token)
@app.route('/error/',methods=['GET','POST'])
def error_handler():
if(request.method=='POST'):
submitter=request.form.get("submitter")
html=request.form.get("html")
additionaldata=request.form.get("add")
newrecord=ErrorLog()
newrecord.submitter=submitter
newrecord.html=html
newrecord.error=request.form.get("error")
newrecord.additionalinfo=additionaldata
newrecord.created_at=datetime.now()
newrecord.put()
return "Thank you for submitting a bug report. I will take some time before I read this error, and take more time before I fix it. So... just be patient."
return render_template('error_form.html')
@app.route('/')
def main():
return render_template('mainpage.html')