LaurentTRIPIED commited on
Commit
46f8b87
1 Parent(s): eb2ba11

Pytorch v.33

Browse files
__pycache__/localisation.cpython-312.pyc CHANGED
Binary files a/__pycache__/localisation.cpython-312.pyc and b/__pycache__/localisation.cpython-312.pyc differ
 
__pycache__/organisations_engagees.cpython-312.pyc CHANGED
Binary files a/__pycache__/organisations_engagees.cpython-312.pyc and b/__pycache__/organisations_engagees.cpython-312.pyc differ
 
localisation.py CHANGED
@@ -4,37 +4,35 @@ from streamlit_folium import folium_static
4
  import streamlit as st
5
 
6
  def get_data():
7
- # URL de l'API
8
  url = "https://opendata.bordeaux-metropole.fr/api/records/1.0/search/?dataset=met_etablissement_rse&q=&rows=100"
9
- try:
10
- response = requests.get(url)
11
- if response.status_code == 200:
12
- data = response.json()
13
- records = data.get("records", [])
14
- cleaned_data = []
15
- for record in records:
16
- fields = record.get("fields", {})
17
- # Assurez-vous que la structure de 'fields' correspond à ce que vous attendez
18
- if 'geolocalisation' in fields:
19
- cleaned_data.append(fields)
20
- return cleaned_data
21
- else:
22
- st.error("Échec de la récupération des données. Statut HTTP : {}".format(response.status_code))
23
- return []
24
- except requests.exceptions.RequestException as e:
25
- st.error("Erreur lors de la connexion à l'API : {}".format(e))
26
  return []
27
 
28
  def display_map(data):
29
- # Initialise la carte
30
  m = folium.Map(location=[44.837789, -0.57918], zoom_start=12)
31
- # Ajoute un marqueur pour chaque élément dans 'data'
32
  for item in data:
33
- point_geo = item.get('geolocalisation')
34
- if point_geo:
35
- lat, lon = point_geo[0], point_geo[1]
36
- folium.Marker([lat, lon],
37
- icon=folium.Icon(color="green", icon="leaf"),
38
- popup=item.get('nom_courant_denomination', 'Inconnu')
39
- ).add_to(m)
40
  folium_static(m)
 
 
 
 
 
 
4
  import streamlit as st
5
 
6
  def get_data():
 
7
  url = "https://opendata.bordeaux-metropole.fr/api/records/1.0/search/?dataset=met_etablissement_rse&q=&rows=100"
8
+ response = requests.get(url)
9
+ if response.status_code == 200:
10
+ data = response.json()
11
+ records = data.get("records", [])
12
+ cleaned_data = []
13
+ for record in records:
14
+ fields = record.get("fields", {})
15
+ # Assumer que 'geolocalisation' contient directement les coordonnées [lat, lon]
16
+ if 'geolocalisation' in fields:
17
+ lat, lon = fields['geolocalisation']
18
+ cleaned_data.append({"lat": lat, "lon": lon, "name": fields.get("nom_courant_denomination", "Inconnu")})
19
+ return cleaned_data
20
+ else:
21
+ st.error("Failed to fetch data")
 
 
 
22
  return []
23
 
24
  def display_map(data):
 
25
  m = folium.Map(location=[44.837789, -0.57918], zoom_start=12)
 
26
  for item in data:
27
+ lat, lon = item["lat"], item["lon"]
28
+ folium.Marker(
29
+ [lat, lon],
30
+ popup=item["name"],
31
+ icon=folium.Icon(color="green", icon="leaf"),
32
+ ).add_to(m)
 
33
  folium_static(m)
34
+
35
+ # Cette partie est pour exécuter le test directement dans ce fichier, si désiré
36
+ if __name__ == "__main__":
37
+ data = get_data()
38
+ display_map(data)