|
7 | 7 | from datetime import datetime |
8 | 8 |
|
9 | 9 | class Weather(): |
10 | | - def get_weather_data(station="", start_time="", end_time=""): |
| 10 | + def get_weather_data(self, station="", start_time="", end_time=""): |
11 | 11 | """ |
12 | 12 | Valid Parameters: |
13 | 13 | station: 'williams', 'atlantic', 'vmh', 'golf', 'chem' |
@@ -118,47 +118,7 @@ def validate_date_format(date_str): |
118 | 118 | except requests.exceptions.RequestException as e: |
119 | 119 | raise RuntimeError(f"API request failed: {e}") |
120 | 120 |
|
121 | | - def get_hourly_forecast(): |
122 | | - hourly_forecast = [] |
123 | | - url = "https://weather.umd.edu/" |
124 | | - |
125 | | - response = requests.get(url) |
126 | | - soup = BeautifulSoup(response.text, 'html.parser') |
127 | | - a = soup.find('div', id="umdwx_weeklyfcst_widget-9") |
128 | | - |
129 | | - for day in a.find_all('div', class_='fcst_day')[:5]: # First 5 elements are hourly forecast |
130 | | - time = day.find('div', class_='fcst_txt-day').text.strip() |
131 | | - temp = day.find('div', class_='fcst_txt-temp') |
132 | | - wind = day.find('div', class_='fcst_txt-wind') |
133 | | - |
134 | | - temp = temp.text.replace('\u2009', ' ').replace('F', ' ').strip() |
135 | | - |
136 | | - wind = re.sub(r'[^\x00-\x7F]+', '', wind.text) |
137 | | - |
138 | | - wind = wind.replace('mph', '').strip() |
139 | | - |
140 | | - hour, period = time.split() |
141 | | - |
142 | | - hour = int(hour) |
143 | | - |
144 | | - if period == 'PM' and hour != 12: |
145 | | - hour += 12 |
146 | | - elif period == 'AM' and hour == 12: |
147 | | - hour = 0 |
148 | | - |
149 | | - time = hour |
150 | | - |
151 | | - |
152 | | - if time and temp and wind: # Ensure elements exist |
153 | | - hourly_forecast.append({ |
154 | | - 'time': time, |
155 | | - 'temperature': temp, |
156 | | - 'wind': wind |
157 | | - }) |
158 | | - return hourly_forecast |
159 | | - |
160 | | - |
161 | | - def save_radar_gif(dir=""): |
| 121 | + def save_radar_gif(self, dir=""): |
162 | 122 | """ |
163 | 123 | Downloads the latest radar GIF and saves it to the specified directory. |
164 | 124 | |
|
0 commit comments