-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
42 lines (30 loc) · 1004 Bytes
/
manage.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
import datetime as dt
from flask.ext.script import Manager
from app import app
from app import db
from app import CurrentGridData
from main import main
manager = Manager(app)
@manager.command
def update_grid(manual=False):
"""
Update the grid on a certain interval
"""
hours_of_day = [6, 9, 12, 15, 18, 21] # hours to use for scheduler
if not (manual or dt.datetime.now().hour in hours_of_day):
return -1
# Update the data
current_data = main()
# Write data to database and delete old data
print('Deleting data from table CurrentGridData')
db.session.query(CurrentGridData).delete()
print('Writing data to table CurrentGridData')
for row in current_data.iterrows():
row = row[1]
row_dat = CurrentGridData(row['gr_id'], row['PM25'], row['O3'],
row['AQI'], row['time'])
db.session.add(row_dat)
db.session.commit()
return 1
if __name__ == "__main__":
manager.run()