diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e48ae2f..161f34e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,9 +18,9 @@ jobs: - uses: docker/setup-buildx-action@v2.5.0 - name: Build the Docker image env: - PAS_SENSOR_IDS: ${{ secrets.PAS_SENSOR_IDS }} - PAS_API_READ_KEY: ${{ secrets.PAS_API_READ_KEY }} - run: docker build . --file Dockerfile --tag purpleair_scraper:$(date +%s) + PAE_SENSOR_IDS: ${{ secrets.PAE_SENSOR_IDS }} + PAE_API_READ_KEY: ${{ secrets.PAE_API_READ_KEY }} + run: docker build . --file Dockerfile -t purpleair_exporter:$(date +%s) - uses: docker/build-push-action@v4.0.0 with: diff --git a/.github/workflows/build_and_publish.yml b/.github/workflows/build_and_publish.yml index 0dafd14..7f00127 100644 --- a/.github/workflows/build_and_publish.yml +++ b/.github/workflows/build_and_publish.yml @@ -16,8 +16,8 @@ jobs: id: docker_meta with: images: | - nirajsanghvi/purpleair_scraper - ghcr.io/nirajsanghvi/purpleair_scraper + nirajsanghvi/purpleair_exporter + ghcr.io/nirajsanghvi/purpleair_exporter tags: | type=semver,pattern={{version}} @@ -38,6 +38,6 @@ jobs: with: build-args: --progress plain push: true - tags: ${{ steps.docker_meta.outputs.tags }}, nirajsanghvi/purpleair_scraper + tags: ${{ steps.docker_meta.outputs.tags }}, nirajsanghvi/purpleair_exporter labels: ${{ steps.docker_meta.outputs.labels }} platforms: linux/amd64,linux/arm64 diff --git a/Dockerfile b/Dockerfile index d60f601..7c10b24 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,9 +5,9 @@ LABEL maintainer="Niraj Sanghvi " ENV PYTHONUNBUFFERED 1 ENV PYTHONDONTWRITEBYTECODE 1 -ENV PAS_PROM_PORT 9101 -ENV PAS_LOGGING info -EXPOSE ${PAS_PROM_PORT} +ENV PAE_PROM_PORT 9101 +ENV PAE_LOGGING info +EXPOSE ${PAE_PROM_PORT} WORKDIR /app @@ -15,4 +15,4 @@ COPY root/ / RUN pip install -r /app/requirements.txt -CMD python /app/purpleair_scraper.py +CMD python /app/purpleair_exporter.py diff --git a/README.md b/README.md index 223dfcc..e86af57 100644 --- a/README.md +++ b/README.md @@ -16,14 +16,14 @@ Additionally, the AQI is computed for PM2.5 (both from the instant value and the ## Configuration The following environment variables are used by this script: -### `PAS_SENSOR_IDS` (required) +### `PAE_SENSOR_IDS` (required) A comma-separated list of sensor IDs to collect data from. Sensor IDs for public sensors can be found on the [PurpleAir map](https://map.purpleair.com) by clicking on the sensor and viewing the widget code, which should contain a 5 or 6-digit number representing the sensor. -### `PAS_API_READ_KEY` (required) +### `PAE_API_READ_KEY` (required) As a relatively new option, you can visit https://develop.purpleair.com/keys to generate API keys. This script only requires the READ key, not the WRITE one since it is only reading sensor data. Note: That website only offers a Google login option, so if you don't want to do that you might have luck trying the older method of simply sending an email to contact@purpleair.com with your first name, last name, and email address to assign them to. -### `PAS_LOGGING` +### `PAE_LOGGING` Log level of the script, defaults to 'info', accepts any [Python logging level name](https://docs.python.org/3/howto/logging.html#logging-levels) -### `PAS_PROM_PORT` +### `PAE_PROM_PORT` The port to run the Prometheus HTTP server on, defaults to 9101 diff --git a/root/app/purpleair_scraper.py b/root/app/purpleair_exporter.py similarity index 94% rename from root/app/purpleair_scraper.py rename to root/app/purpleair_exporter.py index 9ec1be1..d08aa8b 100644 --- a/root/app/purpleair_scraper.py +++ b/root/app/purpleair_exporter.py @@ -11,7 +11,7 @@ API_SENSOR_FIELDS = ["name","last_seen","pm2.5","pm2.5_10minute","pm10.0","temperature","pressure","humidity"] logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s") -logger = logging.getLogger("purpleair_scraper") +logger = logging.getLogger("purpleair_exporter") # Stats STAT_PREFIX = "purpleair_" @@ -47,27 +47,27 @@ def main() -> None: - log_level = os.environ.get("PAS_LOGGING", "info") - prom_port = int(os.environ.get("PAS_PROM_PORT", "9101")) + log_level = os.environ.get("PAE_LOGGING", "info") + prom_port = int(os.environ.get("PAE_PROM_PORT", "9101")) try: - run_interval_s = int(os.environ.get("PAS_RUN_INTERVAL_S", DEFAULT_RUN_INTERVAL_SECONDS)) + run_interval_s = int(os.environ.get("PAE_RUN_INTERVAL_S", DEFAULT_RUN_INTERVAL_SECONDS)) except ValueError: - logger.error(f"Invalid env var: PAS_RUN_INTERVAL_S must be an integer") + logger.error(f"Invalid env var: PAE_RUN_INTERVAL_S must be an integer") sys.exit(1) - if "PAS_SENSOR_IDS" not in os.environ or not os.environ["PAS_SENSOR_IDS"]: - logger.error(f"Missing env var: PAS_SENSOR_IDS") + if "PAE_SENSOR_IDS" not in os.environ or not os.environ["PAE_SENSOR_IDS"]: + logger.error(f"Missing env var: PAE_SENSOR_IDS") sys.exit(1) - api_key = os.environ.get("PAS_API_READ_KEY", "") + api_key = os.environ.get("PAE_API_READ_KEY", "") if api_key == "": - logger.error("Missing env var: PAS_API_READ_KEY") + logger.error("Missing env var: PAE_API_READ_KEY") sys.exit(1) validate_api_key(api_key) - sensor_ids = os.environ["PAS_SENSOR_IDS"].replace(" ", "") + sensor_ids = os.environ["PAE_SENSOR_IDS"].replace(" ", "") log_level = getattr(logging, log_level.upper()) logger.setLevel(log_level)