/
app.py
49 lines (38 loc) · 1.08 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
from flask import Flask
from datetime import datetime
from downloader import main
from multiprocessing import Process, Queue
import traceback
import sys
app = Flask(__name__)
def acquire_data():
p = Process(target=acquire_data_async)
p.start()
def acquire_data_async():
try:
main()
except Exception :
print("Failed to acquire data")
print '-' * 60
traceback.print_exc(file=sys.stdout)
print '-' * 60
@app.route('/')
def homepage():
the_time = datetime.now().strftime("%A, %d. %B %Y %I:%M%p")
return """
<h1>Hello heroku</h1>
<p>It is currently {time}.</p>
<img src="http://loremflickr.com/600/400">
""".format(time=the_time)
@app.route('/download')
def download():
the_time = datetime.now().strftime("%A, %d. %B %Y %I:%M%p")
acquire_data()
return """
<h1>Hello heroku</h1>
<h2>It is currently {time}.</h2>
<h3>Started downloading data</h3>
<img src="http://loremflickr.com/600/400">
""".format(time=the_time)
if __name__ == '__main__':
app.run(debug=True, use_reloader=True)