-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
52 lines (38 loc) · 1.43 KB
/
app.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
import logging
import yaml
import json
from flask import Flask, render_template, request, session as flaskSession
from flask_ask import Ask, statement, question, session
from scraper import get_result
from bs4 import BeautifulSoup
import logging
from logging.handlers import RotatingFileHandler
app = Flask(__name__)
ask = Ask(app, "/")
logging.getLogger("flask_ask").setLevel(logging.DEBUG)
@ask.launch
def index():
welcome_msg = render_template('welcome')
return question(welcome_msg)
@ask.intent('usn', mapping={'year': 'year', 'department': 'department', 'number': 'number'})
def getRes(year, department, number):
YEAR = "%02d" % int(year)
DEPT = department
NUM = "%03d" % int(number)
usn = "1RV{}{}{}".format(YEAR, DEPT, NUM)
result = get_result(usn)
if (result == "400"):
notFound = render_template("notFound", usn=usn)
return statement(notFound).simple_card(title='Not Found', content="Result Not Found for {}".format(usn))
else:
Found = render_template("found", result=result)
card_content = BeautifulSoup(Found)
return statement(Found).simple_card(title=result["sgpa"], content=card_content.text)
@app.route('/status', methods=['GET', 'POST'])
def status():
return "running"
if __name__ == '__main__':
handler = RotatingFileHandler('app.log', maxBytes=10000, backupCount=1)
handler.setLevel(logging.INFO)
app.logger.addHandler(handler)
app.run()