weathergrabber 0.0.9a0__py3-none-any.whl → 0.0.11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,7 @@ from .core import main
4
4
  from .cli import main_cli
5
5
 
6
6
  __all__ = ["main", "main_cli"]
7
- __version__ = "0.0.9a"
7
+ __version__ = "0.0.11"
8
8
 
9
9
  def get_version():
10
10
  return __version__
@@ -1,4 +1,5 @@
1
1
  import logging
2
+ import json
2
3
  from pyquery import PyQuery
3
4
  from weathergrabber.domain.entities.weather_icon_enum import WeatherIconEnum
4
5
  from weathergrabber.domain.entities.city_location import CityLocation
@@ -16,12 +17,12 @@ class ExtractCurrentConditionsService:
16
17
 
17
18
  data = PyQuery(weather_data('div[data-testid="CurrentConditionsContainer"]'))
18
19
 
19
- city_location_data = data.find('h1').text() #'Nova Friburgo, Rio de Janeiro, Brazil'
20
+
20
21
  timestamp_data = data.find('span[class*="timestamp"]').text() # 'As of 8:01 pm GMT-03:00'
21
22
  icon_data = data.find('svg[class*="wxIcon"]').attr('name') # 'partly-cloudy-night'
22
23
  temp_day_night = data.find('div[class*="tempHiLoValue"]').text() #'Day\xa063°\xa0•\xa0Night\xa046°'
23
24
 
24
- city_location = CityLocation.from_string(city_location_data)
25
+ city_location = self.__location(weather_data)
25
26
  timestamp = Timestamp.from_string(timestamp_data)
26
27
  temperature = data.find('span[class*="tempValue"]').text() # '48°'
27
28
  icon = WeatherIconEnum.from_name(icon_data)
@@ -39,4 +40,15 @@ class ExtractCurrentConditionsService:
39
40
 
40
41
  self.logger.debug(f"Extracted current conditions: {current_conditions}")
41
42
 
42
- return current_conditions
43
+ return current_conditions
44
+
45
+ def __location(self, weather_data: PyQuery) -> CityLocation:
46
+ location_str = weather_data.find('script[type="application/ld+json"]').contents().eq(2).text()
47
+ location_data = json.loads(location_str)
48
+ address = location_data.get("address", {})
49
+
50
+ return CityLocation(
51
+ city=address.get("addressLocality"),
52
+ state_province=address.get("addressRegion"),
53
+ country=address.get("addressCountry")
54
+ )
@@ -13,13 +13,9 @@ class SearchLocationService:
13
13
  if not location_name:
14
14
  self.logger.debug("No location name provided. Bypassing search.")
15
15
  return None
16
+ data = self.api.search(location_name, lang)
16
17
 
17
18
  try:
18
- data = self.api.search(location_name, lang)
19
- if not data:
20
- self.logger.error(f"No data found for location: {location_name}")
21
- raise ValueError(f"Location '{location_name}' not found.")
22
-
23
19
  dal = data["dal"]["getSunV3LocationSearchUrlConfig"]
24
20
 
25
21
  # Pick the first (arbitrary) key, then get the value
@@ -29,7 +25,7 @@ class SearchLocationService:
29
25
  self.logger.debug(f"Found location ID: {location_id} for location name: {location_name}")
30
26
 
31
27
  return location_id
32
- except Exception as e:
33
- self.logger.error(f"Error searching for location '{location_name}': {e}")
28
+ except KeyError as e:
29
+ self.logger.debug(f"Error searching for location '{location_name}': {e}")
34
30
  raise ValueError(f"Could not find location '{location_name}'.")
35
31
 
@@ -68,10 +68,10 @@ class WeatherForecastUC:
68
68
 
69
69
  try:
70
70
  location_id = self._resolve_location_id(params)
71
+ weather_data = self.read_weather_service.execute(params.language, location_id)
71
72
  except ConnectionError as e:
73
+ self.logger.debug("A connection error occurred while fetching weather data. Trying to retrieve from cache.")
72
74
  return self.retrieve_forecast_from_cache_service.execute(params)
73
-
74
- weather_data = self.read_weather_service.execute(params.language, location_id)
75
75
 
76
76
  current_conditions = self.extract_current_conditions_service.execute(weather_data)
77
77
  today_details = self.extract_today_details_service.execute(weather_data)
weathergrabber/cli.py CHANGED
@@ -16,9 +16,9 @@ def main_cli():
16
16
  parser.add_argument("--version", "-v", action='version', version=f'Weathergrabber {weathergrabber.get_version()}', help="Show version and exit")
