42Cummer commited on
Commit
59a93f4
·
verified ·
1 Parent(s): 9de9918

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -22
app.py CHANGED
@@ -6,11 +6,7 @@ from bs4 import BeautifulSoup
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)
@@ -202,25 +198,23 @@ def listVehiclesByRoute():
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"):
 
6
  import tempfile
7
  import os
8
 
9
+
 
 
 
 
10
 
11
  app = Flask(__name__)
12
  CORS(app)
 
198
  @app.route("/alerts", methods=["GET"])
199
  def serviceAlerts():
200
  url = "https://www.transsee.ca/showmessages?a=ttc"
201
+ headers = {
202
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36',
203
+ 'Referer': 'https://www.transsee.ca/',
204
+ 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
205
+ 'Accept-Language': 'en-US,en;q=0.9',
206
+ 'DNT': '1',
207
+ 'Connection': 'keep-alive',
208
+ 'Upgrade-Insecure-Requests': '1'
209
+ }
210
 
211
+ try:
212
+ response = requests.get(url, headers=headers, timeout=10)
213
+ response.raise_for_status()
214
+ except Exception as e:
215
+ return jsonify({"error": f"Failed to fetch service alerts: {e}"}), 500
 
 
 
 
 
 
 
 
 
 
 
216
 
217
+ soup = BeautifulSoup(response.text, "html.parser")
218
 
219
  alerts = []
220
  for section in soup.select("section.HighAlert"):