* Adding automatic versioning to the tool.
* Adding a build script * Adding upstream help for formatting advice
This commit is contained in:
parent
44359d26c5
commit
485f962d70
5 changed files with 49 additions and 16 deletions
|
@ -0,0 +1,8 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import pkg_resources
|
||||
|
||||
try:
|
||||
__version__ = pkg_resources.get_distribution("cmw").version
|
||||
except Exception:
|
||||
__version__ = 'unknown'
|
40
cmw/cmw.py
40
cmw/cmw.py
|
@ -1,14 +1,21 @@
|
|||
#!/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}"
|
||||
|
@ -16,18 +23,18 @@ def generate_link(url, location=None, lang=None, format=None):
|
|||
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()
|
||||
|
||||
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
setuptools_git >= 0.3
|
||||
setuptools-git
|
||||
setuptools-git-version
|
||||
|
|
3
setup.py
3
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',
|
||||
|
|
3
setup.sh
Normal file
3
setup.sh
Normal file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
python setup.py bdist_wheel
|
Loading…
Reference in a new issue