From 44359d26c5be5f780e2a83477c09f718a70aa16b Mon Sep 17 00:00:00 2001 From: Elia El Lazkani Date: Wed, 28 Aug 2019 10:44:26 +0200 Subject: [PATCH] Second commit to cmw --- .gitignore | 127 ++++++++++++++++++++++++++++++++++ README.rst | 4 ++ cmw/__init__.py | 0 cmw/cmw.py | 60 ++++++++++++++++ requirements/development.txt | 1 + requirements/requirements.txt | 1 + setup.py | 47 +++++++++++++ 7 files changed, 240 insertions(+) create mode 100644 .gitignore create mode 100644 README.rst create mode 100644 cmw/__init__.py create mode 100644 cmw/cmw.py create mode 100644 requirements/development.txt create mode 100644 requirements/requirements.txt create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2211c42 --- /dev/null +++ b/.gitignore @@ -0,0 +1,127 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# VSCode +.vscode/ diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..33f323c --- /dev/null +++ b/README.rst @@ -0,0 +1,4 @@ +cmw +=== + +`cmw` is a command line weather application that queries `wttr.in`. diff --git a/cmw/__init__.py b/cmw/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cmw/cmw.py b/cmw/cmw.py new file mode 100644 index 0000000..10a9530 --- /dev/null +++ b/cmw/cmw.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 + +import argparse +import requests + +def generate_link(url, location=None, lang=None, format=None): + link = f"https://" + if lang: + link = link + f"{lang}.{url}/" + else: + link = link + f"{url}/" + + if location: + link = link + f"{location}" + + if format: + link = link + f"?format={format}" + + return link + + +def get_weather(link): + result = requests.get(link) + return result.text + +def main(): + parser = argumentparser() + url = "wttr.in" + link = generate_link(url, parser.location, parser.lang, parser.format) + weather = get_weather(link) + print(weather) + + +def argumentparser(): + parser = argparse.ArgumentParser( + description="Get the weather!" + ) + parser.add_argument( + "-l", "--location", + default=None, + type=str, + help="Location (e.g. NewYork)" + ) + parser.add_argument( + "-f", "--format", + default=None, + type=str, + help="Query formatting" + ) + parser.add_argument( + "--lang", + default=None, + type=str, + help="The language to use" + ) + return parser.parse_args() + + +if __name__ == "__main__": + main() diff --git a/requirements/development.txt b/requirements/development.txt new file mode 100644 index 0000000..3bfa2f8 --- /dev/null +++ b/requirements/development.txt @@ -0,0 +1 @@ +setuptools_git >= 0.3 diff --git a/requirements/requirements.txt b/requirements/requirements.txt new file mode 100644 index 0000000..f229360 --- /dev/null +++ b/requirements/requirements.txt @@ -0,0 +1 @@ +requests diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..84891b4 --- /dev/null +++ b/setup.py @@ -0,0 +1,47 @@ +from pathlib import Path +from setuptools import setup + +here = Path(__file__).absolute().parent + +with open(str(here.joinpath('README.rst')), encoding='utf-8') as f: + long_description = f.read() + +with open(str(here.joinpath('requirements/requirements.txt')), + encoding='utf-8') as f: + install_requires = f.read() + +description = 'Command line Weather (cmw)' + +setup( + name='cmw', + exclude_package_data={'': ['.gitignore', 'requirements/', 'setup.py']}, + setup_requires=[ "setuptools_git >= 0.3", ], + license='BSD', + author='Elia El Lazkani', + author_email='eliaellazkani@gmail.com', + url='keybase://private/elazkani/cmw', + python_requires='>=python3.5', + description=description, + long_description=long_description, + install_requires=install_requires, + entry_points={ + 'console_scripts': [ + 'cmw = cmw.cmw:main' + ] + }, + packages=['cmw'], + classifiers=[ + 'Development Status :: 4 - Beta', + 'License :: OSI Approved :: BSD License', + 'Operating System :: POSIX :: Linux', + 'Operating System :: MacOS :: MacOS X', + 'Programming Language :: Python', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Environment :: Console', + 'Intended Audience :: Information Technology', + 'Intended Audience :: System Administrators' + ], + zip_safe=False +)