LaurentTRIPIED commited on
Commit
b2f54a6
1 Parent(s): f680dec

Pytorch v.38

Browse files
Files changed (1) hide show
  1. localisation.py +21 -21
localisation.py CHANGED
@@ -5,30 +5,30 @@ 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
- try:
9
- response = requests.get(url)
10
- if response.status_code == 200:
11
- data = response.json()
12
- records = data.get("records", [])
13
- cleaned_data = []
14
- for record in records:
15
- fields = record.get("fields", {})
16
- geoloc = fields.get("geolocalisation")
17
- if geoloc:
18
- lat, lon = geoloc[0], geoloc[1]
19
- cleaned_data.append({"lat": lat, "lon": lon, "name": fields.get("nom_courant_denomination", "Inconnu")})
20
- return cleaned_data
21
- else:
22
- st.error(f"Failed to fetch data. Status code: {response.status_code}")
23
- return []
24
- except requests.exceptions.RequestException as e:
25
- st.error(f"Error occurred: {e}")
26
  return []
27
 
28
  def display_map(data):
29
- # Initialiser la carte au centre de Bordeaux
 
 
 
30
  m = folium.Map(location=[44.837789, -0.57918], zoom_start=12)
31
-
32
  for item in data:
33
  lat, lon = item["lat"], item["lon"]
34
  folium.Marker(
@@ -36,7 +36,7 @@ def display_map(data):
36
  popup=item["name"],
37
  icon=folium.Icon(color="green", icon="leaf"),
38
  ).add_to(m)
39
-
40
  folium_static(m)
41
 
42
  if __name__ == "__main__":
 
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
+ # Assurez-vous que la structure des données correspond à ce qui est attendu.
16
+ geoloc = fields.get("geolocalisation")
17
+ if geoloc and isinstance(geoloc, list) and len(geoloc) == 2:
18
+ lat, lon = geoloc
19
+ cleaned_data.append({"lat": lat, "lon": lon, "name": fields.get("nom_courant_denomination", "Inconnu")})
20
+ return cleaned_data
21
+ else:
22
+ st.error(f"Failed to fetch data. Status code: {response.status_code}")
 
 
 
23
  return []
24
 
25
  def display_map(data):
26
+ if not data:
27
+ st.write("No data available to display on the map.")
28
+ return
29
+
30
  m = folium.Map(location=[44.837789, -0.57918], zoom_start=12)
31
+
32
  for item in data:
33
  lat, lon = item["lat"], item["lon"]
34
  folium.Marker(
 
36
  popup=item["name"],
37
  icon=folium.Icon(color="green", icon="leaf"),
38
  ).add_to(m)
39
+
40
  folium_static(m)
41
 
42
  if __name__ == "__main__":