Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
fields = ['fields.prix_valeur', 'fields.adresse', 'fields.cp', 'fields.ville']
|
7 |
+
carburants = ["Gazole", "SP98", "SP95", "E10", "E85", "GPLc"]
|
8 |
+
|
9 |
+
with open('departements-region.json', 'r', encoding='utf8') as file:
|
10 |
+
departements_json = json.load(file)
|
11 |
+
|
12 |
+
departements = {}
|
13 |
+
for d in departements_json:
|
14 |
+
value = d["dep_name"]
|
15 |
+
key = str(d["num_dep"]) + ' - ' + d["dep_name"] + ' - ' + d["region_name"]
|
16 |
+
departements[key] = value
|
17 |
+
|
18 |
+
st.title("LaMoinsChère")
|
19 |
+
|
20 |
+
dep_name_key = st.selectbox(label='Choisissez le departement:', options=departements.keys())
|
21 |
+
dep_name_value = departements[dep_name_key]
|
22 |
+
|
23 |
+
carburant = st.selectbox(label='Choisissez le type de carburant:', options=carburants)
|
24 |
+
|
25 |
+
response = requests.get(f"https://data.economie.gouv.fr/api/records/1.0/search/?dataset=prix-carburants-fichier-instantane-test-ods-copie&q=&rows=100&start=0&sort=-prix_valeur&facet=prix_nom&facet=dep_name&refine.dep_name={dep_name_value}&refine.prix_nom={carburant}")
|
26 |
+
records = response.json()['records']
|
27 |
+
|
28 |
+
table = pd.json_normalize(records)[fields]
|
29 |
+
table.columns = ['Prix', 'Adresse', 'CP', 'Ville']
|
30 |
+
|
31 |
+
st.dataframe(table, use_container_width=True)
|