* Adding automatic versioning to the tool.

* Adding a build script
* Adding upstream help for formatting advice
This commit is contained in:
Elia El Lazkani 2019-08-28 17:56:58 +02:00
parent 44359d26c5
commit 485f962d70
5 changed files with 49 additions and 16 deletions

View file

@ -0,0 +1,8 @@
#!/usr/bin/env python3
import pkg_resources
try:
__version__ = pkg_resources.get_distribution("cmw").version
except Exception:
__version__ = 'unknown'

View file

@ -1,14 +1,21 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from . import __version__
import argparse import argparse
import requests import requests
def generate_link(url, location=None, lang=None, format=None): def generate_link(url, location=None, lang=None, format=None, help=False):
link = f"https://" link = f"https://{url}/"
if lang: headers = {}
link = link + f"{lang}.{url}/"
if help:
link = link + f"/:help"
else: else:
link = link + f"{url}/" if lang:
headers = {
"Accept-Language": lang
}
if location: if location:
link = link + f"{location}" link = link + f"{location}"
@ -16,18 +23,18 @@ def generate_link(url, location=None, lang=None, format=None):
if format: if format:
link = link + f"?format={format}" link = link + f"?format={format}"
return link return link, headers
def get_weather(link): def get_weather(link, headers):
result = requests.get(link) result = requests.get(link, headers=headers)
return result.text return result.text
def main(): def main():
parser = argumentparser() parser = argumentparser()
url = "wttr.in" url = "wttr.in"
link = generate_link(url, parser.location, parser.lang, parser.format) link, headers = generate_link(url, parser.location, parser.lang, parser.format, parser.format_help)
weather = get_weather(link) weather = get_weather(link, headers)
print(weather) print(weather)
@ -53,6 +60,19 @@ def argumentparser():
type=str, type=str,
help="The language to use" 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() return parser.parse_args()

View file

@ -1 +1,2 @@
setuptools_git >= 0.3 setuptools-git
setuptools-git-version

View file

@ -15,7 +15,8 @@ description = 'Command line Weather (cmw)'
setup( setup(
name='cmw', name='cmw',
exclude_package_data={'': ['.gitignore', 'requirements/', 'setup.py']}, 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', license='BSD',
author='Elia El Lazkani', author='Elia El Lazkani',
author_email='eliaellazkani@gmail.com', author_email='eliaellazkani@gmail.com',

3
setup.sh Normal file
View file

@ -0,0 +1,3 @@
#!/bin/bash
python setup.py bdist_wheel