From 75a4e852963a9a723178fe200e849ef34e0a0cc2 Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Sun, 8 Feb 2026 19:57:44 +0800 Subject: [PATCH] feat: Implement multi-source weather data collection from OpenWeatherMap, Visual Crossing, and NOAA METAR, and add NYC market-specific data handling. --- bot_listener.py | 24 +- nyc_mb.html | 4415 ++++++++++++++++++++++++ save_nyc_mb.py | 17 + src/data_collection/weather_sources.py | 32 +- test_nyc_mb.py | 39 + 5 files changed, 4513 insertions(+), 14 deletions(-) create mode 100644 nyc_mb.html create mode 100644 save_nyc_mb.py create mode 100644 test_nyc_mb.py diff --git a/bot_listener.py b/bot_listener.py index 54114665..1f755f13 100644 --- a/bot_listener.py +++ b/bot_listener.py @@ -218,13 +218,13 @@ def start_bot(): "la": "los angeles", "洛杉矶": "los angeles", } - # 1. 尝试直接从映射表获取 + # 1. 第一优先级:严格全字匹配 city_name = STANDARD_MAPPING.get(city_input) - # 2. 如果没匹配到,尝试前缀匹配 (如输入 "seou") - if not city_name: + # 2. 第二优先级:如果长度 >= 3,尝试前缀匹配 + if not city_name and len(city_input) >= 3: for k, v in STANDARD_MAPPING.items(): - if len(city_input) >= 3 and k.startswith(city_input[:3]): + if k.startswith(city_input): city_name = v break @@ -278,19 +278,27 @@ def start_bot(): if mb_high is not None: sources.append("MB") - comp_parts.append(f"MB: {mb_high}") + comp_parts.append(f"MB: {mb_high:.1f}{temp_symbol}" if isinstance(mb_high, (int, float)) else f"MB: {mb_high}") if nws_high is not None: sources.append("NWS") - comp_parts.append(f"NWS: {nws_high}") + comp_parts.append(f"NWS: {nws_high:.1f}{temp_symbol}" if isinstance(nws_high, (int, float)) else f"NWS: {nws_high}") if mgm_high is not None: sources.append("MGM") - comp_parts.append(f"MGM: {mgm_high}") + comp_parts.append(f"MGM: {mgm_high:.1f}{temp_symbol}" if isinstance(mgm_high, (int, float)) else f"MGM: {mgm_high}") + + # 检查是否有显著分歧 (超过 5°F 或 2.5°C) + divergence_warning = "" + if mb_high is not None and max_temps: + diff = abs(mb_high - max_temps[0]) + threshold = 5.0 if temp_unit == "fahrenheit" else 2.5 + if diff > threshold: + divergence_warning = f" ⚠️ 模型显著分歧 ({diff:.1f}{temp_symbol})" comp_str = f" ({' | '.join(comp_parts)})" if comp_parts else "" sources_str = " | ".join(sources) msg_lines.append(f"\n📊 预报 ({sources_str})") - msg_lines.append(f"👉 今天: {today_t}{temp_symbol}{comp_str}") + msg_lines.append(f"👉 今天: {today_t}{temp_symbol}{comp_str}{divergence_warning}") # 明后天 if len(dates) > 1: diff --git a/nyc_mb.html b/nyc_mb.html new file mode 100644 index 00000000..7da8c0ad --- /dev/null +++ b/nyc_mb.html @@ -0,0 +1,4415 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Weather Osaka - meteoblue + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+
+ + + +
+
+
+ +
+
+
AD FREE
+
+
+ + Remove ads for 9 € per year
+
+
+ + +
+ +
+ + + +
+
+ + + + +
+
+ +
+
+
+ + Wind direction and wind speed
+
+ + Precipitation amount +
+
+ + Sunshine hours
+
+ + + + Predictability shows if the forecast is reliable , a bit uncertain , or is likely to change .
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+ + +
+ + + +
+
+ + - + 3h
+ +
+
+
+ +
+
+ + +
+
+ 3-hourly view
+ +
+
+
+ 3h + 1h +
+
+ + +
+ General + Sea & Surf +
+ + + +
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+ +
+
+
Icon
+
+
+
+
+
+ Mixed with showers +
+
+
+
+
+
+
+ Overcast with mixture of snow and rain +
+
+
+
+
+
+
+ Mixed with snow showers +
+
+
+
+
+
+
+ Overcast with light snow +
+
+
+
+
+
+
+ Partly cloudy +
+
+
+
+
+
+
+ Clear with few low clouds +
+
+
+
+
+
+
+ Clear with few low clouds +
+
+
+
+
+
+
+ Clear with few low clouds +
+
+
+
+
+ + °C +
+
+
+ 4° +
+
+
+ 3° +
+
+
+ 2° +
+
+
+ 1° +
+
+
+ 2° +
+
+
+ 0° +
+
+
+ -1° +
+
+
+ -1° +
+
+
+ + °C +
+
+
+ -2° +
+
+
+ -3° +
+
+
+ -5° +
+
+
+ -5° +
+
+
+ -5° +
+
+
+ -6° +
+
+
+ -6° +
+
+
+ -6° +
+
+
+ +
+
NW
W
NW
NNW
NNW
NNW
NW
WNW
+
+ + km/h +
+
+
+ 15-40
+
+
+ 17-38
+
+
+ 21-61
+
+
+ 17-52
+
+
+ 20-49
+
+
+ 17-43
+
+
+ 13-35
+
+
+ 10-24
+
+
+ + + mm +
+
+
+ < 1 +
+
+
+ < 1 +
+
+
+ < 1 +
+
+
+ < 1 +
+
+
+ < 1 +
+
+
+ - +
+
+
+ - +
+
+
+ - +
+
+
+ + % +
+
+
+ 65% +
+
+
+ 65% +
+
+
+ 65% +
+
+
+ 75% +
+
+
+ 80% +
+
+
+ 55% +
+
+
+ 0% +
+
+
+ 10% +
+
+
+ + + mm +
+
+
+

