Added apicall to flask, problm with åäö
This commit is contained in:
parent
8f708d5df0
commit
59036c6e6e
|
|
@ -0,0 +1,68 @@
|
|||
import requests
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def extract_time(json):
|
||||
|
||||
print "extract_time"
|
||||
try:
|
||||
return json['DepartureTime']
|
||||
except:
|
||||
return -1
|
||||
|
||||
|
||||
url = 'http://api.trafikinfo.trafikverket.se/beta/data.json'
|
||||
headers = {'Content-Type': 'text/xml'}
|
||||
xml_data = """<?xml version='1.0' encoding='utf-8'?>
|
||||
<REQUEST>
|
||||
<LOGIN authenticationkey="ac4b2399b54648d09a30db1a33fc6eda" /> <QUERY objecttype="FerryAnnouncement">
|
||||
<FILTER>
|
||||
<AND>
|
||||
<EQ name="Route.Id" value="14" />
|
||||
<AND>
|
||||
<GT name="DepartureTime" value="$now"/>
|
||||
<LT name ="DepartureTime" value='$dateadd(0.05:15:00)' />
|
||||
</AND>
|
||||
</AND>
|
||||
</FILTER>
|
||||
<INCLUDE>DepartureTime</INCLUDE>
|
||||
<INCLUDE>Info</INCLUDE>
|
||||
<INCLUDE>ToHarbor.Id</INCLUDE>
|
||||
<INCLUDE>ToHarbor.Name</INCLUDE>
|
||||
<INCLUDE>FromHarbor.Name</INCLUDE>
|
||||
<INCLUDE>FromHarbor.Id</INCLUDE>
|
||||
</QUERY>
|
||||
</REQUEST>
|
||||
"""
|
||||
r = requests.post(url, data=xml_data, headers=headers)
|
||||
|
||||
|
||||
if r.status_code == 200:
|
||||
data = r.json()
|
||||
|
||||
dataFerry = data['RESPONSE']['RESULT'][0]['FerryAnnouncement']
|
||||
|
||||
dataFerry.sort(key=extract_time, reverse=False)
|
||||
|
||||
result = []
|
||||
for item in dataFerry:
|
||||
mydict = {}
|
||||
timestamp = item['DepartureTime']
|
||||
timestamp = datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%S")
|
||||
timestamp = timestamp.strftime("%H:%M:%S")
|
||||
mydict['time'] = timestamp
|
||||
|
||||
|
||||
if 'Info' in item:
|
||||
info = unicode(item['Info'][0])
|
||||
info = info.decode('UTF-8')
|
||||
mydict['info'] = info
|
||||
|
||||
result.append(mydict)
|
||||
|
||||
print result
|
||||
|
||||
|
||||
else:
|
||||
print "error"
|
||||
print r.text
|
||||
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
<nav class="teal lighten-3" role="navigation">
|
||||
<div class="nav-wrapper container"><a id="logo-container" href="#" class="brand-logo">Logo</a>
|
||||
<a href="#" data-activates="nav-mobile" class="button-collapse"><i class="material-icons">menu</i></a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
|
|
@ -12,33 +11,28 @@
|
|||
<div class="section">
|
||||
|
||||
<!-- Icon Section -->
|
||||
<div class="row">
|
||||
<div class="col s12 m4">
|
||||
<div class="icon-block">
|
||||
<h2 class="center light-blue-text"><i class="material-icons">flash_on</i></h2>
|
||||
<h5 class="center">Speeds up development</h5>
|
||||
<div class="container-fluid">
|
||||
<table class="table text-center">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tid</th>
|
||||
<th>Från</th>
|
||||
<th>Info</th>
|
||||
</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>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
<p class="light">We did most of the heavy lifting for you to provide a default stylings that incorporate our custom components. Additionally, we refined animations and transitions to provide a smoother experience for developers.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col s12 m4">
|
||||
<div class="icon-block">
|
||||
<h2 class="center light-blue-text"><i class="material-icons">group</i></h2>
|
||||
<h5 class="center">User Experience Focused</h5>
|
||||
|
||||
<p class="light">By utilizing elements and principles of Material Design, we were able to create a framework that incorporates components and animations that provide more feedback to users. Additionally, a single underlying responsive system across all platforms allow for a more unified user experience.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col s12 m4">
|
||||
<div class="icon-block">
|
||||
<h2 class="center light-blue-text"><i class="material-icons">settings</i></h2>
|
||||
<h5 class="center">Easy to work with</h5>
|
||||
|
||||
<p class="light">We have provided detailed documentation as well as specific code examples to help new users get started. We are also always open to feedback and can answer any questions a user may have about Materialize.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
@ -50,9 +44,9 @@
|
|||
<footer class="page-footer teal">
|
||||
<div class="footer-copyright">
|
||||
<div class="container">
|
||||
Made by Simon
|
||||
Made by Simon
|
||||
</div>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
|
|
|||
|
|
@ -1,43 +1,71 @@
|
|||
from ferry.app import app
|
||||
from flask import render_template, request, jsonify
|
||||
from flask import render_template
|
||||
import requests
|
||||
import pprint
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
@app.route('/')
|
||||
@app.route('/index')
|
||||
def index():
|
||||
data = ferry_request()
|
||||
print data
|
||||
return render_template('index.html', data=data)
|
||||
|
||||
|
||||
def extract_time(json):
|
||||
|
||||
try:
|
||||
return json['DepartureTime']
|
||||
except:
|
||||
return -1
|
||||
|
||||
print ferry_request()
|
||||
return render_template('index.html')
|
||||
|
||||
def ferry_request():
|
||||
url = 'http://api.trafikinfo.trafikverket.se/beta/data.json'
|
||||
headers = {'Content-Type': 'text/xml'}
|
||||
xml_data = """<?xml version='1.0' encoding='utf-8'?>
|
||||
<REQUEST>
|
||||
<LOGIN authenticationkey="ac4b2399b54648d09a30db1a33fc6eda" />
|
||||
<QUERY objecttype="FerryAnnouncement">
|
||||
<FILTER>
|
||||
<AND>
|
||||
<EQ name="Route.Id" value="14" />
|
||||
<AND>
|
||||
<GT name="DepartureTime" value="$now"/>
|
||||
<LT name ="DepartureTime" value='$dateadd(0.02:15:00)' />
|
||||
</AND>
|
||||
</AND>
|
||||
</FILTER>
|
||||
<INCLUDE>DepartureTime</INCLUDE>
|
||||
<INCLUDE>Info</INCLUDE>
|
||||
<INCLUDE>ToHarbor.Id</INCLUDE>
|
||||
<INCLUDE>ToHarbor.Name</INCLUDE>
|
||||
<INCLUDE>FromHarbor.Name</INCLUDE>
|
||||
<INCLUDE>FromHarbor.Id</INCLUDE>
|
||||
</QUERY>
|
||||
</REQUEST>
|
||||
<REQUEST>
|
||||
<LOGIN authenticationkey="ac4b2399b54648d09a30db1a33fc6eda" />
|
||||
<QUERY objecttype="FerryAnnouncement">
|
||||
<FILTER>
|
||||
<AND>
|
||||
<EQ name="Route.Id" value="14" />
|
||||
<AND>
|
||||
<GT name="DepartureTime" value="$now"/>
|
||||
<LT name ="DepartureTime" value='$dateadd(0.04:15:00)' />
|
||||
</AND>
|
||||
</AND>
|
||||
</FILTER>
|
||||
<INCLUDE>DepartureTime</INCLUDE>
|
||||
<INCLUDE>Info</INCLUDE>
|
||||
<INCLUDE>ToHarbor.Id</INCLUDE>
|
||||
<INCLUDE>ToHarbor.Name</INCLUDE>
|
||||
<INCLUDE>FromHarbor.Name</INCLUDE>
|
||||
<INCLUDE>FromHarbor.Id</INCLUDE>
|
||||
</QUERY>
|
||||
</REQUEST>
|
||||
"""
|
||||
r = requests.post(url, data=xml_data, headers=headers).json()
|
||||
print r
|
||||
r = requests.post(url, data=xml_data, headers=headers)
|
||||
|
||||
for i in r['RESPONSE']:
|
||||
print i
|
||||
if r.status_code == 200:
|
||||
data = r.json()
|
||||
dataFerry = data['RESPONSE']['RESULT'][0]['FerryAnnouncement']
|
||||
dataFerry.sort(key=extract_time, reverse=False)
|
||||
|
||||
result = []
|
||||
for item in dataFerry:
|
||||
mydict = {}
|
||||
timestamp = item['DepartureTime']
|
||||
timestamp = datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%S")
|
||||
timestamp = timestamp.strftime("%H:%M:%S")
|
||||
mydict['time'] = timestamp
|
||||
|
||||
if 'Info' in item:
|
||||
info = item['Info'][0].encode('utf-8')
|
||||
mydict['info'] = item['Info']
|
||||
|
||||
result.append(mydict)
|
||||
|
||||
return result
|
||||
else:
|
||||
return 0
|
||||
|
|
|
|||
|
|
@ -1,93 +1,16 @@
|
|||
apsw==3.8.11.1.post1
|
||||
attrs==16.0.0
|
||||
BeautifulSoup==3.2.1
|
||||
beautifulsoup4==4.5.1
|
||||
blinker==1.3
|
||||
boto==2.40.0
|
||||
cffi==1.7.0
|
||||
characteristic==14.3.0
|
||||
chardet==2.3.0
|
||||
CherryPy==3.5.0
|
||||
appdirs==1.4.3
|
||||
backports-abc==0.5
|
||||
certifi==2017.4.17
|
||||
click==6.7
|
||||
configobj==5.0.6
|
||||
cryptography==1.5
|
||||
cssselect==0.9.2
|
||||
cssutils==1.0
|
||||
debtags==2.0
|
||||
decorator==4.0.6
|
||||
defer==1.0.6
|
||||
dirspec==13.10
|
||||
dnspython==1.14.0
|
||||
dulwich==0.14.1
|
||||
duplicity==0.7.6
|
||||
enum34==1.1.6
|
||||
ExifRead==2.1.2
|
||||
fastimport==0.9.6
|
||||
feedparser==5.1.3
|
||||
Flask==0.12.1
|
||||
html5lib==0.999
|
||||
httplib2==0.9.1
|
||||
idna==2.1
|
||||
ipaddress==1.0.16
|
||||
ipython==2.4.1
|
||||
itsdangerous==0.24
|
||||
Jinja2==2.9.6
|
||||
lockfile==0.12.2
|
||||
lxml==3.6.4
|
||||
Markdown==2.6.7
|
||||
livereload==2.5.1
|
||||
MarkupSafe==1.0
|
||||
mechanize==0.2.5
|
||||
meld==3.16.3
|
||||
mutagen==1.34
|
||||
ndg-httpsclient==0.4.2
|
||||
netifaces==0.10.4
|
||||
oauthlib==1.1.2
|
||||
oneconf==0.3.9
|
||||
PAM==0.4.2
|
||||
pbr==1.8.1
|
||||
pexpect==4.2.0
|
||||
Pillow==3.3.1
|
||||
piston-mini-client==0.7.5
|
||||
Pivy==0.5.0
|
||||
ply==3.7
|
||||
ptyprocess==0.5.1
|
||||
pyasn1==0.1.9
|
||||
pyasn1-modules==0.0.7
|
||||
pycparser==2.14
|
||||
pycrypto==2.6.1
|
||||
pycups==1.9.73
|
||||
Pygments==2.1.3
|
||||
pygobject==3.22.0
|
||||
PyJWT==1.4.1
|
||||
pyOpenSSL==16.1.0
|
||||
pyparsing==2.1.8
|
||||
pyserial==3.1.1
|
||||
python-apt==1.1.0b5
|
||||
python-cloudfiles==1.7.10
|
||||
python-dateutil==2.4.2
|
||||
python-debian==0.1.29
|
||||
pyxdg==0.25
|
||||
PyYAML==3.11
|
||||
rabbitvcs==0.16.0
|
||||
repoze.lru==0.6
|
||||
requests==2.10.0
|
||||
Routes==2.2
|
||||
service-identity==16.0.0
|
||||
simplegeneric==0.8.1
|
||||
simplejson==3.8.2
|
||||
packaging==16.8
|
||||
pyparsing==2.2.0
|
||||
requests==2.13.0
|
||||
singledispatch==3.4.0.3
|
||||
six==1.10.0
|
||||
software-center-aptd-plugins==0.0.0
|
||||
stevedore==1.10.0
|
||||
svtplay-dl==0.30.2016.1.10
|
||||
Twisted==16.4.1
|
||||
urllib3==1.15.1
|
||||
uTidylib==0.3
|
||||
vboxapi==1.0
|
||||
virtualenv==13.1.2
|
||||
virtualenv-clone==0.2.6
|
||||
virtualenvwrapper==4.7.1
|
||||
WebOb==1.6.1
|
||||
tornado==4.5.1
|
||||
Werkzeug==0.12.1
|
||||
wxPython==3.0.2.0
|
||||
wxPython-common==3.0.2.0
|
||||
zope.interface==4.2.0
|
||||
|
|
|
|||
Loading…
Reference in New Issue