From dfb8edc01ba5e7ade1c96f9f51c333df15496e74 Mon Sep 17 00:00:00 2001 From: Benjamin Sigonneau Date: Sun, 10 Jul 2022 20:34:35 +0200 Subject: [PATCH] First version, get current price with CLI --- fioul.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 fioul.py diff --git a/fioul.py b/fioul.py new file mode 100644 index 0000000..dc9b482 --- /dev/null +++ b/fioul.py @@ -0,0 +1,36 @@ +#! /usr/bin/env python3 + +# from bottle import hook, request, route, run, static_file, view +import requests +import json + + +query = """query { + getProductGroups(category: 1, zipcode: 1184) { + name + default_price_tax + } +} +""" + + +def get_price(): + response = requests.post( + url="https://www.bretagne-multi-energies.fr/graphql", + json={"query": query}, + headers={"content-type": "application/json"}, + ) + json_data = json.loads(response.text) + products = json_data["data"]["getProductGroups"] + product = next( + filter(lambda x: x["name"] == "Fioul Domestique Standard", products), None + ) + return product["default_price_tax"] + + +def main(): + print(get_price()) + + +if __name__ == "__main__": + main()