+ 00:00 to 01:00:
65% chance of precipitation in the area.
0.1 mm are predicted by our local models.

+

+ 01:00 to 02:00:
10% chance of precipitation in the area.
0 mm are predicted by our local models.

+

+ 02:00 to 03:00:
10% chance of precipitation in the area.
0 mm are predicted by our local models.

+
+
+
+

+ 03:00 to 04:00:
20% chance of precipitation in the area.
0 mm are predicted by our local models.

+

+ 04:00 to 05:00:
65% chance of precipitation in the area.
0 mm are predicted by our local models.

+

+ 05:00 to 06:00:
65% chance of precipitation in the area.
0.1 mm are predicted by our local models.

+
+
+
+

+ 06:00 to 07:00:
65% chance of precipitation in the area.
0.1 mm are predicted by our local models.

+

+ 07:00 to 08:00:
55% chance of precipitation in the area.
0 mm are predicted by our local models.

+

+ 08:00 to 09:00:
30% chance of precipitation in the area.
0 mm are predicted by our local models.

+
+
+
+

+ 09:00 to 10:00:
65% chance of precipitation in the area.
0.2 mm are predicted by our local models.

+

+ 10:00 to 11:00:
75% chance of precipitation in the area.
0 mm are predicted by our local models.

+

+ 11:00 to 12:00:
75% chance of precipitation in the area.
0 mm are predicted by our local models.

+
+
+
+

+ 12:00 to 13:00:
80% chance of precipitation in the area.
0 mm are predicted by our local models.

+

+ 13:00 to 14:00:
80% chance of precipitation in the area.
0 mm are predicted by our local models.

+

+ 14:00 to 15:00:
55% chance of precipitation in the area.
0 mm are predicted by our local models.

+
+
+
+

