Remove _AsyncDownloader, just use a regular function instead
This commit is contained in:
@@ -210,20 +210,17 @@ class UpdatesControllerThread(BaseDownloadThread):
|
|||||||
# self.status = ThreadStatus.OK
|
# self.status = ThreadStatus.OK
|
||||||
|
|
||||||
|
|
||||||
class _AsyncDownloader:
|
async def _download_resource(session, link):
|
||||||
"""Mixin class for asynchronous threads."""
|
"""Return the content of 'link' as bytes."""
|
||||||
|
ssl_context = ssl.create_default_context(
|
||||||
async def _download_resource(self, session, link):
|
purpose=ssl.Purpose.SERVER_AUTH,
|
||||||
"""Return the content of 'link' as bytes."""
|
cafile=get_cacert_file()
|
||||||
ssl_context = ssl.create_default_context(
|
)
|
||||||
purpose=ssl.Purpose.SERVER_AUTH,
|
resp = await session.get(link, ssl=ssl_context)
|
||||||
cafile=get_cacert_file()
|
return await resp.read()
|
||||||
)
|
|
||||||
resp = await session.get(link, ssl=ssl_context)
|
|
||||||
return await resp.read()
|
|
||||||
|
|
||||||
|
|
||||||
class UpdateSpaceWeatherThread(BaseDownloadThread, _AsyncDownloader):
|
class UpdateSpaceWeatherThread(BaseDownloadThread):
|
||||||
"""Subclass BaseDownloadThread. Download the space weather data."""
|
"""Subclass BaseDownloadThread. Download the space weather data."""
|
||||||
|
|
||||||
_PROPERTIES = ("xray", "prot_el", "ak_index", "sgas", "geo_storm")
|
_PROPERTIES = ("xray", "prot_el", "ak_index", "sgas", "geo_storm")
|
||||||
@@ -236,14 +233,12 @@ class UpdateSpaceWeatherThread(BaseDownloadThread, _AsyncDownloader):
|
|||||||
async def _download_property(self, session, property_name):
|
async def _download_property(self, session, property_name):
|
||||||
"""Download the data conteining the information of a specific property."""
|
"""Download the data conteining the information of a specific property."""
|
||||||
link = getattr(Constants, "SPACE_WEATHER_" + property_name.upper())
|
link = getattr(Constants, "SPACE_WEATHER_" + property_name.upper())
|
||||||
data = await self._download_resource(session, link)
|
data = await _download_resource(session, link)
|
||||||
setattr(self._space_weather_data, property_name, str(data, 'utf-8'))
|
setattr(self._space_weather_data, property_name, str(data, 'utf-8'))
|
||||||
|
|
||||||
async def _download_image(self, session, n):
|
async def _download_image(self, session, n):
|
||||||
"""Download the data corresponding the n-th image displayed in the screen."""
|
"""Download the data corresponding the n-th image displayed in the screen."""
|
||||||
im = await self._download_resource(
|
im = await _download_resource(session, Constants.SPACE_WEATHER_IMGS[n])
|
||||||
session, Constants.SPACE_WEATHER_IMGS[n]
|
|
||||||
)
|
|
||||||
self._space_weather_data.images[n].loadFromData(im)
|
self._space_weather_data.images[n].loadFromData(im)
|
||||||
|
|
||||||
async def _download_resources(self):
|
async def _download_resources(self):
|
||||||
@@ -278,7 +273,7 @@ class UpdateSpaceWeatherThread(BaseDownloadThread, _AsyncDownloader):
|
|||||||
asyncio.run(self._download_resources())
|
asyncio.run(self._download_resources())
|
||||||
|
|
||||||
|
|
||||||
class UpdateForecastThread(BaseDownloadThread, _AsyncDownloader):
|
class UpdateForecastThread(BaseDownloadThread):
|
||||||
"""Subclass BaseDownloadThread. Download the forecast data."""
|
"""Subclass BaseDownloadThread. Download the forecast data."""
|
||||||
|
|
||||||
class _PropertyName(Enum):
|
class _PropertyName(Enum):
|
||||||
@@ -293,7 +288,7 @@ class UpdateForecastThread(BaseDownloadThread, _AsyncDownloader):
|
|||||||
|
|
||||||
async def _download_property(self, session, link, prop_name):
|
async def _download_property(self, session, link, prop_name):
|
||||||
"""Download the data from 'link' and set the corresponding property of the owner."""
|
"""Download the data from 'link' and set the corresponding property of the owner."""
|
||||||
resp = await self._download_resource(session, link)
|
resp = await _download_resource(session, link)
|
||||||
resp = str(resp, 'utf-8')
|
resp = str(resp, 'utf-8')
|
||||||
if prop_name is self._PropertyName.FORECAST:
|
if prop_name is self._PropertyName.FORECAST:
|
||||||
self.owner.forecast = resp
|
self.owner.forecast = resp
|
||||||
|
|||||||
Reference in New Issue
Block a user