File size: 1,210 Bytes
c8ff904
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import streamlit as st
import requests
import json
import pandas as pd

fields = ['fields.prix_valeur', 'fields.adresse', 'fields.cp', 'fields.ville']
carburants = ["Gazole", "SP98", "SP95", "E10", "E85", "GPLc"]

with open('departements-region.json', 'r', encoding='utf8') as file:
    departements_json = json.load(file)
    
departements = {}
for d in departements_json:
    value = d["dep_name"]
    key = str(d["num_dep"]) + ' - ' + d["dep_name"] + ' - ' + d["region_name"]
    departements[key] = value

st.title("LaMoinsChère")

dep_name_key = st.selectbox(label='Choisissez le departement:', options=departements.keys())
dep_name_value = departements[dep_name_key]

carburant = st.selectbox(label='Choisissez le type de carburant:', options=carburants)

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}")
records = response.json()['records']

table = pd.json_normalize(records)[fields]
table.columns = ['Prix', 'Adresse', 'CP', 'Ville']

st.dataframe(table, use_container_width=True)