Skip to main content

Python library for scraping daily electricity prices from OTE (ote-cr.cz)

Project description

python-ote

Electricity prices scraper for OTE (ote-cr.cz)

Install

pip install python-ote

In order to parse numbers corrently (Czech notation - e.g. 1,000,000) this package needs the cs_CZ.UTF-8 system locale. If the OS doesn't have it by default the following commands can be used generate it:

echo "cs_CZ.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen

Usage

from ote import Ote
from dateutil import parser

# Create client
ote = Ote()

Use getDayMarketPrices(date_from, date_to) method to get electricity prices for the given time range. It accepts a date_from and optionally a date_to, both of which have to be a datetime.date object. If date_to is not specified the method returns data to today.

Examples:

# Get water consumption data from the specified date to now.
date_from = parser.parse('2020-08-01').date()
deferred_data = ote.getDayMarketPrices(date_from);

# Get water consumption data for a date interval
date_from = parser.parse('2020-08-01').date()
date_to = parser.parse('2020-08-11').date()
deferred_data = ote.getDayMarketPrices(date_from, date_to);

# Get water consumption data for a specific date (just 1 day)
date = parser.parse('2020-08-01').date()
deferred_data = ote.getDayMarketPrices(date, date);

You may call getDayMarketPrices multiple times with different parameters. It returns a twisted.internet.defer.Deferred object that can be used to retrieve the price data in the future using a callback you need to provide.

def process_prices(prices)
  print(prices)

deferred_data.addCallback(process_prices)

If you have multiple Deferreds from multiple calls to getDayMarketPrices you can use Ote.join() to get a Deferred that will be resolved after all crawlers are finished.

The last callback should stop the reactor so it's shut down cleanly. Reactor should be stopped after all crawlers are done so the join() method comes in handy. Note that the reactor cannot be restarted so make sure this is the last thing you do:

from twisted.internet import reactor

d = ote.join()
d.addBoth(lambda _: reactor.stop())

The last thing you need to do is run the reactor. The script will block until the crawling is finished and all configured callbacks executed.

reactor.run(installSignalHandlers=False)

This might look a bit daunting so please see test.py for a complete example.

Keep in mind the library is using Scrapy internally which means it is scraping the OTE website. If OTE comes to think you are abusing the website they may block your IP address.

License

See LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_ote-0.2.3.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_ote-0.2.3-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file python_ote-0.2.3.tar.gz.

File metadata

  • Download URL: python_ote-0.2.3.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for python_ote-0.2.3.tar.gz
Algorithm Hash digest
SHA256 6bb5f8db95cb721a079151f62f95f0d6ff605d8031e486d2f55097c402d06d57
MD5 16b815ab858fd2a9b9345d0e34090331
BLAKE2b-256 fcee549cafae8fdf0f3abcdfff482ab3f6763495933abffa3c55a43759f26914

See more details on using hashes here.

File details

Details for the file python_ote-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: python_ote-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for python_ote-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0ab6dc65c501c31223481659c91839ca3d0e331fe0b1d32d69a57c0f65cfbb83
MD5 48d54436ec62af0f65fb1661c42d6b53
BLAKE2b-256 30354145b7906baa57f0ecc8857c3e31023928aa98bd811399fc662d3583dda3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page