mathteix7 commited on
Commit
5d3cb1d
路
verified 路
1 Parent(s): 426e750

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -39,11 +39,10 @@ def buscar_coordenadas_arcgis(endereco_limpo, bairro, cidade):
39
  candidate = dados['candidates'][0]
40
  end_oficial = candidate['address'].lower()
41
 
42
- # BLOQUEIO DE SEGURAN脟A: Se a planilha pede uma rua/estrada espec铆fica e o mapa responder "Rodovia", rejeita!
43
  if "rodovia" in end_oficial and "rodovia" not in endereco_limpo.lower():
44
  return None, None
45
 
46
- # S贸 aceita se o ponto estiver em Jarinu
47
  if "jarinu" in end_oficial:
48
  local = candidate['location']
49
  return local['y'], local['x']
@@ -52,7 +51,7 @@ def buscar_coordenadas_arcgis(endereco_limpo, bairro, cidade):
52
  busca_forcada = f"{endereco_limpo}, Jarinu - SP, Brasil"
53
  url_reserva = f"https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates?f=json&singleLine={busca_forcada}&maxLocations=1"
54
  resposta = requests.get(url_reserva, timeout=10)
55
- dados = response_dados = resposta.json()
56
 
57
  if dados and dados.get('candidates'):
58
  candidate = dados['candidates'][0]
@@ -87,10 +86,12 @@ if arquivo_enviado is not None:
87
  else:
88
  df = pd.read_csv(arquivo_enviado, sep=',')
89
 
90
- # Criando ou limpando as colunas para o Circuit
91
- df['Latitude'] = None
92
- df['Longitude'] = None
93
 
 
 
94
  if 'Destination Address' in df.columns:
95
  df['Destination Address'] = df['Destination Address'].astype(object)
96
 
@@ -114,13 +115,14 @@ if arquivo_enviado is not None:
114
  cidade_print = f", {cidade}" if cidade and str(cidade).lower() != 'nan' else ", Jarinu"
115
  endereco_final_preservado = f"{endereco_limpo}{bairro_print}{cidade_print} - SP"
116
 
117
- # S贸 coloca a coordenada se ela for de confian莽a (n茫o jogou para rodovia)
118
  if lat and lng:
119
  df.at[index, 'Latitude'] = lat
120
  df.at[index, 'Longitude'] = lng
121
  df.at[index, 'Destination Address'] = endereco_final_preservado
122
  else:
123
- # Deixa Latitude e Longitude vazias para for莽ar o Circuit a ler o texto da rua correto
 
 
124
  df.at[index, 'Destination Address'] = endereco_final_preservado
125
 
126
  time.sleep(0.02)
 
39
  candidate = dados['candidates'][0]
40
  end_oficial = candidate['address'].lower()
41
 
42
+ # Se a planilha pede uma rua/estrada e o mapa responder "Rodovia", rejeita o ponto!
43
  if "rodovia" in end_oficial and "rodovia" not in endereco_limpo.lower():
44
  return None, None
45
 
 
46
  if "jarinu" in end_oficial:
47
  local = candidate['location']
48
  return local['y'], local['x']
 
51
  busca_forcada = f"{endereco_limpo}, Jarinu - SP, Brasil"
52
  url_reserva = f"https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates?f=json&singleLine={busca_forcada}&maxLocations=1"
53
  resposta = requests.get(url_reserva, timeout=10)
54
+ dados = resposta.json()
55
 
56
  if dados and dados.get('candidates'):
57
  candidate = dados['candidates'][0]
 
86
  else:
87
  df = pd.read_csv(arquivo_enviado, sep=',')
88
 
89
+ # Garante que as colunas existam no formato correto
90
+ if 'Latitude' not in df.columns: df['Latitude'] = None
91
+ if 'Longitude' not in df.columns: df['Longitude'] = None
92
 
93
+ df['Latitude'] = df['Latitude'].astype(object)
94
+ df['Longitude'] = df['Longitude'].astype(object)
95
  if 'Destination Address' in df.columns:
96
  df['Destination Address'] = df['Destination Address'].astype(object)
97
 
 
115
  cidade_print = f", {cidade}" if cidade and str(cidade).lower() != 'nan' else ", Jarinu"
116
  endereco_final_preservado = f"{endereco_limpo}{bairro_print}{cidade_print} - SP"
117
 
 
118
  if lat and lng:
119
  df.at[index, 'Latitude'] = lat
120
  df.at[index, 'Longitude'] = lng
121
  df.at[index, 'Destination Address'] = endereco_final_preservado
122
  else:
123
+ # IMPORTANTE: For莽a a linha a ficar SEM coordenadas para o Circuit n茫o usar lixo de mem贸ria
124
+ df.at[index, 'Latitude'] = pd.NA
125
+ df.at[index, 'Longitude'] = pd.NA
126
  df.at[index, 'Destination Address'] = endereco_final_preservado
127
 
128
  time.sleep(0.02)