-
Notifications
You must be signed in to change notification settings - Fork 0
/
slcm.py
103 lines (89 loc) · 3.43 KB
/
slcm.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
from flask import Flask, render_template, request, Response, redirect
from getcaptchaimg import login_to_website
from htm2json import Attendance2JSON, Internals2JSON, Calendar2JSON, name_scrape, image_scrape
from json import dumps
from json2html import *
import requests
from PIL import Image
import io
import base64
app = Flask(__name__)
@app.route("/")
def hello():
return render_template("index.html")
@app.route("/login")
def loginpage():
return render_template("loginpage.html")
@app.route("/authors")
def authorspage():
return render_template("authors.html")
@app.route("/livestatus")
def livestatus():
return render_template("livestatus.html")
@app.route("/results", methods=["POST"])
def getAttendance():
print(request.form['username'], request.form['password'])
login_to_website(request.form['username'], request.form['password'])
attendanceJSON = Attendance2JSON()
mark2json = Internals2JSON()
calendarJSON = Calendar2JSON()
name = name_scrape()
calendarfinal = json2html.convert(json=calendarJSON['calendar'])
attendancefinal = json2html.convert(json=attendanceJSON['attendance'])
markfinal = mark2json['marks']
url = "https://slcm.manipal.edu/imagereader.aspx"
imagelink = image_scrape()
imagepath = imagelink.split("ImagePath=", 1)[1]
querystring = {"FileName": "", "ImagePath": "{}".format(imagepath)}
response = requests.request("GET", url, params=querystring)
image = Image.open(io.BytesIO(response.content))
encoded = base64.b64encode(response.content).decode('UTF-8')
datauri = "data:image/png;base64," + encoded
return render_template("afterlogin.html", mark=markfinal, greetingname=name, atten=attendancefinal, datauri=datauri, cal=calendarfinal)
@app.route("/api/v1/post", methods=["POST"])
def handleRequest():
request_body = request.get_json()
username = request_body['username']
password = request_body['password']
tpe = request_body['type']
if(tpe == "ATTENDANCE"):
login_to_website(username, password)
jsn = Attendance2JSON()
jsonfinal = dumps(jsn, indent=4, sort_keys=True)
resp = Response(jsonfinal, 200)
resp.headers['Content-Type'] = "application/json"
return resp
elif(tpe == "MARKS"):
login_to_website(username, password)
jsn = Internals2JSON()
jsonfinal = dumps(jsn, indent=4, sort_keys=True)
resp = Response(jsonfinal, 200)
resp.headers['Content-Type'] = "application/json"
return resp
elif(tpe == "CALENDAR"):
login_to_website(username, password)
jsn = Calendar2JSON()
jsonfinal = dumps(jsn, indent=4, sort_keys=True)
resp = Response(jsonfinal, 200)
resp.headers['Content-Type'] = "application/json"
return resp
elif(tpe == "ALL"):
login_to_website(username, password)
jsn1 = Internals2JSON()
jsn2 = Attendance2JSON()
jsn3 = Calendar2JSON()
name = name_scrape()
image = image_scrape()
imagescrape = {'imageurl': image}
namescrape = {'name': name}
jsn = {**namescrape, **imagescrape, **jsn2, **jsn1, **jsn3}
jsonfinal = dumps(jsn, indent=4, sort_keys=True)
resp = Response(jsonfinal, 200)
resp.headers['Content-Type'] = "application/json"
return resp
else:
resp = Response("Error", 501)
return resp
return "Error"
if __name__ == "__main__":
app.run(port=5000, debug=True)