Add viewer prototype for packages

This commit is contained in:
IamTheFij 2018-02-05 20:40:14 -08:00
parent 8f251a5a0f
commit 3085a45ac9
11 changed files with 175 additions and 3 deletions

View File

@ -19,3 +19,13 @@ services:
build: ./parsers/package-tracking build: ./parsers/package-tracking
ports: ports:
- "8183:3000" - "8183:3000"
viewer_package_tracking:
build: ./viewers/package-tracking
volumes:
- ./viewers/package-tracking:/usr/src/app
links:
- indexer
environment:
INDEXER_URL: http://indexer:5000
ports:
- "8184:5000"

View File

@ -68,9 +68,9 @@ class EmailToken(db.Model):
return jsonify(tokens=[token.as_dict() for token in results]) return jsonify(tokens=[token.as_dict() for token in results])
@app.route("/") @app.route('/')
def check(): def check():
return "OK" return 'OK'
@app.route('/token', methods=['POST']) @app.route('/token', methods=['POST'])
@ -125,6 +125,6 @@ def get_token(token_id):
return jsonify(token.as_dict()) return jsonify(token.as_dict())
if __name__ == "__main__": if __name__ == '__main__':
db.create_all() db.create_all()
app.run(host='0.0.0.0', port=5000) app.run(host='0.0.0.0', port=5000)

View File

@ -0,0 +1,8 @@
FROM python:3.6-onbuild
ENV FLASK_DEBUG=1
EXPOSE 5000
# TODO: Track debug in env and use threads
CMD python -m viewer.main

View File

@ -0,0 +1,48 @@
# Indexer
Simple service to act as data layer for Email Assitant
# Healthcheck
Path: `/`
Returns: `OK`
# Tokens
Path: `/token`
## POST
Accepts JSON representation of a EmailToken
Accepts:
|Field|Type|Example|
|---|---|---|
|`"subject"`|String|`"Your shipping info"`|
|`"token"`|String|`"123456"`|
|`"type"`|String|`"SHIPPING"`|
|`"metadata"`|Object (optional)|`{"carrier": "UPS"}`|
|`"disabled"`|Boolean (optional)|`false`|
Returns:
|Field|Type|Example|
|---|---|---|
|`"success"`|Boolean|`true`|
|`"token"`|Token Object|`{"id": 1, ... }`|
## GET
Path: `/token`
Returns all Token Objects
Parameters:
|Parameter|Description|Example|
|---|---|---|
|`"filter_type"`|String token type to filter by|`SHIPPING`|
Returns:
|Field|Type|Example|
|---|---|---|
|`"tokens"`|List of Token Objects|`[{"id": 1, ... }, ...]`|
Path: `/token/<int:token_id>`
Returns Token Object with that ID

View File

@ -0,0 +1,10 @@
version: '2'
services:
main:
build: .
environment:
INDEXER_URL: http://localhost:8181
volumes:
- .:/usr/src/app
ports:
- "8184:5000"

View File

@ -0,0 +1,2 @@
ipdb
ipython

View File

@ -0,0 +1,3 @@
flask==0.12.2
requests
flask_bootstrap

View File

@ -0,0 +1,34 @@
import os
import sys
from flask_bootstrap import Bootstrap
import flask
import requests
app = flask.Flask(__name__)
app.config['DEBUG'] = True
Bootstrap(app)
indexer_url = os.environ.get('INDEXER_URL', 'http://indexer')
@app.route('/')
def check():
return 'OK'
@app.route('/shipping')
def get_tokens():
resp = requests.get(
indexer_url+'/token',
params={'filter_type': 'SHIPPING'},
)
resp.raise_for_status()
print(resp.text, file=sys.stderr)
tokens = resp.json().get('tokens')
return flask.render_template('shipping.html', trackers=tokens)
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)

View File

@ -0,0 +1,30 @@
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
{% block head %}
{% endblock %}
<title>{% block title %}Email Assistant{% endblock %}</title>
</head>
<body>
{% block body %}
<div class="container">
{% block container %}
{% endblock %}
</div>
{% endblock %}
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>

View File

@ -0,0 +1,27 @@
{% extends "base.html" %}
{% block title %}This is an example page{% endblock %}
{% block container %}
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Tracking Number</th>
<th scope="col">Carrier</th>
<th scope="col">Subject</th>
<th scope="col">Disabled</th>
</tr>
</thead>
<tbody>
{% for row in trackers %}
<tr>
<th scope="row">{{ row['id'] }}</th>
<td>{{ row['token'] }}</td>
<td>{{ row['metadata']['carrier_name'] }}</td>
<td>{{ row['subject'] }}</td>
<td>{{ row['disabled'] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}