17
17
  parser.add_argument(
18
18
  "--log",
19
- default="critical",
19
+ default="ERROR",
20
20
  choices=["debug", "info", "warning", "error", "critical", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
21
- help="Set the logging level (default: CRITICAL)"
21
+ help="Set the logging level (default: ERROR)"
22
22
  )
23
23
  args = parser.parse_args()
24
24
 
weathergrabber/core.py CHANGED
@@ -32,4 +32,12 @@ def main(log_level: str, location_name: str, location_id: str, lang: str, output
32
32
  cache_statistics=cache_statistics,
33
33
  )
34
34
 
35
- app = WeatherGrabberApplication(params)
35
+ try:
36
+ app = WeatherGrabberApplication(params)
37
+ except Exception as e:
38
+ logger = logging.getLogger()
39
+ if logger.level == logging.DEBUG:
40
+ logger.error(f"{e}", exc_info=True)
41
+ else:
42
+ logger.error(f"{e}")
43
+ raise SystemExit(1)
@@ -47,6 +47,7 @@ class WeatherIconEnum(Enum):
47
47
  # Suggestions from Copilot
48
48
  BLIZZARD = ('blizzard', '\u2744', '🌨️')
49
49
  DUST = ('dust', '\uf063', '🌪️')
50
+ BLOWING_DUST_SANDSTORM = ('blowing-dust-sandstorm', '\uf063', '🌪️')
50
51
  FLURRIES = ('flurries', '\u2744', '🌨️')
51
52
  FREEZING_DRIZZLE = ('freezing-drizzle', '\uf0e9', '🌧️')
52
53
  FREEZING_DRIZZLE_RAIN = ('freezing-drizzle-rain', '\uf0e9', '🌧️')
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: weathergrabber
3
- Version: 0.0.9a0
3
+ Version: 0.0.11
4
4
  Summary: A grabber for weather.com data with various output formats.
5
5
  Author-email: Carlos Anselmo Mendes Junior <cjuniorfox@gmail.com>
6
6
  License: MIT
@@ -1,7 +1,7 @@
1
- weathergrabber/__init__.py,sha256=5f7V1Cw3xEDm1ILym-TI69RtSvznomtyNcxDLunUHjY,217
1
+ weathergrabber/__init__.py,sha256=jyad_PXvxFjRMqfok4rwKL7ULoOSuH6Cwf7SJef7XIE,217
2
2
  weathergrabber/__main__.py,sha256=yYL-jc4kVHqaYVADzjKZfmCN2mziRofsXgnzrECbGDo,68
3
- weathergrabber/cli.py,sha256=o5CgYggCGNzLpTj8Ynuy_QqoloGYGcnPCgm9RN8iO_c,2480
4
- weathergrabber/core.py,sha256=76xkBPJluuQkhfEEWLrMp7ash03MZLnwl0kHzOKJseY,1376
3
+ weathergrabber/cli.py,sha256=oGHgkWWC3wnMDuisV2XgImQpQRHWNUL_yoqNhnJT2V4,2474
4
+ weathergrabber/core.py,sha256=ARQrqtLI-UMqJVS_T2l16dpANXLj-3bxctui2RGChpA,1618
5
5
  weathergrabber/adapter/client/weather_api.py,sha256=9S7JmXaAVvvPY60dz6rC3lx7X68BcqyvNzvSVM1-af8,963
6
6
  weathergrabber/adapter/client/weather_search_api.py,sha256=1oy7JitHcmwkkhFlD0eIt5A7a4cGbf7LMNi26tR8z5o,1724
7
7
  weathergrabber/adapter/repository/forecast_repository.py,sha256=kuQWG6e-cNzFpS7BxqbHJUKw6OLH59zYUD6sOTtEO2o,5814
@@ -11,7 +11,7 @@ weathergrabber/adapter/tty/statistics_tty.py,sha256=6ES5AsnCAnXl6Bp_8tyqz2_C2j92
11
11
  weathergrabber/adapter/tty/waybar_tty.py,sha256=vGErv9NshqPVzP2eh-O3govZRumUM-VXiwWRBsiRGzo,6191
12
12
  weathergrabber/application/weathergrabber_application.py,sha256=yFbo920vGLi6TreDMw6n1bZ-wy1lcBJewKurP0qKfCA,5190
13
13
  weathergrabber/application/services/extract_aqi_service.py,sha256=OIDbdXankKCn3LrxUsZkAlpf0tIgniFxuGiSDviL5UM,1099
14
- weathergrabber/application/services/extract_current_conditions_service.py,sha256=lUo7meqt5SMCuZTKEjVW-iWYpxsYksvsDOGZdHD57ac,1883
14
+ weathergrabber/application/services/extract_current_conditions_service.py,sha256=2LUkHwF8zS9xQg-TjchbdK8_4DR8KmZb80lG_57e7ig,2269
15
15
  weathergrabber/application/services/extract_daily_forecast_oldstyle_service.py,sha256=HPODxFKinUIhZrE6O-1PyaKavWtp1go4Xp5yY2KnC10,2226
16
16
  weathergrabber/application/services/extract_daily_forecast_service.py,sha256=tJ7Lvi3bEiAT1cN6byoq4nx00BG91fG16iXEhwT0MDc,2762
17
17
  weathergrabber/application/services/extract_health_activities_service.py,sha256=efrJMsVXEGTURGqOTmlbD973eF00vrX53tQqwbtytmo,1023
@@ -23,9 +23,9 @@ weathergrabber/application/services/read_weather_service.py,sha256=7_B8E9IN1KCwO
23
23
  weathergrabber/application/services/retrieve_forecast_from_cache_service.py,sha256=7fY6pJ_2qahbFNzhnxJ7taG1cb9-ExFEV7tYnLlMCAs,1314
24
24
  weathergrabber/application/services/retrieve_statistics_service.py,sha256=XjDGbjZNlaaV1eT3hgVq_Pm012b6JHMQ66xT9DdVnPI,838
25
25
  weathergrabber/application/services/save_forecast_to_cache_service.py,sha256=a64D2_JIpFHiQodltlWJ4Us3MtTcDff_xVwSJZmwZ0c,747
26
- weathergrabber/application/services/search_location_service.py,sha256=tZmVgO45hjwoa4cl5bKPjMBmYlGxJiH_I9Ymb5pwEwU,1422
26
+ weathergrabber/application/services/search_location_service.py,sha256=8Snv8CnweRfx1LHFASgF0_N6k_tDdL7RN3zE4LDWJ64,1222
27
27
  weathergrabber/application/usecases/statistics_uc.py,sha256=ycr0dH9Ddy5S8kdzjdk5Munk01RUfY1JNPXEriH2dE0,836
28
- weathergrabber/application/usecases/weather_forecast_uc.py,sha256=zD77byoQx3YOJeKqgp1LgyRZU15OAzXfErt-7LMRqvo,6968
28
+ weathergrabber/application/usecases/weather_forecast_uc.py,sha256=PZMalRrIALLSfFOYeE26Uorud415x_J6YYZJOL-osHA,7084
29
29
  weathergrabber/domain/adapter/icon_enum.py,sha256=YxGYS5vBRV2AiAfeuPOdqaQOHixAssiMbOzQnTmdSBg,84
30
30
  weathergrabber/domain/adapter/output_enum.py,sha256=KwR3mpIrW9T3b6mV3vEHjv4ff8BAxQM-58UTtX5EVZ0,116
31
31
  weathergrabber/domain/adapter/params.py,sha256=TBhF1H2esDG16HuME43yUwm7OZivgHHnanzRpjVfj-M,2220
@@ -70,11 +70,11 @@ weathergrabber/domain/entities/temperature_hight_low.py,sha256=PQOJ5uDtfMRBR5yMx
70
70
  weathergrabber/domain/entities/timestamp.py,sha256=Bk6f8Tx0-yNitYmEKIWHnqh_ALDwxEHrhoCRSrfvYTU,1222
71
71
  weathergrabber/domain/entities/today_details.py,sha256=EUlV7xerYw5QhEsBfvO5m6-9Ghm4nPkXJz9zCmSYTbA,2398
72
72
  weathergrabber/domain/entities/uv_index.py,sha256=7XalamfjJdVSqo4x7G4JVf_HJtrPJxO1BpbvmAfBhnw,1481
73
- weathergrabber/domain/entities/weather_icon_enum.py,sha256=4mbTtZjyYaX7hNlKh1LLQdVNAEjZkmFGPijARxilZLs,4088
73
+ weathergrabber/domain/entities/weather_icon_enum.py,sha256=2JqK3MJEAdbmL_jqzJUw0V31qF9EXJFq6zF1J653eRU,4165
74
74
  weathergrabber/domain/entities/wind.py,sha256=wTDz3X1rYsnw_eNoDi1miwaomxwhiJkY_q6xrdZtLak,789
75
- weathergrabber-0.0.9a0.dist-info/licenses/LICENSE,sha256=X5JFljoqN43yFwpMLudQ9rtty4K_FeZfnz3v8Yhw23Q,1067
76
- weathergrabber-0.0.9a0.dist-info/METADATA,sha256=xRa6noDzRVyXgMOGAwxGKUVrk9rzOaVZkgVwCkowVBo,7475
77
- weathergrabber-0.0.9a0.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
78
- weathergrabber-0.0.9a0.dist-info/entry_points.txt,sha256=m2P9a4mrJDTzuNaiTU438NA60GxCfaw7VKvruWw43N8,63
79
- weathergrabber-0.0.9a0.dist-info/top_level.txt,sha256=P3NMDJJYRIvQujf994Vb4gZrobkKWkL2gh3NF_ajQWM,15
80
- weathergrabber-0.0.9a0.dist-info/RECORD,,
75
+ weathergrabber-0.0.11.dist-info/licenses/LICENSE,sha256=X5JFljoqN43yFwpMLudQ9rtty4K_FeZfnz3v8Yhw23Q,1067
76
+ weathergrabber-0.0.11.dist-info/METADATA,sha256=q0ESC-yO8eh_aNuDF_ASFuXg6GZPeG1ryX9qawdA-kk,7474
77
+ weathergrabber-0.0.11.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
78
+ weathergrabber-0.0.11.dist-info/entry_points.txt,sha256=m2P9a4mrJDTzuNaiTU438NA60GxCfaw7VKvruWw43N8,63
79
+ weathergrabber-0.0.11.dist-info/top_level.txt,sha256=P3NMDJJYRIvQujf994Vb4gZrobkKWkL2gh3NF_ajQWM,15
80
+ weathergrabber-0.0.11.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.10.1)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5