|
|
|
import flask
|
|
|
|
import flask_apscheduler
|
|
|
|
import feedtools
|
|
|
|
import json
|
|
|
|
|
|
|
|
APP = flask.Flask(__name__,
|
|
|
|
static_url_path="",
|
|
|
|
static_folder="static",
|
|
|
|
template_folder="templates")
|
|
|
|
|
|
|
|
# Initialize Flask-APScheduler
|
|
|
|
# https://github.com/viniciuschiele/flask-apscheduler
|
|
|
|
# Thanks Crunk for pointing to this extention!
|
|
|
|
scheduler = flask_apscheduler.APScheduler()
|
|
|
|
scheduler.api_enabled = False
|
|
|
|
scheduler.init_app(APP)
|
|
|
|
scheduler.start()
|
|
|
|
|
|
|
|
@scheduler.task('interval', id='update', minutes=10)
|
|
|
|
def update():
|
|
|
|
print('Updating the Multifeeder!')
|
|
|
|
feedtools.update()
|
|
|
|
|
|
|
|
@APP.route("/")
|
|
|
|
def index():
|
|
|
|
db = feedtools.load()
|
|
|
|
template = flask.render_template(
|
|
|
|
"index.html",
|
|
|
|
db=db,
|
|
|
|
)
|
|
|
|
return template
|
|
|
|
|
|
|
|
@APP.route("/API/latest/<num>")
|
|
|
|
def latest(num):
|
|
|
|
request = feedtools.latest(num)
|
|
|
|
response = APP.response_class(
|
|
|
|
response=json.dumps(request),
|
|
|
|
status=200,
|
|
|
|
mimetype='application/json'
|
|
|
|
)
|
|
|
|
return response
|
|
|
|
|
|
|
|
@APP.route("/API/today/")
|
|
|
|
def today():
|
|
|
|
request = feedtools.today()
|
|
|
|
response = APP.response_class(
|
|
|
|
response=json.dumps(request),
|
|
|
|
status=200,
|
|
|
|
mimetype='application/json'
|
|
|
|
)
|
|
|
|
return response
|
|
|
|
|
|
|
|
@APP.route("/API/past/<days>")
|
|
|
|
def past(days):
|
|
|
|
request = feedtools.past(days)
|
|
|
|
response = APP.response_class(
|
|
|
|
response=json.dumps(request),
|
|
|
|
status=200,
|
|
|
|
mimetype='application/json'
|
|
|
|
)
|
|
|
|
return response
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
feedtools.update()
|
|
|
|
APP.debug = True
|
|
|
|
APP.run(port=5678)
|
|
|
|
|