Workspace
Antonio Hernández Coarasa/

Tests Folium

0
Beta
Spinner
import folium, json
from folium.plugins import MarkerCluster
import requests

# Define the location of Castante, Logroño, Spain
location = [42.4634, -2.4449]

# Create the map centered in Castante, Logroño, Spain
m = folium.Map(location=location, tiles="cartodbpositron", zoom_start=12)

# Define the icon for the marker
icon = folium.Icon(icon='spray-can', prefix='fa')

# Define the login endpoint and credentials
login_url = 'https://app.cesens.com/api/usuarios/login'
login_data = {'nombre': '[email protected]', 'clave': 'P.s812516'}

# Authenticate and get the token
response = requests.post(login_url, data=json.dumps(login_data))
token = response.json()['auth']

# Define the endpoint to get the data points
data_url = 'https://app.cesens.com/api/ubicaciones'

# Add the data points to the map
header=dict()
header["Authentication"] = "Token " + token
response = requests.get(data_url, headers=header)

locations = response.json()

for point in locations:
    if True: #try:
        if point["objectType"] == "UbicacionCliente":
            if point["nodo"]["tipo"] == 6:
                color = "blue"
            elif point["nodo"]["tipo"] == 5:
                color = "green"
            else:
                continue
            left_col_color = "#19a7bd"
            right_col_color = "#f2f0d3"
            hoursFromLastConnection = 
            html =  """<!DOCTYPE html>
                    <html>
                    <head>
                    <h4>{}</h4>""".format(point["nombre"]) + """
                    </head>
                    <table>
                    <tbody>
                    <tr>
                    <td style="background-color: """+ left_col_color +""";"><span style="color: #ffffff;">Primer Dato</span></td>
                    <td style="background-color: """+ right_col_color +""";">{}</td>""".format(point["primerDato"]) + """
                    </tr>
                    <tr>
                    <td style="background-color: """+ left_col_color +""";"><span style="color: #ffffff;">Último Dato</span></td>
                    <td style="background-color: """+ right_col_color +""";">{}</td>""".format(point["ultimoDato"]) + """
                    </tr>
                    </tbody>
                    </table>
                    </html>
                    """
            popup = folium.Popup(folium.Html(html, script=True), max_width=500)
            marker = folium.Marker(location=[point['latitud'], point['longitud']], icon=folium.Icon(color=color, icon='spray', prefix='fa'),popup=popup)
            marker.add_to(folium.FeatureGroup(name = 'Misters').add_to(m))
            
    #except:
        #print("Error")

# Display the map
folium.LayerControl().add_to(m)
folium.plugins.MiniMap().add_to(m)
folium.plugins.Terminator().add_to(m) #Sun position
folium.plugins.Geocoder().add_to(m) #Search bar
#folium.plugins.MarkerCluster(data).add_to(m)# Cluster Misters
m
import folium, json, datetime
from folium.plugins import MarkerCluster
import requests

# Define the location of Castante, Logroño, Spain
location = [42.4634, -2.4449]

# Create the map centered in Castante, Logroño, Spain
m = folium.Map(location=location, tiles="cartodbpositron", zoom_start=12)

# Define the icon for the marker
icon = folium.Icon(icon='spray-can', prefix='fa')

# Create FeatureGroups for each classification
ferointegra = folium.FeatureGroup(name='FeroIntegra')
sigis = folium.FeatureGroup(name='SIGIS')
group3 = folium.FeatureGroup(name='Others')
FeatureGroups = [ferointegra,sigis,group3]

# Define the login endpoint and credentials
login_url = 'https://app.cesens.com/api/usuarios/login'
login_data = {'nombre': '[email protected]', 'clave': 'P.s812516'}

# Authenticate and get the token
response = requests.post(login_url, data=json.dumps(login_data))
token = response.json()['auth']

# Define the endpoint to get the data points
data_url = 'https://app.cesens.com/api/ubicaciones'

# Add the data points to the map
header=dict()
header["Authentication"] = "Token " + token
response = requests.get(data_url, headers=header)

locations = response.json()

for point in locations:
    if True: #try:
        if point["objectType"] == "UbicacionCliente":
            if point["nodo"]["tipo"] == 6:
                color = "blue"
            elif point["nodo"]["tipo"] == 5:
                color = "green"
            else:
                continue
            left_col_color = "#19a7bd"
            right_col_color = "#f2f0d3"
            hoursFromLastConnection = datetime.datetime.now()
            html =  """<!DOCTYPE html>
                    <html>
                    <head>
                    <h4>{}</h4>""".format(point["nombre"]) + """
                    </head>
                    <table>
                    <tbody>
                    <tr>
                    <td style="background-color: """+ left_col_color +""";"><span style="color: #ffffff;">Primer Dato</span></td>
                    <td style="background-color: """+ right_col_color +""";">{}</td>""".format(point["primerDato"]) + """
                    </tr>
                    <tr>
                    <td style="background-color: """+ left_col_color +""";"><span style="color: #ffffff;">Último Dato</span></td>
                    <td style="background-color: """+ right_col_color +""";">{}</td>""".format(point["ultimoDato"]) + """
                    </tr>
                    </tbody>
                    </table>
                    </html>
                    """
            popup = folium.Popup(folium.Html(html, script=True), max_width=500)
            marker = folium.Marker(location=[point['latitud'], point['longitud']], icon=folium.Icon(color=color, icon='spray', prefix='fa'),popup=popup)
            if point['nombre'][:3] == 'FI-':
                marker.add_to(ferointegra)
            elif point['nombre'][:3] == 'SIG':
                marker.add_to(sigis)
            else:
                marker.add_to(group3)
            for FG in FeatureGroups:
                FG.add_to(m)
            #marker.add_to(folium.FeatureGroup(name = 'Misters').add_to(m))
            
    #except:
        #print("Error")

# Display the map
folium.LayerControl().add_to(m)
folium.plugins.MiniMap().add_to(m)
folium.plugins.Terminator().add_to(m) #Sun position
folium.plugins.Geocoder().add_to(m) #Search bar
#folium.plugins.MarkerCluster(data).add_to(m)# Cluster Misters
m
Unknown integration
DataFrameavailable as
df
variable
CREATE TABLE points (
    id SERIAL PRIMARY KEY,
    name VARCHAR(255),
    latitude FLOAT,
    longitude FLOAT
);
This query is taking long to finish...Consider adding a LIMIT clause or switching to Query mode to preview the result.
  • AI Chat
  • Code