+ 15:00 to 16:00:
55% chance of precipitation in the area.
0 mm are predicted by our local models.

+

+ 16:00 to 17:00:
20% chance of precipitation in the area.
0 mm are predicted by our local models.

+

+ 17:00 to 18:00:
20% chance of precipitation in the area.
0 mm are predicted by our local models.

+
+
+
+

+ 18:00 to 19:00:
0% chance of precipitation in the area.
0 mm are predicted by our local models.

+

+ 19:00 to 20:00:
0% chance of precipitation in the area.
0 mm are predicted by our local models.

+

+ 20:00 to 21:00:
0% chance of precipitation in the area.
0 mm are predicted by our local models.

+
+
+
+

+ 21:00 to 22:00:
10% chance of precipitation in the area.
0 mm are predicted by our local models.

+

+ 22:00 to 23:00:
10% chance of precipitation in the area.
0 mm are predicted by our local models.

+

+ 23:00 to 00:00:
10% chance of precipitation in the area.
0 mm are predicted by our local models.

+
+
+
+ + 20 km +
+
+
+ +
+
+ Sea/surf forecast +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+ Significant wave height (m) + +
+
+
+ 1.8
+
+ 1.8
+
+
+ 1.2
+
+ 1.2
+
+
+ 1.9
+
+ 1.9
+
+
+ 2
+
+ 2
+
+
+ 1
+
+ 1
+
+
+ 0.9
+
+ 0.9
+
+
+ 0.7
+
+ 0.7
+
+
+ 0.6
+
+ 0.6
+
+
+ Significant wave direction in which the waves move + +
+
+
+ Water temperature (°C) +
+
+
+ + Swell wave height (m) +
+
+
+ 0
+
+ 0
+
+
+ 0
+
+ 0
+
+
+ 0
+
+ 0
+
+
+ 0
+
+ 0
+
+
+ 0.7
+
+ 0.7
+
+
+ 0.1
+
+ 0.1
+
+
+ 0
+
+ 0
+
+
+ 0
+
+ 0
+
+
+ Swell wave period (s) +
+
+
+ 4.7
+
+ 4.7
+
+
+ 5.1
+
+ 5.1
+
+
+ 5.1
+
+ 5.1
+
+
+ 4.9
+
+ 4.9
+
+
+ 4.7
+
+ 4.7
+
+
+ 4.9
+
+ 4.9
+
+
+ 4.6
+
+ 4.6
+
+
+ 4.1
+
+ 4.1
+
+
+ Wind wave direction in which the waves move + +
+
+
+ Wind wave height (m) + +
+
+
+ 1.8
+
+ 1.8
+
+
+ 1.2
+
+ 1.2
+
+
+ 1.9
+
+ 1.9
+
+
+ 2
+
+ 2
+
+
+ 0.7
+
+ 0.7
+
+
+ 0.8
+
+ 0.8
+
+
+ 0.7
+
+ 0.7
+
+
+ 0.6
+
+ 0.6
+
+
+ Wind wave period (s) +
+
4.5
3.9
4.4
4.7
3.5
3.5
3.3
3
+
+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+
+ +
+
+ +
+
+
+
+ Mixed with showers +
+
+
+
+
+
+
+ Overcast with mixture of snow and rain +
+
+
+
+
+
+
+ Mixed with snow showers +
+
+
+
+
+
+
+ Overcast with light snow +
+
+
+
+
+
+
+ Partly cloudy +
+
+
+
+
+
+
+ Clear with few low clouds +
+
+
+
+
+
+
+ Clear with few low clouds +
+
+
+
+
+
+
+ Clear with few low clouds +
+
+
+
-1°
-1°
+
+ + -2°
+
+
+ + -3°
+
+
+ + -5°
+
+
+ + -5°
+
+
+ + -5°
+
+
+ + -6°
+
+
+ + -6°
+
+
+ + -6°
+
+
+
+ NW
+ 15-40
+
+
+
+ W
+ 17-38
+
+
+
+ NW
+ 21-61
+
+
+
+ NNW
+ 17-52
+
+
+
+ NNW
+ 20-49
+
+
+
+ NNW
+ 17-43
+
+
+
+ NW
+ 13-35
+
+
+
+ WNW
+ 10-24
+
+
+
+ < 1 mm +
+ 65% +
+
+
+
+ < 1 mm +
+ 65% +
+
+
+
+ < 1 mm +
+ 65% +
+
+
+
+ < 1 mm +
+ 75% +
+
+
+
+ < 1 mm +
+ 80% +
+
+
+
+ - +
+ 55% +
+
+
+
+ - +
+ 0% +
+
+
+
+ - +
+ 10% +
+
+ +
+
+ The weather forecast has medium predictability. Compare different forecasts with MultiModel.
+ +
+

