Api site working, starting with calc speed

This commit is contained in:
Simon 2017-05-04 20:36:16 +02:00
parent 59036c6e6e
commit 744dcc7fd4
5 changed files with 117 additions and 13 deletions

2
.gitignore vendored
View File

@ -58,3 +58,5 @@ docs/_build/
# PyBuilder
target/
.ropeproject

View File

@ -24,6 +24,37 @@
</head>
<body>
{% set navigation_bar = [
('ferry', 'ferry', 'Färja'),
('timeleft', 'timeleft', 'Räkna ut tid kvar'),
] -%}
<!-- set the active page so we can change the nav accordingly -->
{% set active_page = active_page|default('ferry') -%}
{% block navbar -%}
<div class="container">
<nav class="teal lighten-3 navbar-default" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-left" >
{% for href, id, caption in navigation_bar -%}
<li {% if id == active_page -%} class="active"{% endif -%}>
<a href={{ url_for(href) }}>
{{ caption }}
</a>
<span class="sr-only"></span>
</li>
{% endfor -%}
</ul>
</div> <!-- /.navbar-header -->
</nav>
</div><!-- /.container -->
{% endblock %}
{% block body %}{% endblock %}

View File

@ -1,12 +1,20 @@
{% extends 'base.html' %}
{% set active_page = "ferry" %}
{% block navbar -%}
{{super()}}
{% endblock %}
{% block body %}
<!--
<nav class="teal lighten-3" role="navigation">
<div class="nav-wrapper container"><a id="logo-container" href="#" class="brand-logo">Logo</a>
<div class="nav-wrapper container"><a id="logo-container" href="#" class="brand-logo">Färja till Gräsö</a>
<a href="#" data-activates="nav-mobile" class="button-collapse"><i class="material-icons">menu</i></a>
</div>
</nav>
-->
<div class="container teal lighten-5">
<div class="section">
@ -16,28 +24,23 @@
<thead>
<tr>
<th>Tid</th>
<th>Från</th>
{% if info %}
<th>Info</th>
{% endif %}
</tr>
</thead>
{% for value in data %}
<tr>
<td>{{ value['time'] }} </td>
<td>nånting</td>
{% if 'info' in value %}
<td>{{ value['info'] }}</td>
{% else %}
<td>nånting</td>
<td>{{ value['info'][0] }}</td>
{% endif %}
</tr>
{% endfor %}
</table>
</div>
</div>
<br><br>
</div>

View File

@ -0,0 +1,55 @@
{% extends 'base.html' %}
{% set active_page = "timeleft" %}
{% block navbar -%}
{{super()}}
{% endblock %}
{% block body %}
<div class="container teal lighten-5">
<div class="section">
<!-- Icon Section -->
<div class="container-fluid">
<h5 class="center">
Snitthastighet
</h5>
<div class="container">
<form>
<div class="form-group row">
<label for="inputTimeleft" class="col-sm-2 col-form-label">Tid kvar (i min)</label>
<div >
<input class="form-control" type="number" id="inputTimeleft" >
</div>
</div>
<div class="form-group row">
<label for="inputRange" class="col-sm-2 col-form-label">Sträcka kvar (i km)</label>
<div >
<input class="form-control" type="number"id="inputRange" >
</div>
</div>
<button type="submit" class="btn btn-primary">Send</button>
</form>
</div>
</div>
</div>
<br><br>
</div>
<footer class="page-footer teal">
<div class="footer-copyright">
<div class="container">
Made by Simon
</div>
</div>
</footer>
{% endblock %}

View File

@ -1,3 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from ferry.app import app
from flask import render_template
import requests
@ -5,11 +8,19 @@ from datetime import datetime
@app.route('/')
@app.route('/index')
def index():
def ferry():
data = ferry_request()
print data
return render_template('index.html', data=data)
info = False
for value in data:
if 'info' in value:
info = True
break
return render_template('ferry.html', data=data, info=info)
@app.route("/time")
def timeleft():
return render_template("timeleft.html")
def extract_time(json):
@ -20,6 +31,7 @@ def extract_time(json):
return -1
# <GT name ="DepartureTime" value='$dateadd(0.10:15:00)' />
def ferry_request():
url = 'http://api.trafikinfo.trafikverket.se/beta/data.json'
headers = {'Content-Type': 'text/xml'}
@ -68,4 +80,5 @@ def ferry_request():
return result
else:
print r.text
return 0