42Cummer commited on
Commit
5aadc1b
·
verified ·
1 Parent(s): 6a3e83e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -1
app.py CHANGED
@@ -83,9 +83,49 @@ def seek():
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__':
 
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
+
87
+ pattern = re.compile(r'^\d{2,3}_\d{3,4}_[1-3]$')
88
+
89
+ vehicles = []
90
+
91
+ for p_tag in soup.find_all('p', id=pattern):
92
+ vehicle_data = {'id': p_tag.get('id')}
93
+
94
+ # Get minutes
95
+ minpred_span = p_tag.find('span', class_='minpred')
96
+ if minpred_span:
97
+ inner_span = minpred_span.find('span')
98
+ if inner_span and inner_span.text.strip().isdigit():
99
+ minutes = inner_span.text.strip()
100
+ vehicle_data['minutes'] = f"{minutes} minutes"
101
+
102
+ # Get delay text and color
103
+ delay_span = p_tag.find('span', style=re.compile(r'color'))
104
+ if delay_span:
105
+ vehicle_data['delay_text'] = delay_span.get_text(strip=True)
106
+ vehicle_data['delay_color'] = delay_span.get('style').replace('color: ', '')
107
+
108
+ # Get vehicle number
109
+ vehicle_link = p_tag.find('a', href="#MapMain")
110
+ if vehicle_link and vehicle_link.text.strip().isdigit():
111
+ vehicle_data['vehicle_number'] = vehicle_link.text.strip()
112
+
113
+ # Get stop location description
114
+ text_nodes = [t for t in p_tag.stripped_strings]
115
+ location = None
116
+ for text in reversed(text_nodes):
117
+ if any(word in text.lower() for word in ['at', 'past', 'aprchg']):
118
+ location = text
119
+ break
120
+ if location:
121
+ vehicle_data['location'] = location
122
+
123
+ vehicles.append(vehicle_data)
124
+
125
  return jsonify({
126
  'stop': stop_id,
127
+ 'routes': routes,
128
+ 'vehicles': vehicles
129
  })
130
 
131
  if __name__ == '__main__':