diff --git a/README.md b/README.md index a4fbcb3..b541fac 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ cli-weather command [-h] [-c COUNTRY] [-u UNITS] [-d] city_name/postal_code Fork this repository $ git clone "https://github.com/username/cli-weather" $ cd cli_weather -$ pip install -r requirements.txt +$ pip install requests $ python main.py [command] [options] ``` @@ -56,6 +56,14 @@ $ python main.py [command] [options] GNU General Public License v3.0 +**ver 0.1.2** + +3 - Alpha Test Release +- Python2 and Python3 compatible +- Introductio of wheel distribution in binary +- Minor bug fixes in setup.py + + **ver 0.1.1** 3 - Alpha Test Release @@ -68,4 +76,4 @@ GNU General Public License v3.0 - Get weather by city - Get weather by postalcode - Change units according as you wish [Metric/Scientific/Farenheit] -- Only temparature by default, detailed information from snowfall to solar radiation \ No newline at end of file +- Only temparature by default, detailed information from snowfall to solar radiation using -d \ No newline at end of file diff --git a/build/lib.linux-x86_64-2.7/cli_weather/__init__.py b/build/lib.linux-x86_64-2.7/cli_weather/__init__.py new file mode 100644 index 0000000..e44686e --- /dev/null +++ b/build/lib.linux-x86_64-2.7/cli_weather/__init__.py @@ -0,0 +1,9 @@ +""" +cli-weather + +Get fast updates on weather-data right on the command line. +""" + +__version__ = "0.1.0" +__author__ = 'Shree Vatsa N' + diff --git a/build/lib.linux-x86_64-2.7/cli_weather/get_by_city.py b/build/lib.linux-x86_64-2.7/cli_weather/get_by_city.py new file mode 100644 index 0000000..cf4f836 --- /dev/null +++ b/build/lib.linux-x86_64-2.7/cli_weather/get_by_city.py @@ -0,0 +1,94 @@ +from __future__ import print_function +import requests +import argparse + +def get_by_city_args(subparsers): + city_parser = subparsers.add_parser('city', + formatter_class=argparse.RawTextHelpFormatter + ) + city_parser.add_argument( + "city", + help="get weather by city name" + ) + city_parser.add_argument( + "-c", "--country", + help="country of entered area", + default="" + ) + city_parser.add_argument( + "-u", "--units", + help="M - [DEFAULT] Metric (Celcius, m/s, mm)\nS - Scientific (Kelvin, m/s, mm)\nI - Fahrenheit (F, mph, in)", + default="M" + ) + city_parser.add_argument( + "-d","--detailed", + help="display detailed weather data", + action="store_true" + ) + +def city_parse(args): + city = args.city + country = "&" + args.country + units = args.units + API_KEY = "2a7db0585e7541018229c17efb2efa94" + + if args.country == "": + API_URL = "https://api.weatherbit.io/v2.0/current?city="+city+"&key=" + else: + API_URL = "https://api.weatherbit.io/v2.0/current?city="+city+country+"&key=" + + url = API_URL + API_KEY + + querystring = { + "lang":"en", + "units":units + } + + response = requests.request("GET", url, params=querystring) + + try: + main_data = response.json() + # ValueError-unable to decode json, UnboundLocalError-used var before declaring + except (ValueError,UnboundLocalError) as err: + print("Invalid city") + print("Please use format ex: $ cli-weather bengaluru [-c country_name][-u S/M/F][-d]") + return + + data = main_data['data'] + weather = data[0]['weather'] + # defalut metric values + degree = "celcius" + speed = "m/s" + distance = "mm" + + if args.units == "S": + degree = "kelvin" + elif args.units == "F": + degree = "Fahrenheit" + speed = "mph" + distance = "in" + + if args.detailed: + print("Have a nice day!\n") + print("city : {}".format(args.city.capitalize())) + print("temparature : {} {}".format(data[0]['temp'],degree)) + print("summary : {}".format(weather['description'])) + print("source station ID : {}".format(data[0]['station'])) + print("latitude : {} degrees".format(data[0]['lat'])) + print("longitude : {} degrees".format(data[0]['lon'])) + print("timezone : {}".format(data[0]['timezone'])) + print("last observation time : {}".format(data[0]['ob_time'])) + print("sunrise : {}".format(data[0]['sunrise'])) + print("sunset : {}".format(data[0]['sunset'])) + print("pressure : {} mb".format(data[0]['pres'])) + print("sea level pressure : {} mb".format(data[0]['slp'])) + print("wind speed : {} {}".format(data[0]['wind_spd'],speed)) + print("wind direction : {} degrees".format(data[0]['wind_dir'])) + print("visibility : {} KM".format(data[0]['vis'])) + print("relative humidity : {} %".format(data[0]['rh'])) + print("snowfall : {} {}/hr".format(data[0]['snow'],distance)) + print("estimated solar radiation: {} W/m^2".format(data[0]['solar_rad'])) + + elif args.detailed is False: + print("Current temparature in {} is {} {}" .format(city.capitalize(), data[0]['temp'], degree)) + \ No newline at end of file diff --git a/build/lib.linux-x86_64-2.7/cli_weather/get_by_postalcode.py b/build/lib.linux-x86_64-2.7/cli_weather/get_by_postalcode.py new file mode 100644 index 0000000..339f982 --- /dev/null +++ b/build/lib.linux-x86_64-2.7/cli_weather/get_by_postalcode.py @@ -0,0 +1,93 @@ +from __future__ import print_function +import requests +import argparse + +def get_by_postalcode_args(subparsers): + postalcode_parser = subparsers.add_parser('postalcode', + formatter_class=argparse.RawTextHelpFormatter + ) + postalcode_parser.add_argument( + "postalcode", + help="get weather by postal code" + ) + postalcode_parser.add_argument( + "-c", "--country", + help="country of entered area", + default="" + ) + postalcode_parser.add_argument( + "-u", "--units", + help="M - [DEFAULT] Metric (Celcius, m/s, mm)\nS - Scientific (Kelvin, m/s, mm)\nI - Fahrenheit (F, mph, in)", + default="M" + ) + postalcode_parser.add_argument( + "-d","--detailed", + help="display sdetailed weather data", + action="store_true" + ) + +def postalcode_parse(args): + postalcode = args.postalcode + country = "&" + args.country + units = args.units + API_KEY = "2a7db0585e7541018229c17efb2efa94" + + if args.country == "": + API_URL = "https://api.weatherbit.io/v2.0/current?postal_code="+postalcode+"&key=" + else: + API_URL = "https://api.weatherbit.io/v2.0/current?postal_code="+postalcode+country+"&key=" + + url = API_URL + API_KEY + + querystring = { + "lang":"en", + "units":units + } + + response = requests.request("GET", url, params=querystring) + + try: + main_data = response.json() + # ValueError-unable to decode json, UnboundLocalError-used var before declaring + except (ValueError,UnboundLocalError) as err: + print("Invalid postal-code") + print("Please use format ex: $ cli-weather postal-code 560032 [-c country_name][-u S/M/F][-d]") + return + + data = main_data['data'] + weather = data[0]['weather'] + # defalut metric values + degree = "celcius" + speed = "m/s" + distance = "mm" + + if args.units == "S": + degree = "kelvin" + elif args.units == "F": + degree = "Fahrenheit" + speed = "mph" + distance = "in" + + if args.detailed: + print("Have a nice day!\n") + print("city : {}".format(data[0]['city_name'].capitalize())) + print("temparature : {} {}".format(data[0]['temp'],degree)) + print("summary : {}".format(weather['description'])) + print("source station ID : {}".format(data[0]['station'])) + print("latitude : {} degrees".format(data[0]['lat'])) + print("longitude : {} degrees".format(data[0]['lon'])) + print("timezone : {}".format(data[0]['timezone'])) + print("last observation time : {}".format(data[0]['ob_time'])) + print("sunrise : {}".format(data[0]['sunrise'])) + print("sunset : {}".format(data[0]['sunset'])) + print("pressure : {} mb".format(data[0]['pres'])) + print("sea level pressure : {} mb".format(data[0]['slp'])) + print("wind speed : {} {}".format(data[0]['wind_spd'],speed)) + print("wind direction : {} degrees".format(data[0]['wind_dir'])) + print("visibility : {} KM".format(data[0]['vis'])) + print("relative humidity : {} %".format(data[0]['rh'])) + print("snowfall : {} {}/hr".format(data[0]['snow'],distance)) + print("estimated solar radiation: {} W/m^2".format(data[0]['solar_rad'])) + elif args.detailed is False: + print("Current temparature in {} is {} {}" .format(data[0]['city_name'].capitalize(), data[0]['temp'], degree)) + \ No newline at end of file diff --git a/build/lib.linux-x86_64-2.7/cli_weather/main.py b/build/lib.linux-x86_64-2.7/cli_weather/main.py new file mode 100644 index 0000000..4a42a4d --- /dev/null +++ b/build/lib.linux-x86_64-2.7/cli_weather/main.py @@ -0,0 +1,29 @@ +from __future__ import print_function +import argparse + +# handle ModuleNotFoundError python3 execution +try: + from cli_weather.get_by_city import get_by_city_args, city_parse + from cli_weather.get_by_postalcode import get_by_postalcode_args, postalcode_parse +except ModuleNotFoundError: + from get_by_city import get_by_city_args, city_parse + from get_by_postalcode import get_by_postalcode_args, postalcode_parse + +def main(): + parser = argparse.ArgumentParser('cli-weather') + + # dest - name of the attribute under which sub-command name will be stored, defalut=None + subparsers = parser.add_subparsers(dest="selected_subparser") + get_by_city_args(subparsers) + get_by_postalcode_args(subparsers) + args = parser.parse_args() + + # args.selected_subparser holds selectd subparser in + if args.selected_subparser == "city": + city_parse(args) + elif args.selected_subparser == "postalcode": + postalcode_parse(args) + +if __name__ == "__main__": + main() + \ No newline at end of file diff --git a/cli_weather.egg-info/PKG-INFO b/cli_weather.egg-info/PKG-INFO index d7f9d68..3213893 100644 --- a/cli_weather.egg-info/PKG-INFO +++ b/cli_weather.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: cli-weather -Version: 0.1.1 +Version: 0.1.2 Summary: Lightweight command line app to get fast weather data right on the command line Home-page: https://github.com/vatsa287/cli-weather Author: Shree Vatsa N @@ -55,7 +55,7 @@ Description: # cli-weather Fork this repository $ git clone "https://github.com/username/cli-weather" $ cd cli_weather - $ pip install -r requirements.txt + $ pip install requests $ python main.py [command] [options] ``` @@ -64,6 +64,14 @@ Description: # cli-weather GNU General Public License v3.0 + **ver 0.1.2** + + 3 - Alpha Test Release + - Python2 and Python3 compatible + - Introductio of wheel distribution in binary + - Minor bug fixes in setup.py + + **ver 0.1.1** 3 - Alpha Test Release @@ -76,7 +84,7 @@ Description: # cli-weather - Get weather by city - Get weather by postalcode - Change units according as you wish [Metric/Scientific/Farenheit] - - Only temparature by default, detailed information from snowfall to solar radiation + - Only temparature by default, detailed information from snowfall to solar radiation using -d Platform: UNKNOWN Classifier: Development Status :: 3 - Alpha Classifier: Topic :: Utilities diff --git a/cli_weather/__pycache__/get_by_city.cpython-36.pyc b/cli_weather/__pycache__/get_by_city.cpython-36.pyc index 25a84f0..b47f2ec 100644 Binary files a/cli_weather/__pycache__/get_by_city.cpython-36.pyc and b/cli_weather/__pycache__/get_by_city.cpython-36.pyc differ diff --git a/cli_weather/__pycache__/get_by_postalcode.cpython-36.pyc b/cli_weather/__pycache__/get_by_postalcode.cpython-36.pyc index 871d677..18bffc5 100644 Binary files a/cli_weather/__pycache__/get_by_postalcode.cpython-36.pyc and b/cli_weather/__pycache__/get_by_postalcode.cpython-36.pyc differ diff --git a/cli_weather/get_by_city.py b/cli_weather/get_by_city.py index af4250d..cf4f836 100644 --- a/cli_weather/get_by_city.py +++ b/cli_weather/get_by_city.py @@ -1,3 +1,4 @@ +from __future__ import print_function import requests import argparse diff --git a/cli_weather/get_by_postalcode.py b/cli_weather/get_by_postalcode.py index 98edebc..339f982 100644 --- a/cli_weather/get_by_postalcode.py +++ b/cli_weather/get_by_postalcode.py @@ -1,3 +1,4 @@ +from __future__ import print_function import requests import argparse @@ -89,4 +90,4 @@ def postalcode_parse(args): print("estimated solar radiation: {} W/m^2".format(data[0]['solar_rad'])) elif args.detailed is False: print("Current temparature in {} is {} {}" .format(data[0]['city_name'].capitalize(), data[0]['temp'], degree)) - + \ No newline at end of file diff --git a/cli_weather/main.py b/cli_weather/main.py index b57a926..4a42a4d 100644 --- a/cli_weather/main.py +++ b/cli_weather/main.py @@ -1,6 +1,13 @@ +from __future__ import print_function import argparse -from get_by_city import get_by_city_args, city_parse -from get_by_postalcode import get_by_postalcode_args, postalcode_parse + +# handle ModuleNotFoundError python3 execution +try: + from cli_weather.get_by_city import get_by_city_args, city_parse + from cli_weather.get_by_postalcode import get_by_postalcode_args, postalcode_parse +except ModuleNotFoundError: + from get_by_city import get_by_city_args, city_parse + from get_by_postalcode import get_by_postalcode_args, postalcode_parse def main(): parser = argparse.ArgumentParser('cli-weather') @@ -18,4 +25,5 @@ def main(): postalcode_parse(args) if __name__ == "__main__": - main() \ No newline at end of file + main() + \ No newline at end of file diff --git a/dist/cli-weather-0.1.1.tar.gz b/dist/cli-weather-0.1.1.tar.gz deleted file mode 100644 index d5b61a2..0000000 Binary files a/dist/cli-weather-0.1.1.tar.gz and /dev/null differ diff --git a/dist/cli-weather-0.1.2.tar.gz b/dist/cli-weather-0.1.2.tar.gz new file mode 100644 index 0000000..0eeea54 Binary files /dev/null and b/dist/cli-weather-0.1.2.tar.gz differ diff --git a/dist/cli_weather-0.1.2-py2.py3-none-any.whl b/dist/cli_weather-0.1.2-py2.py3-none-any.whl new file mode 100644 index 0000000..5d783b3 Binary files /dev/null and b/dist/cli_weather-0.1.2-py2.py3-none-any.whl differ diff --git a/setup.py b/setup.py index 5b78e49..173eeb3 100644 --- a/setup.py +++ b/setup.py @@ -1,13 +1,14 @@ from setuptools import setup -long_description = open('/home/vatsa/cli-weather/PyPIDocumentation.md').read() +with open('README.md') as f: + long_description = f.read() setup( name='cli-weather', - version='0.1.1', + version='0.1.2', description='Lightweight command line app to get fast weather data right on the command line', - long_description_content_type='text/markdown', long_description=long_description, + long_description_content_type='text/markdown', url='https://github.com/vatsa287/cli-weather', author='Shree Vatsa N', author_email='i.mnshreevatsa@gmail.com',