42Cummer commited on
Commit
d2b5028
·
verified ·
1 Parent(s): 12bedb7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py CHANGED
@@ -6,6 +6,12 @@ from bs4 import BeautifulSoup
6
  import tempfile
7
  import os
8
 
 
 
 
 
 
 
9
  app = Flask(__name__)
10
  CORS(app)
11
 
@@ -193,6 +199,41 @@ def listVehiclesByRoute():
193
  "vehicles": vehicles
194
  })
195
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  @app.route('/', methods=['GET'])
197
  def health_check():
198
  return 'Backend is running!', 200
 
6
  import tempfile
7
  import os
8
 
9
+ from selenium import webdriver
10
+ from selenium.webdriver.chrome.options import Options
11
+ from selenium.webdriver.common.by import By
12
+ from selenium.webdriver.support.ui import WebDriverWait
13
+ from selenium.webdriver.support import expected_conditions as EC
14
+
15
  app = Flask(__name__)
16
  CORS(app)
17
 
 
199
  "vehicles": vehicles
200
  })
201
 
202
+ @app.route("/alerts", methods=["GET"])
203
+ def serviceAlerts():
204
+ url = "https://www.transsee.ca/showmessages?a=ttc"
205
+
206
+ # Headless Chrome
207
+ options = Options()
208
+ options.add_argument("--headless=new")
209
+ options.add_argument("--disable-gpu")
210
+ options.add_argument("--no-sandbox")
211
+
212
+ driver = webdriver.Chrome(options=options)
213
+ driver.get(url)
214
+
215
+ # Wait until at least one HighAlert is loaded
216
+ WebDriverWait(driver, 15).until(
217
+ EC.presence_of_element_located((By.CSS_SELECTOR, "section.HighAlert"))
218
+ )
219
+
220
+ html = driver.page_source
221
+ driver.quit()
222
+
223
+ soup = BeautifulSoup(html, "html.parser")
224
+
225
+ alerts = []
226
+ for section in soup.select("section.HighAlert"):
227
+ title = section.find("b").get_text(strip=True) if section.find("b") else ""
228
+ route = section.find("div").get_text(strip=True) if section.find("div") else ""
229
+
230
+ alerts.append({
231
+ "title": title,
232
+ "route": route
233
+ })
234
+
235
+ return jsonify(alerts)
236
+
237
  @app.route('/', methods=['GET'])
238
  def health_check():
239
  return 'Backend is running!', 200