forked from fernaoguerra/fundamentus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
executable file
·33 lines (28 loc) · 907 Bytes
/
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
#!/usr/bin/env python3
from flask import Flask, jsonify, make_response
from flask_cors import CORS, cross_origin
from fundamentus import get_data, get_todays_data
from datetime import datetime
import json, csv
app = Flask(__name__)
cors = CORS(app)
app.config['CORS_HEADERS'] = 'Content-Type'
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True
# First update
lista = (get_data())
dia = datetime.strftime(datetime.today(), '%d')
@app.route("/")
@cross_origin()
def json_api():
global lista, dia
# Then only update once a day
if dia == datetime.strftime(datetime.today(), '%d'):
# print('a lista esta ' + lista)
lista = get_todays_data()
return (lista)
else:
# lista = (get_data())
lista, dia = (get_data()), datetime.strftime(datetime.today(), '%d')
#print('a lista esta ' + lista)
return (lista)
app.run(debug=True, host='0.0.0.0')