Skip to content

Commit

Permalink
Merge pull request #2 from nirajsanghvi/rename-to-exporter
Browse files Browse the repository at this point in the history
Rename from scraper to exporter, PAS to PAE
  • Loading branch information
nirajsanghvi authored Apr 17, 2023
2 parents be8fc80 + f5f06a2 commit febe2c8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -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
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ LABEL maintainer="Niraj Sanghvi <niraj.sanghvi@gmail.com>"
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

COPY root/ /

RUN pip install -r /app/requirements.txt

CMD python /app/purpleair_scraper.py
CMD python /app/purpleair_exporter.py
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 10 additions & 10 deletions root/app/purpleair_scraper.py → root/app/purpleair_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit febe2c8

Please sign in to comment.