From e5ae0b527aa55d75d3f210e56c33a72ba6054849 Mon Sep 17 00:00:00 2001 From: "2569718930@qq.com" <2569718930@qq.com> Date: Sun, 8 Feb 2026 20:30:17 +0800 Subject: [PATCH] refactor: Implement structured data collection and configuration modules, replacing legacy city-specific files and updating documentation. --- README.md | 3 +- README_ZH.md | 3 +- nyc_mb.html | 4415 ------------------------ save_nyc_mb.py | 17 - src/data_collection/weather_sources.py | 98 +- src/utils/config_loader.py | 1 + test_nyc_mb.py | 39 - 7 files changed, 50 insertions(+), 4526 deletions(-) delete mode 100644 nyc_mb.html delete mode 100644 save_nyc_mb.py delete mode 100644 test_nyc_mb.py diff --git a/README.md b/README.md index 8de4947f..d627a505 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ An intelligent weather information bot designed to provide ultra-fast, live mete - **Python 3.11+** - Dependencies: `pip install -r requirements.txt` +- **Environment**: Configure `METEOBLUE_API_KEY` in `.env` to enable high-precision London forecasts. ### Running Locally (Windows/Linux) @@ -82,7 +83,7 @@ graph TD subgraph "Data Engine" Collector --> OM[Open-Meteo API] - Collector --> MB[Meteoblue Scraper] + Collector --> MB[Meteoblue Weather API] Collector --> NOAA[METAR Data Center] Collector --> MGM[Turkish MGM API] Collector --> NWS[US NWS API] diff --git a/README_ZH.md b/README_ZH.md index be2303a6..5d6486ff 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -8,6 +8,7 @@ - **Python 3.11+** - 依赖安装: `pip install -r requirements.txt` +- **环境变量**: 需在 `.env` 中配置 `METEOBLUE_API_KEY` 以激活伦敦高精度预报。 ### 本地运行 (Windows/Linux) @@ -88,7 +89,7 @@ graph TD subgraph "Data Engine" Collector --> OM[Open-Meteo API] - Collector --> MB[Meteoblue Scraper] + Collector --> MB[Meteoblue Weather API] Collector --> NOAA[METAR Data Center] Collector --> MGM[Turkish MGM API] Collector --> NWS[US NWS API] diff --git a/nyc_mb.html b/nyc_mb.html deleted file mode 100644 index 7da8c0ad..00000000 --- a/nyc_mb.html +++ /dev/null @@ -1,4415 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 deleted file mode 100644 index 36f8fd6f..00000000 --- a/save_nyc_mb.py +++ /dev/null @@ -1,17 +0,0 @@ -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 4bfe57e2..1453355d 100644 --- a/src/data_collection/weather_sources.py +++ b/src/data_collection/weather_sources.py @@ -37,7 +37,9 @@ class WeatherDataCollector: def __init__(self, config: dict): self.config = config - self.wunderground_key = config.get("wunderground_api_key") + weather_cfg = config.get("weather", {}) + self.wunderground_key = weather_cfg.get("wunderground_api_key") + self.meteoblue_key = weather_cfg.get("meteoblue_api_key") self.timeout = 30 # 增加超时以支持高延迟 VPS self.session = requests.Session() @@ -532,75 +534,65 @@ class WeatherDataCollector: use_fahrenheit: bool = False, ) -> Optional[Dict]: """ - 从 Meteoblue 网页抓取多模型预测数据的“共识”最高温 + 通过 Meteoblue 官方 API 获取高精度预测数据 """ + if not self.meteoblue_key: + logger.warning("Meteoblue API Key 未配置,跳过抓取。") + return None + 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") - - # 使用 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", - "Referer": "https://www.meteoblue.com/" + # 1. 调用官方 API (使用 basic-day 包,它是多模型 ML 融合结果) + # 格式: https://my.meteoblue.com/packages/basic-day?apikey=KEY&lat=LAT&lon=LON&format=json + url = "https://my.meteoblue.com/packages/basic-day" + params = { + "apikey": self.meteoblue_key, + "lat": lat, + "lon": lon, + "format": "json", + "as_daylight": "true" } response = self.session.get( url, - headers=headers, - timeout=self.timeout, - allow_redirects=True # 允许重定向,但我们要检查终点 + params=params, + timeout=self.timeout ) response.raise_for_status() + data = response.json() - content = response.text + day_data = data.get("data_day", {}) + max_temps = day_data.get("temperature_max", []) - # 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 + if not max_temps: + logger.warning(f"Meteoblue API 返回数据中找不到最高温 (坐标: {lat},{lon})") + return None - # 3. 提取最高温 - match = re.search(r'Today.*?tab-temp-max.*?(\d+) °C', content, re.DOTALL | re.IGNORECASE) - - result = { - "source": "meteoblue", - "url": response.url, - "today_high": None, - "daily_highs": [], - "unit": "celsius" - } - + # 2. 转换单位 def c_to_f(c): return round((c * 9/5) + 32, 1) - if match: - val = float(match.group(1)) - result["today_high"] = c_to_f(val) if use_fahrenheit else val + result = { + "source": "meteoblue", + "today_high": None, + "daily_highs": [], + "unit": "fahrenheit" if use_fahrenheit else "celsius", + "url": f"https://www.meteoblue.com/en/weather/week/{lat}N{lon}E" # 仅供参考 + } + + # 提取今日最高 + mb_today_c = max_temps[0] + result["today_high"] = c_to_f(mb_today_c) if use_fahrenheit else mb_today_c - # 同时提取接下来几天 - all_highs = re.findall(r'tab-temp-max.*?(\d+) °C', content, re.DOTALL) - if all_highs: - if use_fahrenheit: - result["daily_highs"] = [c_to_f(float(h)) for h in all_highs] - else: - result["daily_highs"] = [float(h) for h in all_highs] - - result["unit"] = "fahrenheit" if use_fahrenheit else "celsius" - logger.info(f"✅ Meteoblue 抓取成功 ({coord_str}): 今天 {result['today_high']}{result['unit']}") + # 提取接下来几天的最高温 + if use_fahrenheit: + result["daily_highs"] = [c_to_f(t) for t in max_temps] + else: + result["daily_highs"] = max_temps + + logger.info(f"✅ Meteoblue API 获取成功 ({lat},{lon}): 今天 {result['today_high']}{result['unit']}") return result except Exception as e: - logger.error(f"Meteoblue fetch failed: {e}") + logger.error(f"Meteoblue API fetch failed: {e}") return None def extract_date_from_title(self, title: str) -> Optional[str]: diff --git a/src/utils/config_loader.py b/src/utils/config_loader.py index 6abaab9f..f0424c53 100644 --- a/src/utils/config_loader.py +++ b/src/utils/config_loader.py @@ -25,6 +25,7 @@ def load_config(): "openweather_api_key": get_env_or_none("OPENWEATHER_API_KEY"), "wunderground_api_key": get_env_or_none("WUNDERGROUND_API_KEY"), "visualcrossing_api_key": get_env_or_none("VISUALCROSSING_API_KEY"), + "meteoblue_api_key": get_env_or_none("METEOBLUE_API_KEY"), "proxy": os.getenv("HTTPS_PROXY") or os.getenv("HTTP_PROXY"), }, "telegram": { diff --git a/test_nyc_mb.py b/test_nyc_mb.py deleted file mode 100644 index 543d6834..00000000 --- a/test_nyc_mb.py +++ /dev/null @@ -1,39 +0,0 @@ -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()