Store graphql query inside function + rename function
This commit is contained in:
7
fioul.py
7
fioul.py
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user