Store graphql query inside function + rename function

This commit is contained in:
2022-07-20 22:43:57 +02:00
parent 49d8004b71
commit 083451d506

View File

@@ -9,6 +9,8 @@ import requests
import json
import webapp
def get_today_price_from_internet():
query = """query {
getProductGroups(category: 1, zipcode: 1184) {
name
@@ -16,9 +18,6 @@ query = """query {
}
}
"""
def get_price():
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: