pax_global_header00006660000000000000000000000064137210417470014520gustar00rootroot0000000000000052 comment=73f86811208459d690217ae58a669158410774e0 danoscarmike-aqipy-73f8681/000077500000000000000000000000001372104174700155715ustar00rootroot00000000000000danoscarmike-aqipy-73f8681/.gitignore000066400000000000000000000024261372104174700175650ustar00rootroot00000000000000# 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/ *.egg-info/ .installed.cfg *.egg MANIFEST release.sh # 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/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover .hypothesis/ .pytest_cache/ # Translations *.mo *.pot # Django stuff: *.log local_settings.py db.sqlite3 # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder target/ # Jupyter Notebook .ipynb_checkpoints # pyenv .python-version # celery beat schedule file celerybeat-schedule # SageMath parsed files *.sage.py # Environments .env .venv bin/ include/ env/ venv/ ENV/ env.bak/ pip-selfcheck.json pyvenv.cfg venv.bak/ # Spyder project settings .spyderproject .spyproject # Rope project settings .ropeproject # mkdocs documentation /site # mypy .mypy_cache/ # IDE stuff .vscode # Mac stuff .DS_Store danoscarmike-aqipy-73f8681/LICENSE000066400000000000000000000020641372104174700166000ustar00rootroot00000000000000MIT License Copyright (c) 2018 Daniel John O'Meara Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. danoscarmike-aqipy-73f8681/README.md000066400000000000000000000013451372104174700170530ustar00rootroot00000000000000# AQIPY A simple tool to get Air Quality Indices from around the world. ## Installation 1. Get an API token [here](https://aqicn.org/data-platform/token/#/). 1. Create an environment variable with your token: `export AQIPY_TOKEN=''` ### From source 1. Clone this repository. 1. From your new directory: `pip3 install -e .` ### From PyPI `pip install aqipy` ## Usage To get the AQI for your current location (IP based): `aqipy` To get the AQI for a specific location (latitude longitude): `aqipy geo [--latlon / -l ]` ### Example `$ aqipy geo --latlon 53.8 -7.4` ## Attribution This tool uses APIs provided by the [World Air Quality Index Project](http://waqi.info/). danoscarmike-aqipy-73f8681/aqipy/000077500000000000000000000000001372104174700167145ustar00rootroot00000000000000danoscarmike-aqipy-73f8681/aqipy/__init__.py000066400000000000000000000000171372104174700210230ustar00rootroot00000000000000name = "aqipy" danoscarmike-aqipy-73f8681/aqipy/__main__.py000066400000000000000000000057661372104174700210240ustar00rootroot00000000000000import click import os import requests @click.group(invoke_without_command=True) @click.pass_context def main(ctx): """A simple command line tool to find Air Quality Indices (AQI) from around the world.""" ctx.ensure_object(dict) try: api_token = os.environ["AQIPY_TOKEN"] ctx.obj["TOKEN"] = {"token": api_token} ctx.obj["BASE_URL"] = "http://api.waqi.info/feed/" except: click.echo(f"ERROR: You must set an AQIPY_TOKEN environment variable.") click.echo(f"Request a token at https://aqicn.org/data-platform/token/#/") return if ctx.invoked_subcommand is None: url = f'{ctx.obj["BASE_URL"]}here/' api_request(url, ctx.obj["TOKEN"]) def validate_latlon(ctx, param, value): try: lat, lon = value[0], value[1] return lat.strip() + ";" + lon.strip() except ValueError: raise click.BadParameter('latlon must be in format "lat lon"') @main.command() @click.pass_context @click.option( "--latlon", "-l", callback=validate_latlon, help="Format: Latitude, Longitude", nargs=2, prompt="Enter decimal latitude and longitude ", ) def geo(ctx, latlon): url = f'{ctx.obj["BASE_URL"]}geo:{latlon}/' api_request(url, ctx.obj["TOKEN"]) def echo_header(location): leader_text = "Air quality information for " header_len = get_header_len(leader_text, location) click.echo() click.echo(f'{"-"*header_len}') click.echo(f"{leader_text}{location}") click.echo(f'{"-"*header_len}') def get_header_len(leader_text, location): leader_len = len(leader_text) location_len = len(location) return leader_len + location_len def echo_attributions(attribs): click.secho(f"With thanks to: ", fg="blue") click.echo(f'\t{attribs[-1]["name"]}') i = 0 while i < len(attribs) - 1: click.echo(f'\t{attribs[i]["name"]}') i += 1 click.echo() def echo_results(response): location = response["data"]["city"]["name"] aqi = response["data"]["aqi"] time = response["data"]["time"]["s"] tz = response["data"]["time"]["tz"] attribs = response["data"]["attributions"] quality, color = aqi_quality(aqi) echo_header(location) click.secho(f"The air quality is: ", fg="blue", nl=False) click.secho(f"{quality}", fg=color, blink=True) click.secho(f"The AQI is: ", fg="blue", nl=False) click.echo(f"{aqi}") click.secho(f"Updated: ", fg="blue", nl=False) click.echo(f"{time} {tz}") echo_attributions(attribs) def api_request(url, payload): r = requests.get(url, params=payload) response = r.json() echo_results(response) def aqi_quality(aqi): if aqi < 50: return "Good", "green" if aqi < 100: return "Moderate", "bright_yellow" if aqi < 150: return "Unhealthy for sensitive groups", "yellow" if aqi < 200: return "Unhealthy", "red" if aqi < 300: return "Very unhealthy", "bright_magenta" else: return "Hazardous", "magenta" danoscarmike-aqipy-73f8681/install.sh000066400000000000000000000000221372104174700175650ustar00rootroot00000000000000pip3 install -e . danoscarmike-aqipy-73f8681/setup.py000066400000000000000000000013221372104174700173010ustar00rootroot00000000000000from setuptools import setup with open("README.md", "r") as fh: long_description = fh.read() setup( name="aqipy", version="0.4.0", author="Dan O'Meara", author_email="omeara.dan@gmail.com", description="A simple CLI to get live Air Quality Indices", long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/danoscarmike/aqipy", packages=["aqipy"], entry_points={"console_scripts": ["aqipy = aqipy.__main__:main"]}, install_requires=["click", "requests",], classifiers=[ "Programming Language :: Python :: 3", "Development Status :: 3 - Alpha", "License :: OSI Approved :: MIT License", ], ) danoscarmike-aqipy-73f8681/uninstall.sh000066400000000000000000000000251372104174700201330ustar00rootroot00000000000000pip3 uninstall aqipy