Skip to content

Commit a23425d

Browse files
authored
Merge pull request #60 from TheFinalJoke/cleanup-and-annotate
Cleanup and annotate
2 parents d3e3c41 + 0c0c096 commit a23425d

File tree

7 files changed

+109
-112
lines changed

7 files changed

+109
-112
lines changed

lib/run.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import requests
66
import logging
77
import aiohttp
8+
from requests.models import Response
89

910
stream_formatter = logging.Formatter(
1011
"%(levelname)s:%(asctime)s:%(module)s:%(message)s"
@@ -61,22 +62,26 @@ def __init__(self, config):
6162
else:
6263
self.logger.setLevel(10)
6364
self.logger.debug(f"Runner logger is set to {self.logger.getEffectiveLevel()}")
64-
def run_non_async_request(self, url):
65+
66+
def run_non_async_request(self, url) -> Response:
6567
response = requests.get(url)
6668
return response
67-
async def get_data(self, url, headers: Dict[str, str]={}):
69+
70+
async def get_data(self, url, headers: Dict[str, str]={}) -> Dict:
6871
self.logger.debug(f'Getting data with URL {url}')
6972
async with aiohttp.ClientSession() as session:
7073
async with session.get(url, headers=headers) as resp:
7174
data = await resp.json()
7275
return data
73-
async def get_non_json_data(self, url, headers: Dict[str, str]={}):
76+
77+
async def get_non_json_data(self, url, headers: Dict[str, str]={}) -> Dict:
7478
self.logger.debug(f'Getting data with URL {url}')
7579
async with aiohttp.ClientSession() as session:
7680
async with session.get(url, headers=headers) as resp:
7781
data = await resp.text()
7882
return data
79-
async def get_img(self, url, headers: Dict[str, str]={}):
83+
84+
async def get_img(self, url, headers: Dict[str, str]={}) -> Dict:
8085
self.logger.debug(f'Getting data with URL {url}')
8186
async with aiohttp.ClientSession() as session:
8287
async with session.get(url, headers=headers) as resp:

lib/stock/stockquote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async def run(self) -> Dict:
2626
"""
2727
returns current stock Quotes and Price
2828
"""
29-
self.logger.info("Running Stock Data")
29+
self.logger.info("Running Stock Api")
3030
symbol = self.config.get('symbol')
3131
api_data = await self.get_data(self.url_builder(symbol=symbol))
3232
api_data['symbol'] = symbol

lib/weather/weather.py

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,39 @@
44
import sys
55
import os
66
import json
7-
from typing import Dict, Tuple
7+
from typing import Dict, Tuple, List
88
from datetime import datetime
9+
from datetime import timedelta
910
import csv
1011

11-
def get_weather_csv():
12+
def get_weather_csv() -> List[Dict[str, str]]:
1213
csv_path = '/etc/ohmyoled/ecIcons_utf8.csv'
1314
return list(csv.DictReader(open(csv_path)))
14-
def build_weather_icons():
15+
def build_weather_icons() -> str:
1516
csv = get_weather_csv()
1617
icon = {}
1718
for icn in csv:
1819
icon.update({icn["OWMCode"]: WeatherIcon(icn['OWMCode'], icn['Description'], icn['fontcode'], icn['font'])})
1920
return icon
2021

2122
class WeatherIcon():
22-
def __init__(self, owm_id, description, fontcode, font) -> None:
23+
def __init__(self, owm_id: str, description: str, fontcode: str, font: str) -> None:
2324
self.owm_id = owm_id
2425
self.description = description
2526
self.fontcode = fontcode
2627
self.font = font
2728

2829
@property
29-
def get_owm_id(self):
30+
def get_owm_id(self) -> str:
3031
return self.owm_id
3132
@property
32-
def get_description(self):
33+
def get_description(self) -> str:
3334
return self.description
3435
@property
35-
def get_fontcode(self):
36+
def get_fontcode(self) -> str:
3637
return self.fontcode
3738
@property
38-
def get_font(self):
39+
def get_font(self) -> str:
3940
return self.font
4041

4142

@@ -46,14 +47,14 @@ class WeatherApi(Runner):
4647
To parse the config file and
4748
Run Data
4849
"""
49-
def __init__(self, config):
50+
def __init__(self, config) -> None:
5051
super().__init__(config)
5152
self.weather = self.config['weather']
5253
try:
5354
if "open_weather_token" in self.config['basic']:
54-
self.token = self.config['basic'].get('open_weather_token')
55+
self.token: str = self.config['basic'].get('open_weather_token')
5556
else:
56-
self.token = os.environ['WEATHERTOKEN']
57+
self.token: str = os.environ['WEATHERTOKEN']
5758
except KeyError:
5859
self.logger.critical("No Weather Token")
5960
sys.exit("No Weather Token")
@@ -80,7 +81,7 @@ async def get_long_and_lat(self, location: str=None, zipcode: int=None) -> Tuple
8081
self.logger.debug("Getting Lat and Long")
8182
try:
8283
if location:
83-
self.logger.debug("Getting Longitude and Latitude")
84+
self.logger.debug("Computing Longitude and Latitude")
8485
url = f'http://api.openweathermap.org/data/2.5/weather?q={location}&appid={self.token}'
8586
response = await self.get_data(url)
8687
lon = response.get('coord').get('lon')
@@ -91,7 +92,8 @@ async def get_long_and_lat(self, location: str=None, zipcode: int=None) -> Tuple
9192
except Exception as e:
9293
self.logger.critical(e)
9394
sys.exit("No City Found")
94-
def get_current_location(self):
95+
96+
def get_current_location(self) -> Dict[str, str]:
9597
url = 'http://ipinfo.io/json'
9698
response = self.run_non_async_request(url)
9799
return response.json()
@@ -100,9 +102,9 @@ async def url_builder(self, location=None, zipcode=None, current_location=False)
100102
"""
101103
Builds Url to poll the Api
102104
"""
103-
self.logger.debug("Building url...")
105+
self.logger.debug("Building Weather url...")
104106
if current_location:
105-
ip_json = self.get_current_location()
107+
ip_json: Dict[str, str] = self.get_current_location()
106108
lon, lat = ip_json['loc'].split(',')[1], ip_json['loc'].split(',')[0]
107109
url = f"https://api.openweathermap.org/data/2.5/onecall?lat={lat}&lon={lon}&appid={self.token}&units={self.weather.get('format')}"
108110
elif location:
@@ -114,15 +116,8 @@ async def url_builder(self, location=None, zipcode=None, current_location=False)
114116
url = f"https://api.openweathermap.org/data/2.5/onecall?lat={lat}&lon={lon}&appid={self.token}&units={self.weather.get('format')}"
115117
return url
116118

117-
async def run(self):
118-
"""
119-
Get Args
120-
parse args
121-
Build URL
122-
make request
123-
return Json
124-
"""
125-
self.logger.info("Using to get Weather")
119+
async def run(self) -> Dict:
120+
self.logger.info("Running Api for Weather")
126121
args = await self.parse_args()
127122
api_data = await self.get_data(args)
128123
api_data['name'] = self.get_current_location()['city']
@@ -180,89 +175,89 @@ def __repr__(self) -> str:
180175
return f"Weather(\n{joined_attrs})"
181176

182177
@property
183-
def get_wind_speed(self):
178+
def get_wind_speed(self) -> int:
184179
return self._wind_speed
185180

186-
def set_wind_speed(self, speed):
181+
def set_wind_speed(self, speed: int) -> None:
187182
self._wind_speed = speed
188183

189184
@property
190-
def get_daily(self):
185+
def get_daily(self) -> Dict[str, str]:
191186
return self._daily
192187

193188
@property
194-
def get_wind_deg(self):
189+
def get_wind_deg(self) -> int:
195190
return self._wind_deg
196191

197192
@property
198-
def get_precipitation(self):
193+
def get_precipitation(self) -> int:
199194
return self._pop * 100
200195

201196
@property
202-
def get_uv(self):
197+
def get_uv(self) -> int:
203198
return self._uv
204199

205-
def set_place(self, place):
200+
def set_place(self, place: str) -> None:
206201
self._place = place
207202

208203
@property
209-
def get_place(self):
204+
def get_place(self) -> str:
210205
return self._place
211206

212-
def set_weather(self, weather):
207+
def set_weather(self, weather: Dict[str, str]) -> None:
213208
self._weather = weather
214209

215210
@property
216-
def get_weather(self):
211+
def get_weather(self) -> Dict[str, str]:
217212
return self._weather
218213

219-
def set_conditions(self, conditions):
214+
def set_conditions(self, conditions: str) -> None:
220215
self._conditions = conditions
221216

222217
@property
223-
def get_conditions(self):
218+
def get_conditions(self) -> str:
224219
return self._conditions
225220

226-
def set_weather_icon(self, icon):
221+
def set_weather_icon(self, icon: str) -> None:
227222
self._weather_icon = icon
228223

229224
@property
230-
def get_weather_icon(self):
225+
def get_weather_icon(self) -> str:
231226
return self._weather_icon
232227

233-
def set_temp(self, temp):
228+
def set_temp(self, temp: int) -> None:
234229
self._temp = temp
235230

236231
@property
237-
def get_temp(self):
232+
def get_temp(self) -> int:
238233
return self._temp
239234

240-
def set_feels_like(self, feels):
235+
def set_feels_like(self, feels: int):
241236
self._feels_like = feels
242237

243238
@property
244-
def get_feels_like(self):
239+
def get_feels_like(self) -> int:
245240
return self._feels_like
246241

247-
def set_min_temp(self, temp):
242+
def set_min_temp(self, temp: int) -> None:
248243
self._min_temp = temp
249244

250245
@property
251-
def get_min_temp(self):
246+
def get_min_temp(self) -> int:
252247
return self._min_temp
253248

254-
def set_max_temp(self, temp):
249+
def set_max_temp(self, temp: int) -> None:
255250
self._max_temp = temp
256251

257252
@property
258-
def get_max_temp(self):
253+
def get_max_temp(self) -> int:
259254
return self._max_temp
260255

261-
def set_humidity(self, humidity):
256+
def set_humidity(self, humidity: int) -> None:
262257
self._humidity = humidity
263258

264259
@property
265-
def get_humidity(self):
260+
def get_humidity(self) -> None:
266261
return self._humidity
267262

268263
def set_wind(self, wind: Dict) -> None:
@@ -272,14 +267,14 @@ def set_wind(self, wind: Dict) -> None:
272267
def get_wind(self) -> Dict:
273268
return self._wind
274269

275-
def set_time(self, time) -> None:
270+
def set_time(self, time: int) -> None:
276271
self._time = datetime.fromtimestamp(time)
277272

278273
@property
279274
def get_time(self) -> datetime:
280275
return self._time
281276

282-
def set_sunrise(self, time) -> None:
277+
def set_sunrise(self, time: int) -> None:
283278
self._sunrise = datetime.fromtimestamp(time)
284279

285280
@property
@@ -293,5 +288,5 @@ def set_sunset(self, time) -> None:
293288
def get_sunset(self) -> datetime:
294289
return self._sunset
295290

296-
def calculate_duration_of_daylight(self):
291+
def calculate_duration_of_daylight(self) -> timedelta:
297292
return self._sunset - self._time

matrix/matrix.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
from abc import abstractmethod
55
import asyncio
66
import functools
7-
import configparser
87
import logging
98
from sys import exec_prefix
10-
from PIL import Image, ImageDraw, ImageFont
9+
from PIL import Image, ImageDraw
1110
from typing import Deque, Tuple, List
1211
from collections import deque
1312
from rgbmatrix import (
14-
RGBMatrixOptions,
1513
RGBMatrix,
1614
graphics
1715
)

0 commit comments

Comments
 (0)