Skip to main content

A universal watcher extendable for any kind of data.

Project description

Universal Watcher

License Python

Universal Watcher is a versatile and extendable Python package designed to monitor various data sources and notify users about new data through multiple notification platforms. Easily add support for new data sources and notification methods without modifying the core package.

Table of Contents

Installation

Install via pip:

pip install universal_watcher

Or install from source:

git clone https://github.com/simon-ne/universal-watcher.git
cd universal-watcher
pip install .

Usage

Universal Watcher provides methods to create new watchers, check existing watchers for new data, and check all watchers at once.

Creating a Watcher

To create a new watcher, define the data source and notification platform parameters and register the watcher in the database. This setup allows you to monitor specific data sources and receive notifications through your chosen platforms.

from universal_watcher import Watcher

watcher = Watcher()
watcher.create(
    watcher_name="my_watcher",
    data_source_data={
        "name": "bazos_sk",
        "formatter": "email_formatter",
        "parameters": {
            "category": "auto",
            "location": "12345",
            "search": "sedan",
            "min_price": 5000,
            "max_price": 20000,
            "radius": 50
        }
    },
    notification_platform_data={
        "name": "email",
        "parameters": {
            "to": "recipient@example.com"
        }
    }
)

Checking Watchers

  • Check a Specific Watcher: Looks for new data and notifies the user if any new items are found.

    watcher.check("my_watcher")
    
  • Check All Watchers: Iterates through all registered watchers, checking for new data and sending notifications as needed.

    watcher.check_all()
    

Using a Custom Formatter

  • Create a custom formatter: Inherit from Formatter class, implement format_items method.

    # your_formatter.py
    from universal_watcher.core.classes.formatter.formatter import Formatter
    from universal_watcher.core.classes.data_source.data_source_item import (
        DataSourceItem,
    )
    from universal_watcher.core.classes.notification_platform.notification_platform_input import (
        NotificationPlatformInput,
    )
    
    
    class YourCustomFormatter(Formatter):
        def format_items(
            self, items: list[DataSourceItem]
        ) -> NotificationPlatformInput:
            # Implement formatting logic
            pass
    
  • Use the custom formatter: Instead of using watcher.check() method, do the following.

    # main.py
    from universal_watcher import Watcher
    from your_formatter import YourCustomFormatter
    
    watcher = Watcher()
    new_items = watcher.get_new_data(watcher_name)
    notif_input = YourCustomFormatter().format_items(new_items)
    watcher.send_notification(watcher_name, notif_input)
    

Extending Universal Watcher

Universal Watcher is designed to be easily extensible. You can add new data sources, formatters, and notification platforms without altering the core package.

Adding a New Data Source

  1. Create the Data Source Class: Inherit from DataSource and implement the required abstract methods.

  2. Add Formatters: Each data source can have multiple formatters. Create formatter classes inheriting from Formatter.

  3. Register the Data Source: Place your data source in the data_sources package and ensure it's discoverable via the setup.py script.

Example Structure:

universal_watcher/
  data_sources/
    your_data_source/
      __init__.py
      your_data_source.py
      formatters/
        your_formatter.py
      models/
        your_item.py
      services/
        your_service.py

Adding a New Formatter

  1. Create Formatter Class: Inherit from Formatter and implement the format_items method.

  2. Register Formatter: Add the formatter to the data source's config.py under the FORMATTERS dictionary.

# your_formatter.py
from universal_watcher.core.classes.formatter.formatter import Formatter

class YourFormatter(Formatter):
    def format_items(self, items):
        # Implement formatting logic
        pass
# config.py
from .your_formatter import YourFormatter

FORMATTERS = {
    'your_formatter': YourFormatter
}

Adding a New Notification Platform

  1. Create Notification Platform Class: Inherit from NotificationPlatform and implement the required methods.

  2. Register the Notification Platform: Place your platform in the notification_platforms package and ensure it's discoverable via the setup.py script.

Example Structure:

universal_watcher/
  notification_platforms/
    your_platform/
      __init__.py
      your_platform.py
      models/
        your_input.py
      services/
        your_service.py

Configuration

Use environment variables to manage sensitive configurations such as SMTP credentials. This ensures that sensitive information is not hard-coded and can be easily managed across different environments.

Example Environment Variables for Email Notification Platform:

  • SMTP_HOST
  • SMTP_PORT
  • SMTP_ENCRYPTION
  • SMTP_USERNAME
  • SMTP_PASSWORD
  • SMTP_SENDER_EMAIL

You can set these variables in your environment or use a .env file. Ensure that your environment variables are loaded before running the application.

Contributing

Contributions are welcome! Please open issues or submit pull requests for enhancements or bug fixes.

License

This project is licensed under the MIT 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

universal_watcher-0.1.21.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

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

universal_watcher-0.1.21-py3-none-any.whl (36.2 kB view details)

Uploaded Python 3

File details

Details for the file universal_watcher-0.1.21.tar.gz.

File metadata

  • Download URL: universal_watcher-0.1.21.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for universal_watcher-0.1.21.tar.gz
Algorithm Hash digest
SHA256 f66e2a0d5a66e84f68f46cbc59a4f26adfb8c88b36f664943970755dde82f28c
MD5 0ad2c3baf990f2c1709b33d44bca43b5
BLAKE2b-256 f74bbb74e90d2085640785e8e7cb531d5a02e7137dfe663479aabf80ce2b2476

See more details on using hashes here.

Provenance

The following attestation bundles were made for universal_watcher-0.1.21.tar.gz:

Publisher: release.yml on simon-ne/universal-watcher

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file universal_watcher-0.1.21-py3-none-any.whl.

File metadata

File hashes

Hashes for universal_watcher-0.1.21-py3-none-any.whl
Algorithm Hash digest
SHA256 88ee62751b2c213e93e0c8893cf039029126af7b4c61d4e787ef2bcef1ad0042
MD5 5593d5538269baff9a6161325306c7d5
BLAKE2b-256 dadaceba01dcd36e703b4062dc7b6a6c2fab19ae9b0f50b96222b2a65c0daac3

See more details on using hashes here.

Provenance

The following attestation bundles were made for universal_watcher-0.1.21-py3-none-any.whl:

Publisher: release.yml on simon-ne/universal-watcher

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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