Weather report for Osaka

+

Overnight into Sunday it is cloudy with a wintry mix of snow and rain. On Sunday morning no more precipitation is expected but it remains partly cloudy. Sunday afternoon a few clouds are expected. The sun will not be visible. There is a high chance of Precipitation near 70%. Temperatures as high as 5 °C are foreseen. Overnight into Sunday a gentle breeze is expected (12 to 20 km/h). At daytime expect a moderate breeze (20 to 29 km/h). From time to time gusts could reach up to 64 km/h. Winds blowing overnight from West, in the morning from Northwest and during the afternoon from North. The weather forecast for Osaka for Sunday can be accurate in parts but deviations are expected. Check again for latest updates.

+
+ +
+ +
+
+
+
+ sun-icon +
+ + UV 3
+
+
+
+ 06:49
+
+ 17:35
+
+
+ +
+
+ + + + Waning gibbous moon (259°) + + + + + + + + + + + + + + + +
+
+
+ ----
+
+ 09:54
+
+
+
+ +
+

+ Pressure: + 1013 hPa +

+

+ Timezone: + JST (UTC +09:00h) +

+
+
+
+ +
+ Show more +
+ +
+
+ The weather forecast has medium predictability. Compare different forecasts with MultiModel.
+ +
+

Weather report for Osaka

+

Overnight into Sunday it is cloudy with a wintry mix of snow and rain. On Sunday morning no more precipitation is expected but it remains partly cloudy. Sunday afternoon a few clouds are expected. The sun will not be visible. There is a high chance of Precipitation near 70%. Temperatures as high as 5 °C are foreseen. Overnight into Sunday a gentle breeze is expected (12 to 20 km/h). At daytime expect a moderate breeze (20 to 29 km/h). From time to time gusts could reach up to 64 km/h. Winds blowing overnight from West, in the morning from Northwest and during the afternoon from North. The weather forecast for Osaka for Sunday can be accurate in parts but deviations are expected. Check again for latest updates.

+
+ +
+ +
+
+
+
+ sun-icon +
+ + UV 3
+
+
+
+ 06:49
+
+ 17:35
+
+
+ +
+
+ + + + Waning gibbous moon (259°) + + + + + + + + + + + + + + + +
+
+
+ ----
+
+ 09:54
+
+
+
+ +
+

+ Pressure: + 1013 hPa +

+

+ Timezone: + JST (UTC +09:00h) +

+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + + + + + + +
+ + + + + + + + + +
+ + + +

Weather anomaly: Unusually cold weather for this time of the year

+ +
+
+
+ +
+
+ Extremely cold
+
+ Unusually cold
+
+ Normal
+
+ Unusually warm
+
+ Extremely warm
+
+
+

+ By comparing today's temperatures to 40 years of historical data we can see whether today's forecast is unusually warm (red areas) or cold (blue areas). Coloured dots show observed actual temperatures from professional and private weather stations.

+

+ + More Weather Maps +

+
+
+
+
+ + + + + +
+ + + +

Weather radar, Japan

