-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
48 lines (41 loc) · 1.22 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
# -*- coding: utf-8 -*-
"""
Main flask process
"""
from os import environ as env
import json
import atexit
from flask import Flask, jsonify
from apscheduler.schedulers.background import BackgroundScheduler
from apscheduler.triggers.interval import IntervalTrigger
import requests
from mail import send_mail
from scrapers.settings import load_env
load_env()
APP = Flask(__name__)
REQUESTS_SESSION = requests.Session()
SCHEDULER = BackgroundScheduler()
SCHEDULER.start()
SCHEDULER.add_job(
func=send_mail,
trigger=IntervalTrigger(minutes=1),
id='send_mail',
name='Poll IIT KGP\'s noticeboards every minute',
replace_existing=True)
atexit.register(lambda: SCHEDULER.shutdown()) # pylint: disable=W0108
@APP.route('/', methods=['GET'])
def index():
"""
Handle http request to root
"""
notices = REQUESTS_SESSION.get(env['VERITAS_URL'])
return jsonify(notices.json())
@APP.route('/<string:noticeboard>', methods=['GET'])
def get_type(noticeboard):
"""
Handle http request for specific type
"""
notices = REQUESTS_SESSION.get(env['VERITAS_URL'] + noticeboard)
return jsonify(notices.json())
if __name__ == "__main__":
APP.run(debug=True, host='0.0.0.0', port=5010, use_reloader=False)