42Cummer commited on
Commit
2613c4c
·
verified ·
1 Parent(s): 607783b

Upload 3 files

Browse files
Files changed (3) hide show
  1. Procfile +1 -0
  2. app.py +95 -0
  3. requirements.txt +38 -0
Procfile ADDED
@@ -0,0 +1 @@
 
 
1
+ web: gunicorn app:app
app.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, jsonify
2
+ from flask_cors import CORS
3
+ import re
4
+ import requests
5
+ from bs4 import BeautifulSoup
6
+ import tempfile
7
+ import os
8
+
9
+ app = Flask(__name__)
10
+ CORS(app)
11
+
12
+ import re
13
+ import requests
14
+ from bs4 import BeautifulSoup
15
+ from flask import jsonify
16
+
17
+ @app.route('/routelist', methods=['GET'])
18
+ def getRouteList():
19
+ url = "https://www.transsee.ca/routelist?a=ttc&ShowAll=1"
20
+ headers = {
21
+ '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',
22
+ 'Referer': 'https://www.transsee.ca/',
23
+ 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
24
+ 'Accept-Language': 'en-US,en;q=0.9',
25
+ 'DNT': '1',
26
+ 'Connection': 'keep-alive',
27
+ 'Upgrade-Insecure-Requests': '1'
28
+ }
29
+
30
+ try:
31
+ response = requests.get(url, headers=headers, timeout=10)
32
+ response.raise_for_status()
33
+ except Exception as e:
34
+ return jsonify({"error": f"Failed to fetch route list: {e}"}), 500
35
+
36
+ soup = BeautifulSoup(response.text, "html.parser")
37
+ routes = {}
38
+
39
+ for rid in range(7, 204): # all conventional routes
40
+ tag = soup.find("p", {"id": str(rid)})
41
+ if tag and tag.text.strip():
42
+ # Clean text:
43
+ text = tag.get_text(strip=True)
44
+
45
+ # Remove leading symbols like "*" or "== $0"
46
+ text = re.sub(r"^[^A-Za-z0-9]+", "", text) # strip non-alphanumeric at start
47
+ text = re.sub(r"\s*==.*$", "", text) # strip trailing "== $0" or similar
48
+ text = re.sub(r"\s+", " ", text).strip() # collapse spaces
49
+
50
+ # Replace dash between number and name with space (e.g., "26-Dupont" -> "26 Dupont")
51
+ text = re.sub(r'(\d+)-([A-Za-z])', r'\1 \2', text)
52
+
53
+ routes[rid] = text
54
+
55
+ for rid in range(300, 399): # all blue night routes
56
+ tag = soup.find("p", {"id": str(rid)})
57
+ if tag and tag.text.strip():
58
+ # Clean text:
59
+ text = tag.get_text(strip=True)
60
+
61
+ # Remove leading symbols like "*" or "== $0"
62
+ text = re.sub(r"^[^A-Za-z0-9]+", "", text) # strip non-alphanumeric at start
63
+ text = re.sub(r"\s*==.*$", "", text) # strip trailing "== $0" or similar
64
+ text = re.sub(r"\s+", " ", text).strip() # collapse spaces
65
+
66
+ # Replace dash between number and name with space (e.g., "26-Dupont" -> "26 Dupont")
67
+ text = re.sub(r'(\d+)-([A-Za-z])', r'\1 \2', text)
68
+
69
+ routes[rid] = text
70
+
71
+ for rid in range(900, 999): # all express routes
72
+ tag = soup.find("p", {"id": str(rid)})
73
+ if tag and tag.text.strip():
74
+ # Clean text:
75
+ text = tag.get_text(strip=True)
76
+
77
+ # Remove leading symbols like "*" or "== $0"
78
+ text = re.sub(r"^[^A-Za-z0-9]+", "", text) # strip non-alphanumeric at start
79
+ text = re.sub(r"\s*==.*$", "", text) # strip trailing "== $0" or similar
80
+ text = re.sub(r"\s+", " ", text).strip() # collapse spaces
81
+
82
+ # Replace dash between number and name with space (e.g., "26-Dupont" -> "26 Dupont")
83
+ text = re.sub(r'(\d+)-([A-Za-z])', r'\1 \2', text)
84
+
85
+ routes[rid] = text
86
+
87
+ return jsonify(routes)
88
+
89
+
90
+ @app.route('/', methods=['GET'])
91
+ def health_check():
92
+ return 'Backend is running!', 200
93
+
94
+ if __name__ == '__main__':
95
+ app.run(debug=True, port=5000)
requirements.txt ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ beautifulsoup4==4.13.4
2
+ blinker==1.9.0
3
+ certifi==2025.1.31
4
+ charset-normalizer==3.4.1
5
+ click==8.1.8
6
+ easyocr==1.7.2
7
+ filelock==3.18.0
8
+ Flask==3.1.0
9
+ fsspec==2025.3.2
10
+ gunicorn==23.0.0
11
+ idna==3.10
12
+ imageio==2.37.0
13
+ itsdangerous==2.2.0
14
+ Jinja2==3.1.6
15
+ lazy_loader==0.4
16
+ MarkupSafe==3.0.2
17
+ mpmath==1.3.0
18
+ networkx==3.4.2
19
+ ninja==1.11.1.4
20
+ numpy==2.2.5
21
+ opencv-python-headless==4.11.0.86
22
+ packaging==25.0
23
+ pillow==11.2.1
24
+ pyclipper==1.3.0.post6
25
+ python-bidi==0.6.6
26
+ PyYAML==6.0.2
27
+ requests==2.32.3
28
+ scikit-image==0.25.2
29
+ scipy==1.15.2
30
+ shapely==2.1.0
31
+ soupsieve==2.7
32
+ sympy==1.13.3
33
+ tifffile==2025.3.30
34
+ torch==2.7.0
35
+ torchvision==0.22.0
36
+ typing_extensions==4.13.2
37
+ urllib3==2.4.0
38
+ Werkzeug==3.1.3