2020-01-29 21:05:28 +00:00
|
|
|
import requests
|
2020-01-29 21:59:43 +00:00
|
|
|
from datetime import datetime, timedelta
|
2020-01-29 21:05:28 +00:00
|
|
|
from dateutil.parser import parse as dateparse
|
|
|
|
from pytz import reference
|
|
|
|
import flask
|
|
|
|
|
|
|
|
app = flask.Flask(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/")
|
|
|
|
def index():
|
2020-01-29 21:59:43 +00:00
|
|
|
try:
|
|
|
|
refresh = int(flask.request.args.get("refresh", "300"))
|
|
|
|
except ValueError:
|
|
|
|
refresh = 300
|
|
|
|
|
2020-01-29 21:05:28 +00:00
|
|
|
url = flask.request.args.get("apiurl", "")
|
|
|
|
if url:
|
|
|
|
json = requests.get(url).json()
|
|
|
|
listings = [
|
|
|
|
listing
|
|
|
|
for listing in json["listings"]
|
|
|
|
if listing["priorityProduct"] == "NONE"
|
|
|
|
]
|
|
|
|
else:
|
|
|
|
listings = []
|
|
|
|
|
2020-01-29 21:59:43 +00:00
|
|
|
now = datetime.now()
|
2020-01-29 21:05:28 +00:00
|
|
|
return flask.render_template(
|
|
|
|
"marktplaats.html",
|
|
|
|
listings=listings,
|
2020-01-29 21:59:43 +00:00
|
|
|
refresh=refresh,
|
2020-01-29 21:05:28 +00:00
|
|
|
dateparse=dateparse,
|
2020-01-29 21:59:43 +00:00
|
|
|
now=now,
|
|
|
|
next=now + timedelta(seconds=refresh),
|
2020-01-29 21:05:28 +00:00
|
|
|
tz=reference.LocalTimezone(),
|
|
|
|
apiurl=url,
|
|
|
|
)
|