From 083451d5069babb2a6e36f7796fdccfe76f9bdc8 Mon Sep 17 00:00:00 2001 From: Benjamin Sigonneau Date: Wed, 20 Jul 2022 22:43:57 +0200 Subject: [PATCH] Store graphql query inside function + rename function --- fioul.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/fioul.py b/fioul.py index ff2e26d..b943989 100755 --- a/fioul.py +++ b/fioul.py @@ -9,16 +9,15 @@ import requests import json import webapp -query = """query { - getProductGroups(category: 1, zipcode: 1184) { - name - default_price_tax - } -} -""" - -def get_price(): +def get_today_price_from_internet(): + query = """query { + getProductGroups(category: 1, zipcode: 1184) { + name + default_price_tax + } + } + """ response = requests.post( url="https://www.bretagne-multi-energies.fr/graphql", json={"query": query}, @@ -41,7 +40,7 @@ def store_current_price(): today = date.today() # Get price returns a float (price per L) # We store an int (price per m^3) - price = int(get_price() * 1000) + price = int(get_today_price_from_internet() * 1000) try: Price.create(date=today, price=price) except IntegrityError: