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 json
|
||||||
import webapp
|
import webapp
|
||||||
|
|
||||||
|
|
||||||
|
def get_today_price_from_internet():
|
||||||
query = """query {
|
query = """query {
|
||||||
getProductGroups(category: 1, zipcode: 1184) {
|
getProductGroups(category: 1, zipcode: 1184) {
|
||||||
name
|
name
|
||||||
@@ -16,9 +18,6 @@ query = """query {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def get_price():
|
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
url="https://www.bretagne-multi-energies.fr/graphql",
|
url="https://www.bretagne-multi-energies.fr/graphql",
|
||||||
json={"query": query},
|
json={"query": query},
|
||||||
@@ -41,7 +40,7 @@ def store_current_price():
|
|||||||
today = date.today()
|
today = date.today()
|
||||||
# Get price returns a float (price per L)
|
# Get price returns a float (price per L)
|
||||||
# We store an int (price per m^3)
|
# We store an int (price per m^3)
|
||||||
price = int(get_price() * 1000)
|
price = int(get_today_price_from_internet() * 1000)
|
||||||
try:
|
try:
|
||||||
Price.create(date=today, price=price)
|
Price.create(date=today, price=price)
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
|
|||||||
Reference in New Issue
Block a user