+ +
+
+ + +
+ +
+
+
+ Drizzle
+
+ Light
+
+ Moderate
+
+ Heavy
+
+ Very Heavy
+
+ Hail
+
+ +
+

+ The location marker is placed on Osaka. + + Orange crosses indicate lightning. Data provided by nowcast.de (available in USA, Europe, Australia). Drizzle or light snow fall might be invisible for the radar. Precipitation intensity is colour coded, ranging from turquoise to red.

+
+
+
+
+
+ + + + + + +
+ +

Hourly weather forecast for Osaka

+
+
+
+
+
+
+ + Our 5-day meteogram for Osaka offers all weather information in 3 simple graphs: + [More] + +
    +
  • Temperature chart with weather pictograms. The yellow background indicates daylight.
  • +
  • Clouds in different altitudes: from few clouds (light grey) to overcast (dark grey). Dark blue bars show hourly precipitation and light blue showers. An asterisk indicates snow fall.
  • +
  • Forecasts for wind speeds are blue and for gusts are green. The arrowheads point in the same direction as the wind.
  • +
+

+ + You can embed this meteogram into your own website. Customize it here.

+
+
+
+ + + + +
+

Live satellite map, Japan

+
+
+ +
+ +
+
+ + The location marker is placed on Osaka. [More] + +

+ The real-time satellite image combines visible light during daytime with infrared radiation during nighttime. At night, the image is not dark as infrared radiation can detect temperature differences. Unfortunately, low clouds and fog are difficult to distinguish from ground temperatures and thus can be almost invisible during the night. Meteosat satellite images for Europe are updated in real-time every 5 minutes. GOES-16/GOES-17 (North & South America) and Himawari (Asia) images update every 10 minutes.

+

+ Precipitation is estimated from radar and satellites. Precipitation estimates from satellites are less accurate at night than during daytime.

+

+

+ + © 2026 meteoblue, NOAA Satellites GOES-16 and EUMETSAT. Lightning data provided by nowcast.

+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + + + +
+
+ + Back to top +
+
+ + + + + + + + + + + + + + + + + +
+
+ × +
+ +
Hey there,
seems like you are using an ad blocker.
+
+
+

Advertising is essential to maintain our free website with unique detail and accuracy.

+ +

Please whitelist www.meteoblue.com on your ad blocker or consider buying one of our products:

+
+ +
+ +

Already have a subscription?
Then please login.

