Skip to content

Commit

Permalink
feat: add debug logging to proxy requests (#22)
Browse files Browse the repository at this point in the history
* feat: add debug logging to proxy requests
* fix: tox
  • Loading branch information
lhw authored Sep 13, 2024
1 parent ac7b281 commit f1ee529
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
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("Forwarding Wunderground data: %s", 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("Forwarding WeatherCloud data: %s", url)
return await self.session.get(url)

async def forward(self, sink: DataSink, request: web.Request) -> web.Response:
Expand Down
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
asyncio_default_fixture_loop_scope = function
1 change: 0 additions & 1 deletion tests/test_server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import pytest
from aiohttp import web
from aiocloudweather.server import CloudWeatherListener
Expand Down

0 comments on commit f1ee529

Please sign in to comment.