Spaces:
Sleeping
Sleeping
Update app.py
Browse filesMise à jour nouvelle API
app.py
CHANGED
@@ -3,7 +3,7 @@ import requests
|
|
3 |
import json
|
4 |
import pandas as pd
|
5 |
|
6 |
-
|
7 |
carburants = ["Gazole", "SP98", "SP95", "E10", "E85", "GPLc"]
|
8 |
|
9 |
with open('departements-region.json', 'r', encoding='utf8') as file:
|
@@ -21,11 +21,14 @@ dep_name_key = st.selectbox(label='Choisissez le departement:', options=departem
|
|
21 |
dep_name_value = departements[dep_name_key]
|
22 |
|
23 |
carburant = st.selectbox(label='Choisissez le type de carburant:', options=carburants)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
records = response.json()['records']
|
27 |
|
28 |
-
table =
|
29 |
-
table.columns = ['Prix', 'Adresse', 'CP', 'Ville']
|
30 |
-
|
31 |
-
st.dataframe(table, use_container_width=True)
|
|
|
3 |
import json
|
4 |
import pandas as pd
|
5 |
|
6 |
+
columns_to_display = ['cp', 'adresse', 'ville', 'gazole_prix', 'sp98_prix', 'sp95_prix', 'e10_prix', 'e85_prix', 'gplc_prix']
|
7 |
carburants = ["Gazole", "SP98", "SP95", "E10", "E85", "GPLc"]
|
8 |
|
9 |
with open('departements-region.json', 'r', encoding='utf8') as file:
|
|
|
21 |
dep_name_value = departements[dep_name_key]
|
22 |
|
23 |
carburant = st.selectbox(label='Choisissez le type de carburant:', options=carburants)
|
24 |
+
url = f'https://data.economie.gouv.fr/api/explore/v2.1/catalog/datasets/prix-des-carburants-en-france-flux-instantane-v2/records?order_by={carburant.lower()}_prix&limit=30&&refine=carburants_disponibles%3A%22{carburant}%22&refine=departement%3A%22{dep_name_value}%22'
|
25 |
+
response = requests.get(url)
|
26 |
+
if response.status_code == 200:
|
27 |
+
records = response.json()['results']
|
28 |
+
else:
|
29 |
+
st.error("Erreur lors de la récupération des données.")
|
30 |
+
records = []
|
31 |
|
32 |
+
table = pd.json_normalize(records)[columns_to_display]
|
|
|
33 |
|
34 |
+
st.dataframe(table, use_container_width=True, hide_index=True)
|
|
|
|
|
|