This repository has been archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.py
161 lines (127 loc) · 4.83 KB
/
server.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#importing the required tornado files
import tornado.ioloop
import tornado.web
import tornado.options
import tornado.httpserver
from tornado import gen
from tornado.options import define, options
import os
# files import for fetching the data
from login import login
from facultyadvisor import getFacultyAdvisor
from timetable import getTimetable
from attendance import getAttendance
from examSchedule import getExamSchedule
from cal import getCalmarks
from spotlight import getSpotlight
from academicHistory import getAcademicHistory
from changePassword import changePassword
from messages import getMessages
from marks14 import getMarks14
from marks15 import getMarks15
from refresh import refresh
#importing the mechanical borwser
from mechanize import Browser
define("port", default = 8000, help="Contact the One who made it Contact PIYUSH :P", type = int)
#overloading the tornado.web.Application
class Application(tornado.web.Application):
def __init__(self):
handlers = [ (r"/", SampleHandler), (r"/login", LoginHandler), (r"/facadvdet", FacultyAdvisorHandler), (r"/timetable", TimetableHandler), (r"/attendance", AttendanceHandler), (r"/exam", ExamScheduleHandler), (r"/marks", MarksHandler), (r"/calmarks", CALHandler), (r"/spotlight", SpotlightHandler), (r"/acadhist", AcademicHistoryHandler), (r"/changepsswd", ChangePasswordHandler), (r"/message", MessageHandler), (r"/refresh", RefreshHandler)]
settings = dict(debug = True)
tornado.web.Application.__init__(self, handlers, **settings)
#for knowing the API status
class SampleHandler(tornado.web.RequestHandler):
def post(self):
self.write("Hello!! And welcome To Student API in tornado")
#for logging into the student login
class LoginHandler(tornado.web.RequestHandler):
def post(self):
regno = self.get_argument("regNo")
psswd = self.get_argument("psswd")
br = login(regno, psswd)
self.write(dict(Registration_No = regno, Campus = "Vellore", status = "You are logged in"))
#for getting the faculty advisor details
class FacultyAdvisorHandler(tornado.web.RequestHandler):
def post(self):
regno = self.get_argument("regNo")
psswd = self.get_argument("psswd")
self.write(dict(Faculty_advisor_details = getFacultyAdvisor(regno, psswd)))
#for getting the time table details
class TimetableHandler(tornado.web.RequestHandler):
@gen.coroutine
def post(self):
regno = self.get_argument("regNo")
psswd = self.get_argument("psswd")
self.write(getTimetable(regno, psswd))
#for getting the attendance details
class AttendanceHandler(tornado.web.RequestHandler):
@gen.coroutine
def post(self):
regno = self.get_argument("regNo")
psswd = self.get_argument("psswd")
self.write(getAttendance(regno, psswd))
#for getting the exam schedule details
class ExamScheduleHandler(tornado.web.RequestHandler):
@gen.coroutine
def post(self):
regno = self.get_argument("regNo")
psswd = self.get_argument("psswd")
self.write(getExamSchedule(regno, psswd))
#for getting the marks details
class MarksHandler(tornado.web.RequestHandler):
@gen.coroutine
def post(self):
regno = self.get_argument("regNo")
psswd = self.get_argument("psswd")
if int(regno[0:2]) > 14:
self.write(getMarks15(regno, psswd))
else:
self.write(getMarks14(regno, psswd))
#for getting the CAL marks details
class CALHandler(tornado.web.RequestHandler):
@gen.coroutine
def post(self):
regno = self.get_argument("regNo")
psswd = self.get_argument("psswd")
if int(regno[0:2]) > 14:
self.write(getCalmarks(regno, psswd))
else:
self.write(dict(status = "Not Supported"))
#for getting the Spotlight details
class SpotlightHandler(tornado.web.RequestHandler):
def post(self):
self.write(getSpotlight())
#for getting the Academic History details
class AcademicHistoryHandler(tornado.web.RequestHandler):
@gen.coroutine
def post(self):
regno = self.get_argument("regNo")
psswd = self.get_argument("psswd")
self.write(getAcademicHistory(regno, psswd))
#for getting the statuss for changing password
class ChangePasswordHandler(tornado.web.RequestHandler):
def post(self):
regno = self.get_argument("regNo")
psswd = self.get_argument("psswd")
npsswd = self.get_argument("npsswd")
self.write(changePassword(regno, psswd, npsswd))
#for getting the messages details
class MessageHandler(tornado.web.RequestHandler):
@gen.coroutine
def post(self):
regno = self.get_argument("regNo")
psswd = self.get_argument("psswd")
self.write(getMessages(regno, psswd))
#for getting all the data
class RefreshHandler(tornado.web.RequestHandler):
@gen.coroutine
def post(self):
regno = self.get_argument("regNo")
psswd = self.get_argument("psswd")
self.write(refresh(regno, psswd))
#main fuction to start the API
if __name__ == "__main__":
tornado.options.parse_command_line()
http_server = tornado.httpserver.HTTPServer(Application())
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()