From 38a50d04c6a9990424aa9eb7e1742800712fc090 Mon Sep 17 00:00:00 2001 From: Sijmen Schoon Date: Wed, 29 Jan 2020 22:05:28 +0100 Subject: [PATCH] hi --- .gitignore | 2 + README.md | 7 ++++ app.py | 29 ++++++++++++++ requirements.txt | 3 ++ templates/marktplaats.html | 81 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 122 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 app.py create mode 100644 requirements.txt create mode 100644 templates/marktplaats.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..64f4163 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +__pycache__/ +.mypy_cache diff --git a/README.md b/README.md new file mode 100644 index 0000000..9113d14 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +First do `pip install --user -r requirements.txt` (or use a virtual env or +something, idc). Then do `flask run`. That should be about it. + +Grab the API call from inspect element and stick it in the input box. + +If Marktplaats gets mad at you for using this for some reason, don't get mad at +me. Use at your own risk. diff --git a/app.py b/app.py new file mode 100644 index 0000000..33b60d7 --- /dev/null +++ b/app.py @@ -0,0 +1,29 @@ +import requests +from datetime import datetime +from dateutil.parser import parse as dateparse +from pytz import reference +import flask + +app = flask.Flask(__name__) + + +@app.route("/") +def index(): + 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 = [] + + return flask.render_template( + "marktplaats.html", + listings=listings, + dateparse=dateparse, + tz=reference.LocalTimezone(), + apiurl=url, + ) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..bfaf453 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +pytz~=2019.3 +Flask~=1.1.1 +python-dateutil~=2.8.1 diff --git a/templates/marktplaats.html b/templates/marktplaats.html new file mode 100644 index 0000000..1bc0e74 --- /dev/null +++ b/templates/marktplaats.html @@ -0,0 +1,81 @@ +{##} + + + + + + + +
+
+ URL: + + +
+ + {% for listing in listings %} + +
+
+

{{listing.title}}

+

+ €{{ "{:.2f}".format(listing.priceInfo.priceCents / 100) }} + {{listing.priceInfo.priceType}} +
+ + {{dateparse(listing.date).astimezone(tz).strftime("%Y-%m-%d %H:%M")}} +
+ + {{listing.location.cityName}} ({{listing.location.distanceMeters // 1000}} km) +

+
+ + {% for image in listing.imageUrls %} + + {% endfor %} +
+
+ {% endfor %} +
+ +