Second commit to cmw
This commit is contained in:
commit
44359d26c5
7 changed files with 240 additions and 0 deletions
127
.gitignore
vendored
Normal file
127
.gitignore
vendored
Normal file
|
@ -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/
|
4
README.rst
Normal file
4
README.rst
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
cmw
|
||||||
|
===
|
||||||
|
|
||||||
|
`cmw` is a command line weather application that queries `wttr.in`.
|
0
cmw/__init__.py
Normal file
0
cmw/__init__.py
Normal file
60
cmw/cmw.py
Normal file
60
cmw/cmw.py
Normal file
|
@ -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()
|
1
requirements/development.txt
Normal file
1
requirements/development.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
setuptools_git >= 0.3
|
1
requirements/requirements.txt
Normal file
1
requirements/requirements.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
requests
|
47
setup.py
Normal file
47
setup.py
Normal file
|
@ -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
|
||||||
|
)
|
Loading…
Reference in a new issue