email-assistant/viewers/main/viewer/main.py

51 lines
1.1 KiB
Python
Raw Normal View History

2018-02-06 04:40:14 +00:00
import os
import sys
import flask
import requests
app = flask.Flask(__name__)
app.config['DEBUG'] = True
indexer_url = os.environ.get('INDEXER_URL', 'http://indexer')
2018-04-06 00:00:48 +00:00
@app.route('/healthcheck')
def healthcheck():
return 'OK'
2018-02-06 04:40:14 +00:00
@app.route('/')
2018-04-06 00:00:48 +00:00
def home():
2018-02-09 20:58:05 +00:00
return flask.render_template('home.html')
2018-02-06 04:40:14 +00:00
@app.route('/shipping')
def get_tokens():
resp = requests.get(
indexer_url+'/token',
params={
'filter_type': 'SHIPPING',
'desc': True,
},
2018-02-06 04:40:14 +00:00
)
resp.raise_for_status()
tokens = resp.json().get('tokens')
for token in tokens:
try:
resp = requests.get(
'http://viewer_package_tracking:3000/info/'+token['token']
)
resp.raise_for_status()
print('Response: ', resp.text, file=sys.stderr)
info = resp.json()
token['metadata'].update(info)
except Exception as e:
print('Error', e, file=sys.stderr)
pass
2018-02-06 04:40:14 +00:00
return flask.render_template('shipping.html', trackers=tokens)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)