Skip to main content

E-REDES Scraper

Description

This is a web scraper that collects data from the E-REDES website and can upload it to a database. Since there is no exposed programatic interface to the data, this web scraper was developed as approach to collect it. A high-level of the process is:

  1. The scraper collects the data from the E-REDES website.
  2. A file with the energy consumption readings is downloaded.
  3. [ Optional ] The file is parsed and the data is uploaded to the selected database.
  4. [ Optional ] A feature supporting only the insertion of "deltas" is available.

This package supports E-REDES website available at time of writing 14/06/2023. The entrypoint for the scraper is the page https://balcaodigital.e-redes.pt/consumptions/history.

Installation

The package can be installed using pip:

pip install eredesscraper

Configuration

Usage is based on a YAML configuration file.
config.yml holds the credentials for the E-REDES website and the database connection. Currently, only InfluxDB is supported as a database sink.

Template config.yml:

eredes:
  # eredes credentials
  nif: <my-eredes-nif>
  pwd: <my-eredes-password>
  # CPE to monitor. e.g. PT00############04TW (where # is a digit). CPE can be found in your bill details
  cpe: PT00############04TW


influxdb:
  # url to InfluxDB.  e.g. http://localhost or https://influxdb.my-domain.com
  host: http://localhost
  # default port is 8086
  port: 8086
  bucket: <my-influx-bucket>
  org: <my-influx-org>
  # access token with write access
  token: <token>

Usage

CLI:

ers config load "/path/to/config.yml"

# get current month readings
ers run -d influxdb

# get only deltas from last month readings 
ers run -w previous -d influxdb --delta

# get readings from May 2023
ers run -w select -d influxdb -m 5 -y 2023

# start an API server
ers server -H "localhost" -p 8778 --reload -S <path/to/database>

API:

For more details refer to the OpenAPI documentation or the UI endpoints available at http://<host>:<port>/docs and http://<host>:<port>/redoc

# main methods:

# load an ers configuration 
# different options to load available:
# - directly in the request body,
# - download remote file,
# - upload local file
curl -X 'POST' \
  'http://localhost:8778/config/upload' \
  -H 'Content-Type: multipart/form-data' \
  -F 'file=@my-config.yml'


# run sync workflow
curl -X 'POST' \
  'http://localhost:8778/run' \
  -H 'Content-Type: application/json' \
  -d '{
  "workflow": "current"
}'

# run async workflow
curl -X 'POST' \
  'http://localhost:8778/run_async' \
  -H 'Content-Type: application/json' \
  -d '{
  "workflow": "select",
  "db": [
    "influxdb"
  ],
  "month": 5,
  "year": 2023,
  "delta": true,
  "download": true
}'

# get task status (`task_id` returned in /run_async response body)
curl -X 'GET' \
  'http://localhost:8778/status/<task_id>'

# download the file retrieved by the workflow
curl -X 'GET' \
  'http://localhost:8778/download/<task_id>'

Python:

from eredesscraper.workflows import switchboard
from pathlib import Path

# get deltas from current month readings
switchboard(config_path=Path("./config.yml"),
            name="current",
            db=list("influxdb"),
            delta=True,
            keep=True)

# get readings from May 2023
switchboard(config_path=Path("./config.yml"),
            name="select",
            db=list("influxdb"),
            month=5,
            year=2023)

Features

Available workflows:

  • current: Collects the current month consumption.
  • previous: Collects the previous month consumption data.
  • select: Collects the consumption data from an arbitrary month parsed by the user.

Available databases:

Roadmap

  • Add workflow for retrieving previous month data.
  • Add workflow for retrieving data form an arbitrary month.
  • Build CLI.
  • Build API
  • Containerize app.
  • Documentation.
  • Add CI/CD.
  • Add logging.
  • Add tests (limited coverage).
  • Add runtime support for multiple CPEs.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

See LICENSE file.

Metadata

Release files for eredesscraper 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for eredesscraper 1.0.1
File Size Uploaded Provenance
eredesscraper-1.0.1.tar.gz 55.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for eredesscraper 1.0.1
File Interpreter ABI Platform
eredesscraper-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 93.0 kB

Release files / eredesscraper-1.0.1.tar.gz

Download URL eredesscraper-1.0.1.tar.gz
Size 55.4 kB
Tags Source
SHA-256 checksum
How to use checksums
925766b4b61b4209ede298f5d502ed01f4bea08d3972bdcc5e806f96df3a6b77
BLAKE2b-256 checksum
How to use checksums
c7480f158adba4dad4f39ce566d1d4834288006dd956c342a47ff98988823acb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via poetry/1.8.3 CPython/3.11.9 Linux/6.5.0-1021-azure

Release files / eredesscraper-1.0.1-py3-none-any.whl

Download URL eredesscraper-1.0.1-py3-none-any.whl
Size 37.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ebf1299da2f4018559923040ee4d31ef7cd4de8fb8a459a79d6a735a839b579c
BLAKE2b-256 checksum
How to use checksums
9de0378ed3ae0a50e0716e2314c71182a7d4afcae28e24b6532c69acd76f6983
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via poetry/1.8.3 CPython/3.11.9 Linux/6.5.0-1021-azure

Security for eredesscraper 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page