-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.py
95 lines (76 loc) · 2.08 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
from flask import Flask, jsonify, request, redirect
from scrapper import News
import sys
import json
app = Flask (__name__)
######################
# INDEX #
######################
@app.route ('/', methods=['GET'])
def defaultRoute () :
return jsonify({
'author' : 'Developer Student Club, IIT Bhubaneswar',
'email' : '[email protected]/[email protected]',
'endpoint' : 'http://dsciitbbs-newsapi.herokuapp.com',
'project_name' : 'IITBBSNewsAPI',
'project_url' : 'https://github.com/dsciitbbs/iitbbsnewsapi/'
})
######################
# NEWS #
######################
@app.route ('/news', methods=['GET'])
def newsRoute () :
result = News.getNews()
return jsonify (result)
######################
# EVENTS #
######################
@app.route ('/events', methods=['GET'])
def eventsRoute () :
result = News.getEvents()
return jsonify (result)
######################
# NOTICES #
######################
@app.route ('/notices', methods=['GET'])
def noticesRoute () :
result = News.getNotices()
return jsonify (result)
######################
# NOTICES #
######################
@app.route ('/bus', methods=['GET'])
def busRoute () :
result = News.getBusSchedule()
return jsonify (result)
@app.route ('/timetable', methods=['GET'])
def timeTable () :
roll = request.args.get('roll')
subject = request.args.get('subject')
day = request.args.get('day')
result = News.getTimeTable(roll, subject, day)
return jsonify (result)
# Hacky solution for Python 2 :\
@app.route ('/tweets', methods=['GET'])
def tweets () :
result = News.getTweets()
if sys.version[0] == 3:
return jsonify (result)
else:
response = app.response_class(
response=str(result),
status = 200,
mimetype='application/json'
)
return response
######################
# 404 #
######################
@app.route('/<path:dummy>')
def fallback(dummy):
return redirect("http://dsciitbbs-newsapi.herokuapp.com")
######################
# START FLASK #
######################
if __name__ == "__main__":
app.run()