laMoinsChere / app.py
jsr90's picture
Create app.py
c8ff904
raw
history blame
1.21 kB
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)