Skip to content

Commit d8b3873

Browse files
authored
Merge pull request #65 from TheFinalJoke/dev
Releasing Version 0.5.0
2 parents 94a2d47 + f7d0caa commit d8b3873

File tree

14 files changed

+237
-164
lines changed

14 files changed

+237
-164
lines changed

lib/binary_build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
VERSION="0.4.0"
2+
VERSION="0.5.0"
33

44
# Can't put full folders
55
echo "Building the binary"

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: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,46 @@
11
#!/usr/bin/env python3
22

3+
import asyncio
4+
from logging import currentframe
35
from lib.run import Runner, Caller
6+
from lib.asynclib import make_async
47
import sys
58
import os
69
import json
7-
from typing import Dict, Tuple
10+
from typing import Dict, Tuple, List
811
from datetime import datetime
12+
from datetime import timedelta
913
import csv
1014

11-
def get_weather_csv():
15+
def get_weather_csv() -> List[Dict[str, str]]:
1216
csv_path = '/etc/ohmyoled/ecIcons_utf8.csv'
1317
return list(csv.DictReader(open(csv_path)))
14-
def build_weather_icons():
18+
19+
def build_weather_icons() -> str:
1520
csv = get_weather_csv()
1621
icon = {}
1722
for icn in csv:
1823
icon.update({icn["OWMCode"]: WeatherIcon(icn['OWMCode'], icn['Description'], icn['fontcode'], icn['font'])})
1924
return icon
2025

2126
class WeatherIcon():
22-
def __init__(self, owm_id, description, fontcode, font) -> None:
27+
def __init__(self, owm_id: str, description: str, fontcode: str, font: str) -> None:
2328
self.owm_id = owm_id
2429
self.description = description
2530
self.fontcode = fontcode
2631
self.font = font
2732

2833
@property
29-
def get_owm_id(self):
34+
def get_owm_id(self) -> str:
3035
return self.owm_id
3136
@property
32-
def get_description(self):
37+
def get_description(self) -> str:
3338
return self.description
3439
@property
35-
def get_fontcode(self):
40+
def get_fontcode(self) -> str:
3641
return self.fontcode
3742
@property
38-
def get_font(self):
43+
def get_font(self) -> str:
3944
return self.font
4045

4146

