diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/README.md b/README.md index d05ee4c..9a1594d 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,22 @@ It is intended to be used by ungleich engineers and skilled customers. * ensure you have python3 * git clone this repo +* cd into this repo +* run the following command +``` +sudo pip3 install -r requirements.txt +``` ## Usage general ``` ungleich --help ``` +## Usage: Weather + +``` +ungleich weather +``` ## Usage: DNS diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6404404 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +git+https://github.com/apixu/apixu-python.git@master diff --git a/ungleich b/ungleich index a8f494c..edc559a 100755 --- a/ungleich +++ b/ungleich @@ -5,6 +5,7 @@ import argparse from ungleich_dns import ungleichDNS from ungleich_ripe import ungleichRIPE from ungleich_account import Account_Create +from ungleich_weather import ungleichWeather VERSION = "0.0.3" @@ -16,6 +17,7 @@ class ungleichCLI(object): dns = ungleichDNS(self.parser, self.parser_parents) ripe = ungleichRIPE(self.parser, self.parser_parents) ripe = Account_Create(self.parser, self.parser_parents) + ungleichWeather(self.parser, self.parser_parents) def _init_parser(self): self.parser = {} diff --git a/ungleich_weather.py b/ungleich_weather.py new file mode 100644 index 0000000..5333f2c --- /dev/null +++ b/ungleich_weather.py @@ -0,0 +1,33 @@ +import argparse +import requests +import json +from apixu.client import ApixuClient + + +def get_loc(): + response = requests.get('http://ip-api.com/json/') + data = json.loads(response.content) + + return data['city'], data['countryCode'] + + +class ungleichWeather(object): + def __init__(self, parser, parents): + self.parser = parser + + self.parser['weather'] = self.parser['sub'].add_parser( + 'weather', + help="Weather Enquiries", + parents=[parents]) + self.parser['weather'].set_defaults(func=ungleichWeather.forecast_weather) + + def forecast_weather(args): + _city, _country_code = get_loc() + + client = ApixuClient("cc33a1e3237a4b78b3174104190206") + + forecast = client.forecast(q=f'{ _city},{_country_code}', days=7) + print(f"{'Date':^12}|{'Min Temp':^10}|{'Max Temp':^10}|{'Condition':^15}") + print(f"{'*'*47:^47}") + for day in forecast['forecast']['forecastday']: + print(f"{day['date']:^12}|{day['day']['mintemp_c']:^10}|{day['day']['maxtemp_c']:^10}|{day['day']['condition']['text']:^15}") \ No newline at end of file