Skip to content

Commit

Permalink
feat: add debug logging to proxy requests
Browse files Browse the repository at this point in the history
  • Loading branch information
lhw committed Sep 13, 2024
1 parent ac7b281 commit 51e4d19
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions aiocloudweather/proxy.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"""Proxy for forwarding data to the CloudWeather APIs."""

from enum import Enum
import logging
from aiohttp import web, TCPConnector, ClientSession
from urllib.parse import quote
from aiohttp.resolver import AsyncResolver

_LOGGER = logging.getLogger(__name__)


class DataSink(Enum):
"""Data sinks for the CloudWeather API."""
Expand All @@ -30,12 +33,14 @@ async def forward_wunderground(self, request: web.Request) -> web.Response:
"""Forward Wunderground data to their API."""
query_string = quote(request.query_string).replace("%20", "+")
url = f"https://rtupdate.wunderground.com/weatherstation/updateweatherstation.php?{query_string}"
_LOGGER.debug(f"Forwarding Wunderground data: {url}")
return await self.session.get(url)

async def forward_weathercloud(self, request: web.Request) -> web.Response:
"""Forward WeatherCloud data to their API."""
new_path = request.path[request.path.index("/v01/set") :]
url = f"https://api.weathercloud.net{new_path}"
_LOGGER.debug(f"Forwarding WeatherCloud data: {url}")
return await self.session.get(url)

async def forward(self, sink: DataSink, request: web.Request) -> web.Response:
Expand Down

0 comments on commit 51e4d19

Please sign in to comment.