Anne314159 commited on
Commit
89a792e
·
verified ·
1 Parent(s): 5f4a028

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -148,9 +148,9 @@ import streamlit as st
148
  import pandas as pd
149
 
150
  def get_route(start_coord, end_coord):
151
- api_key = os.getenv('OPENSTREET_API')
152
  if not api_key:
153
- st.error("API key not found. Please set the ORS_API_KEY environment variable.")
154
  return
155
 
156
  headers = {
@@ -161,12 +161,20 @@ def get_route(start_coord, end_coord):
161
  response = requests.get(url, headers=headers)
162
 
163
  if response.status_code == 200:
164
- route = response.json()['features'][0]['geometry']['coordinates']
165
- return route
 
 
 
 
 
 
166
  else:
 
167
  st.error(f"Failed to get route data. Status code: {response.status_code}")
168
  return None
169
 
 
170
  def page_vacation():
171
  st.title("Route Finder with OpenRouteService")
172
 
 
148
  import pandas as pd
149
 
150
  def get_route(start_coord, end_coord):
151
+ api_key = os.getenv('OPENSTREET_API') # Make sure the environment variable matches your setup
152
  if not api_key:
153
+ st.error("API key not found. Please set the OPENSTREET_API environment variable.")
154
  return
155
 
156
  headers = {
 
161
  response = requests.get(url, headers=headers)
162
 
163
  if response.status_code == 200:
164
+ print("API call successful. Response data:", response.json()) # For debugging: remove or comment out in production
165
+ data = response.json()
166
+ if 'features' in data and len(data['features']) > 0:
167
+ route = data['features'][0]['geometry']['coordinates']
168
+ return route
169
+ else:
170
+ st.error("Route data is missing from the response.")
171
+ return None
172
  else:
173
+ print(f"Failed to get route data. Status code: {response.status_code}, Response: {response.text}") # For debugging: remove or comment out in production
174
  st.error(f"Failed to get route data. Status code: {response.status_code}")
175
  return None
176
 
177
+
178
  def page_vacation():
179
  st.title("Route Finder with OpenRouteService")
180