From 485f962d709b73e69a1177297fd936d0d21fa695 Mon Sep 17 00:00:00 2001 From: Elia El Lazkani Date: Wed, 28 Aug 2019 17:56:58 +0200 Subject: [PATCH] * Adding automatic versioning to the tool. * Adding a build script * Adding upstream help for formatting advice --- cmw/__init__.py | 8 ++++++ cmw/cmw.py | 48 +++++++++++++++++++++++++----------- requirements/development.txt | 3 ++- setup.py | 3 ++- setup.sh | 3 +++ 5 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 setup.sh diff --git a/cmw/__init__.py b/cmw/__init__.py index e69de29..c18c27e 100644 --- a/cmw/__init__.py +++ b/cmw/__init__.py @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 + +import pkg_resources + +try: + __version__ = pkg_resources.get_distribution("cmw").version +except Exception: + __version__ = 'unknown' diff --git a/cmw/cmw.py b/cmw/cmw.py index 10a9530..41dfe00 100644 --- a/cmw/cmw.py +++ b/cmw/cmw.py @@ -1,33 +1,40 @@ #!/usr/bin/env python3 +from . import __version__ import argparse import requests -def generate_link(url, location=None, lang=None, format=None): - link = f"https://" - if lang: - link = link + f"{lang}.{url}/" +def generate_link(url, location=None, lang=None, format=None, help=False): + link = f"https://{url}/" + headers = {} + + if help: + link = link + f"/:help" + else: - link = link + f"{url}/" + if lang: + headers = { + "Accept-Language": lang + } - if location: - link = link + f"{location}" + if location: + link = link + f"{location}" - if format: - link = link + f"?format={format}" + if format: + link = link + f"?format={format}" - return link + return link, headers -def get_weather(link): - result = requests.get(link) +def get_weather(link, headers): + result = requests.get(link, headers=headers) return result.text def main(): parser = argumentparser() url = "wttr.in" - link = generate_link(url, parser.location, parser.lang, parser.format) - weather = get_weather(link) + link, headers = generate_link(url, parser.location, parser.lang, parser.format, parser.format_help) + weather = get_weather(link, headers) print(weather) @@ -53,6 +60,19 @@ def argumentparser(): type=str, help="The language to use" ) + + parser.add_argument( + "--format-help", + default=False, + action='store_true', + help="Get format help from upstream" + ) + + parser.add_argument( + '--version', + action='version', + version=f'%(prog)s {__version__}') + return parser.parse_args() diff --git a/requirements/development.txt b/requirements/development.txt index 3bfa2f8..c6dfd89 100644 --- a/requirements/development.txt +++ b/requirements/development.txt @@ -1 +1,2 @@ -setuptools_git >= 0.3 +setuptools-git +setuptools-git-version diff --git a/setup.py b/setup.py index 84891b4..dbc8bc6 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,8 @@ description = 'Command line Weather (cmw)' setup( name='cmw', exclude_package_data={'': ['.gitignore', 'requirements/', 'setup.py']}, - setup_requires=[ "setuptools_git >= 0.3", ], + version_format='{tag}_{gitsha}', + setup_requires=['setuptools-git', 'setuptools-git-version'], license='BSD', author='Elia El Lazkani', author_email='eliaellazkani@gmail.com', diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..65336fd --- /dev/null +++ b/setup.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +python setup.py bdist_wheel