@@ -46,14 +51,14 @@ class WeatherApi(Runner):
4651
To parse the config file and
4752
Run Data
4853
"""
49-
def __init__(self, config):
54+
def __init__(self, config) -> None:
5055
super().__init__(config)
5156
self.weather = self.config['weather']
5257
try:
5358
if "open_weather_token" in self.config['basic']:
54-
self.token = self.config['basic'].get('open_weather_token')
59+
self.token: str = self.config['basic'].get('open_weather_token')
5560
else:
56-
self.token = os.environ['WEATHERTOKEN']
61+
self.token: str = os.environ['WEATHERTOKEN']
5762
except KeyError:
5863
self.logger.critical("No Weather Token")
5964
sys.exit("No Weather Token")
@@ -80,7 +85,7 @@ async def get_long_and_lat(self, location: str=None, zipcode: int=None) -> Tuple
8085
self.logger.debug("Getting Lat and Long")
8186
try:
8287
if location:
83-
self.logger.debug("Getting Longitude and Latitude")
88+
self.logger.debug("Computing Longitude and Latitude")
8489
url = f'http://api.openweathermap.org/data/2.5/weather?q={location}&appid={self.token}'
8590
response = await self.get_data(url)
8691
lon = response.get('coord').get('lon')
@@ -91,7 +96,9 @@ async def get_long_and_lat(self, location: str=None, zipcode: int=None) -> Tuple
9196
except Exception as e:
9297
self.logger.critical(e)
9398
sys.exit("No City Found")
94-
def get_current_location(self):
99+
100+
@make_async
101+
def get_current_location(self) -> Dict[str, str]:
95102
url = 'http://ipinfo.io/json'
96103
response = self.run_non_async_request(url)
97104
return response.json()
@@ -100,32 +107,26 @@ async def url_builder(self, location=None, zipcode=None, current_location=False)
100107
"""
101108
Builds Url to poll the Api
102109
"""
103-
self.logger.debug("Building url...")
110+
self.logger.debug("Building Weather url...")
104111
if current_location:
105-
ip_json = self.get_current_location()
112+
ip_json: Dict[str, str] = await self.get_current_location()
106113
lon, lat = ip_json['loc'].split(',')[1], ip_json['loc'].split(',')[0]
107114
url = f"https://api.openweathermap.org/data/2.5/onecall?lat={lat}&lon={lon}&appid={self.token}&units={self.weather.get('format')}"
108115
elif location:
109116
lon, lat = await self.get_long_and_lat(location)
110117
url = f"https://api.openweathermap.org/data/2.5/onecall?lat={lat}&lon={lon}&appid={self.token}&units={self.weather.get('format')}"
111118
else:
112-
ip_json = self.get_current_location()
119+
ip_json = await self.get_current_location()
113120
lon, lat = ip_json['loc'].split(',')[1], ip_json['loc'].split(',')[0]
114121
url = f"https://api.openweathermap.org/data/2.5/onecall?lat={lat}&lon={lon}&appid={self.token}&units={self.weather.get('format')}"
115122
return url
116123

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")
124+
async def run(self) -> Dict:
125+
self.logger.info("Running Api for Weather")
126126
args = await self.parse_args()
127127
api_data = await self.get_data(args)
128-
api_data['name'] = self.get_current_location()['city']
128+
current_data = await self.get_current_location()
129+
api_data['name'] = current_data['city']
129130
return api_data
130131

131132
class Weather(Caller):
@@ -180,89 +181,89 @@ def __repr__(self) -> str:
180181
return f"Weather(\n{joined_attrs})"
181182

182183
@property
183-
def get_wind_speed(self):
184+
def get_wind_speed(self) -> int:
184185
return self._wind_speed
185186

186-
def set_wind_speed(self, speed):
187+
def set_wind_speed(self, speed: int) -> None:
187188
self._wind_speed = speed
188189

189190
@property
190-
def get_daily(self):
191+
def get_daily(self) -> Dict[str, str]:
191192
return self._daily
192193

193194
@property
194-
def get_wind_deg(self):
195+
def get_wind_deg(self) -> int:
195196
return self._wind_deg
196197

197198
@property
198-
def get_precipitation(self):
199-
return self._pop
199+
def get_precipitation(self) -> int:
200+
return self._pop * 100
200201

201202
@property
202-
def get_uv(self):
203+
def get_uv(self) -> int:
203204
return self._uv
204205

205-
def set_place(self, place):
206+
def set_place(self, place: str) -> None:
206207
self._place = place
207208

208209
@property
209-
def get_place(self):
210+
def get_place(self) -> str:
210211
return self._place
211212

212-
def set_weather(self, weather):
213+
def set_weather(self, weather: Dict[str, str]) -> None:
213214
self._weather = weather
214215

215216
@property
216-
def get_weather(self):
217+
def get_weather(self) -> Dict[str, str]:
217218
return self._weather
218219

219-
def set_conditions(self, conditions):
220+
def set_conditions(self, conditions: str) -> None:
220221
self._conditions = conditions
221222

222223
@property
223-
def get_conditions(self):
224+
def get_conditions(self) -> str:
224225
return self._conditions
225226

226-
def set_weather_icon(self, icon):
227+
def set_weather_icon(self, icon: str) -> None:
227228
self._weather_icon = icon
228229

229230
@property
230-
def get_weather_icon(self):
231+
def get_weather_icon(self) -> str:
231232
return self._weather_icon
232233

233-
def set_temp(self, temp):
234+
def set_temp(self, temp: int) -> None:
234235
self._temp = temp
235236

236237
@property
237-
def get_temp(self):
238+
def get_temp(self) -> int:
238239
return self._temp
239240

240-
def set_feels_like(self, feels):
241+
def set_feels_like(self, feels: int):
241242
self._feels_like = feels
242243

243244
@property
244-
def get_feels_like(self):
245+
def get_feels_like(self) -> int:
245246
return self._feels_like
246247

247-
def set_min_temp(self, temp):
248+
def set_min_temp(self, temp: int) -> None:
248249
self._min_temp = temp
249250

250251
@property
251-
def get_min_temp(self):
252+
def get_min_temp(self) -> int:
252253
return self._min_temp
253254

254-
def set_max_temp(self, temp):
255+
def set_max_temp(self, temp: int) -> None:
255256
self._max_temp = temp
256257

257258
@property
258-
def get_max_temp(self):
259+
def get_max_temp(self) -> int:
259260
return self._max_temp
260261

261-
def set_humidity(self, humidity):
262+
def set_humidity(self, humidity: int) -> None:
262263
self._humidity = humidity
263264

264265
@property
265-
def get_humidity(self):
266+
def get_humidity(self) -> None:
266267
return self._humidity
267268

268269
def set_wind(self, wind: Dict) -> None:
@@ -272,14 +273,14 @@ def set_wind(self, wind: Dict) -> None:
272273
def get_wind(self) -> Dict:
273274
return self._wind
274275

275-
def set_time(self, time) -> None:
276+
def set_time(self, time: int) -> None:
276277
self._time = datetime.fromtimestamp(time)
277278

278279
@property
279280
def get_time(self) -> datetime:
280281
return self._time
281282

282-
def set_sunrise(self, time) -> None:
283+
def set_sunrise(self, time: int) -> None:
283284
self._sunrise = datetime.fromtimestamp(time)
284285

285286
@property
@@ -293,5 +294,5 @@ def set_sunset(self, time) -> None:
293294
def get_sunset(self) -> datetime:
294295
return self._sunset
295296

296-
def calculate_duration_of_daylight(self):
297+
def calculate_duration_of_daylight(self) -> timedelta:
297298
return self._sunset - self._time

0 commit comments

Comments
 (0)