-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspacex.py
78 lines (58 loc) · 2.06 KB
/
spacex.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from datetime import datetime
import random
import os
from flask import Flask, render_template, redirect, url_for
from flask_sslify import SSLify
from flaskext.markdown import Markdown
from app.dashboard import get_launches
from app.details import get_launch_details
app = Flask(__name__)
sslify = SSLify(app)
app.config['TEMPLATES_AUTO_RELOAD'] = True
Markdown(app)
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
@app.route('/')
def dashboard():
launches = get_launches()
if launches == 'error':
return render_template('bs/error.html', error=True)
else:
return render_template('bs/dashboard.html', launches=launches)
@app.route('/all-launches/')
def launches():
launches = get_launches(return_all=True)
if launches == 'error':
return render_template('bs/error.html', error=True)
else:
return render_template('bs/alllaunches.html', launches=launches)
@app.route('/launch/<int:launch_id>')
def launch(launch_id):
launch_details = get_launch_details(launch_id)
if launch == 'error':
return render_template('bs/error.html', error=True)
else:
return render_template('bs/launch_detail.html', launch=launch_details)
@app.route('/random/')
def random_launch():
launches = get_launches(return_all=True)
secure_random = random.SystemRandom()
choice = secure_random.choice(launches)
return redirect(url_for('launch', launch_id=choice['flight_number']))
@app.template_filter('dt')
def datetimeformat(value, format='%H:%M / %d-%m-%Y'):
return value.strftime(format)
@app.template_filter('detail_dt')
def datetimeformat_detail(value, format='%H:%M / %d-%m-%Y'):
datetime_object = datetime.strptime(value, '%Y-%m-%dT%H:%M:%S.%fZ')
return datetime_object.strftime(format)
@app.template_filter('yt')
def youtubelink(link):
return link[32:]
@app.context_processor
def inject_readme():
# filename is case sensitive
with open(os.path.join(APP_ROOT, 'README.md')) as f:
content = f.read()
return dict(readme=content)
if __name__ == '__main__':
app.run()