+
+ +
+
+ + diff --git a/save_nyc_mb.py b/save_nyc_mb.py new file mode 100644 index 00000000..36f8fd6f --- /dev/null +++ b/save_nyc_mb.py @@ -0,0 +1,17 @@ +import requests + +def save_nyc_mb(): + url = "https://www.meteoblue.com/en/weather/week/40.713N74.006W" + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" + } + proxies = {"http": "http://127.0.0.1:7890", "https": "http://127.0.0.1:7890"} + try: + resp = requests.get(url, headers=headers, proxies=proxies, timeout=10) + with open("nyc_mb.html", "w", encoding="utf-8") as f: + f.write(resp.text) + print("Saved nyc_mb.html") + except Exception as e: + print(f"Error: {e}") + +save_nyc_mb() diff --git a/src/data_collection/weather_sources.py b/src/data_collection/weather_sources.py index 2ebd07c2..5accfbd6 100644 --- a/src/data_collection/weather_sources.py +++ b/src/data_collection/weather_sources.py @@ -535,27 +535,47 @@ class WeatherDataCollector: 从 Meteoblue 网页抓取多模型预测数据的“共识”最高温 """ try: + # 1. 构造精确的方向后缀 URL + lat_dir = "N" if lat >= 0 else "S" + lon_dir = "E" if lon >= 0 else "W" + # Meteoblue 坐标 URL 习惯:保留 3 位小数,使用大写方向后缀 + coord_str = f"{abs(lat):.3f}{lat_dir}{abs(lon):.3f}{lon_dir}" tz_slug = timezone_name.replace("/", "%2F") - url = f"https://www.meteoblue.com/en/weather/week/{lat}N{lon}E8_{tz_slug}" + + # 使用 forecast/week 路径通常比直接 week 更稳定 + url = f"https://www.meteoblue.com/en/weather/week/{coord_str}" + if tz_slug: + url += f"_{tz_slug}" headers = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", - "Accept-Language": "en-US,en;q=0.9" + "Accept-Language": "en-US,en;q=0.9", + "Referer": "https://www.meteoblue.com/" } response = self.session.get( url, headers=headers, - timeout=self.timeout + timeout=self.timeout, + allow_redirects=True # 允许重定向,但我们要检查终点 ) response.raise_for_status() content = response.text + + # 2. 检查是否重定向到了错误的地方 (例如大阪 Osaka) + # 如果 URL 里有 W 但页面内容里全是 E 或者城市名完全对不上 + if lon < 0 and "W" in coord_str: + if "osaka" in response.url.lower(): + logger.warning(f"⚠️ Meteoblue 重定向异常: 目标 {coord_str} 却返回了 {response.url}") + return None + + # 3. 提取最高温 match = re.search(r'Today.*?tab-temp-max.*?(\d+) °C', content, re.DOTALL | re.IGNORECASE) result = { "source": "meteoblue", - "url": url, + "url": response.url, "today_high": None, "daily_highs": [], "unit": "celsius" @@ -568,7 +588,7 @@ class WeatherDataCollector: val = float(match.group(1)) result["today_high"] = c_to_f(val) if use_fahrenheit else val - # 同时提取接下来几天的最高温 + # 同时提取接下来几天 all_highs = re.findall(r'tab-temp-max.*?(\d+) °C', content, re.DOTALL) if all_highs: if use_fahrenheit: @@ -577,7 +597,7 @@ class WeatherDataCollector: result["daily_highs"] = [float(h) for h in all_highs] result["unit"] = "fahrenheit" if use_fahrenheit else "celsius" - logger.info(f"✅ Meteoblue 抓取成功: 今天 {result['today_high']}{result['unit']}") + logger.info(f"✅ Meteoblue 抓取成功 ({coord_str}): 今天 {result['today_high']}{result['unit']}") return result except Exception as e: logger.error(f"Meteoblue fetch failed: {e}") diff --git a/test_nyc_mb.py b/test_nyc_mb.py new file mode 100644 index 00000000..543d6834 --- /dev/null +++ b/test_nyc_mb.py @@ -0,0 +1,39 @@ +import requests +import re +from datetime import datetime + +def test_mb_nyc(): + lat = 40.7128 + lon = -74.0060 + timezone_name = "America/New_York" + + lat_dir = "N" if lat >= 0 else "S" + lon_dir = "E" if lon >= 0 else "W" + tz_slug = timezone_name.replace("/", "%2F") + + # Try both ways + url1 = f"https://www.meteoblue.com/en/weather/week/{lat}N{lon}E8_{tz_slug}" + url2 = f"https://www.meteoblue.com/en/weather/week/{abs(lat)}{lat_dir}{abs(lon)}{lon_dir}8_{tz_slug}" + + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", + "Accept-Language": "en-US,en;q=0.9" + } + proxies = {"http": "http://127.0.0.1:7890", "https": "http://127.0.0.1:7890"} + + for url in [url1, url2]: + print(f"\nTesting URL: {url}") + try: + resp = requests.get(url, headers=headers, proxies=proxies, timeout=10) + print(f"Status: {resp.status_code}") + content = resp.text + match = re.search(r'Today.*?tab-temp-max.*?(\d+) °C', content, re.DOTALL | re.IGNORECASE) + if match: + print(f"Captured High: {match.group(1)}°C") + else: + all_highs = re.findall(r'tab-temp-max.*?(\d+) °C', content, re.DOTALL) + print(f"All Highs Found: {all_highs}") + except Exception as e: + print(f"Error: {e}") + +test_mb_nyc()