Skip to content

Commit

Permalink
Added basic timetable endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
PalAditya committed Oct 2, 2019
1 parent 113a5a1 commit 768ee9d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
9 changes: 9 additions & 0 deletions res/4/CS/1/2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"status":"200",
"data":[
{"time" : "10:00-12:00",
"subject": "Compiler design"},
{"time" : "12:00-1:00",
"subject": "Advanced Digital System Design"
}]
}
9 changes: 9 additions & 0 deletions res/4/CS/1/3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"status":"200",
"data":[
{"time" : "5:30-6:30",
"subject": "NSS"},
{"time" : "2:30-4:30",
"subject": "Advanced Algorithms"
}]
}
17 changes: 17 additions & 0 deletions scrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
except ImportError:
import urllib2
from bs4 import BeautifulSoup
from datetime import datetime
import json

class News:

Expand Down Expand Up @@ -106,6 +108,21 @@ def getBusSchedule ():

return response

@staticmethod
def getTimeTable(roll):
year = str(min((datetime.now().year- int(roll[0:2]) + 1), 4))
today = str(datetime.today().weekday())
branch = str(roll[2:4])
dual_or_single = str(roll[5:6])
dest = "res/" + year + "/" + branch + "/"\
+ dual_or_single + "/" + today + ".json"
print(dest)
try:
with open (dest, "r") as f:
data = json.loads(f.read())
return data
except Exception as e:
return {'status':'404','data':[]}
# if __name__ == "__main__":
# print News.getNews()
# print News.getNotices()
Expand Down
10 changes: 8 additions & 2 deletions server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Flask, jsonify, redirect
from flask import Flask, jsonify, request, redirect
from scrapper import News

app = Flask (__name__)
Expand Down Expand Up @@ -55,12 +55,18 @@ def busRoute () :
result = News.getBusSchedule()
return jsonify (result)

@app.route ('/timetable', methods=['GET'])
def timeTable () :
roll = request.args.get('roll')
result = News.getTimeTable(roll)
return jsonify (result)

######################
# 404 #
######################
@app.route('/<path:dummy>')
def fallback(dummy):
return redirect("http://iitbbs.herokuapp.com")
return redirect("http://iitbbs.herokuapp.com")


######################
Expand Down

0 comments on commit 768ee9d

Please sign in to comment.