Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,5 +59,34 @@ def upload():
|
|
| 59 |
'routes': routes
|
| 60 |
})
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
if __name__ == '__main__':
|
| 63 |
app.run(debug=True, port=5000)
|
|
|
|
| 59 |
'routes': routes
|
| 60 |
})
|
| 61 |
|
| 62 |
+
@app.route('/seek', methods=['POST'])
|
| 63 |
+
def seek():
|
| 64 |
+
if not request.is_json:
|
| 65 |
+
return jsonify({'error': 'Request must be JSON'}), 400
|
| 66 |
+
|
| 67 |
+
data = request.get_json()
|
| 68 |
+
stop_id = data.get('stop')
|
| 69 |
+
|
| 70 |
+
if not stop_id:
|
| 71 |
+
return jsonify({'error': 'Stop ID is required'}), 404
|
| 72 |
+
|
| 73 |
+
url = url = f"https://www.transsee.ca/smsstop?a=ttc&id={stop_id}"
|
| 74 |
+
headers = {
|
| 75 |
+
'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',
|
| 76 |
+
'Referer': 'https://www.transsee.ca/',
|
| 77 |
+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
|
| 78 |
+
'Accept-Language': 'en-US,en;q=0.9',
|
| 79 |
+
'DNT': '1', # Do Not Track
|
| 80 |
+
'Connection': 'keep-alive',
|
| 81 |
+
'Upgrade-Insecure-Requests': '1'
|
| 82 |
+
}
|
| 83 |
+
response = requests.get(url, headers=headers)
|
| 84 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
| 85 |
+
routes = [a.text.strip() for a in soup.select('a[href^="stoplist?a=ttc&r="]')]
|
| 86 |
+
return jsonify({
|
| 87 |
+
'stop': stop_id,
|
| 88 |
+
'routes': routes
|
| 89 |
+
})
|
| 90 |
+
|
| 91 |
if __name__ == '__main__':
|
| 92 |
app.run(debug=True, port=5000)
|