A universal watcher extendable for any kind of data.
Project description
Universal Watcher
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
Formatterclass, implementformat_itemsmethod.# 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
-
Create the Data Source Class: Inherit from
DataSourceand implement the required abstract methods. -
Add Formatters: Each data source can have multiple formatters. Create formatter classes inheriting from
Formatter. -
Register the Data Source: Place your data source in the
data_sourcespackage and ensure it's discoverable via thesetup.pyscript.
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
-
Create Formatter Class: Inherit from
Formatterand implement theformat_itemsmethod. -
Register Formatter: Add the formatter to the data source's
config.pyunder theFORMATTERSdictionary.
# 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
-
Create Notification Platform Class: Inherit from
NotificationPlatformand implement the required methods. -
Register the Notification Platform: Place your platform in the
notification_platformspackage and ensure it's discoverable via thesetup.pyscript.
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_HOSTSMTP_PORTSMTP_ENCRYPTIONSMTP_USERNAMESMTP_PASSWORDSMTP_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f66e2a0d5a66e84f68f46cbc59a4f26adfb8c88b36f664943970755dde82f28c
|
|
| MD5 |
0ad2c3baf990f2c1709b33d44bca43b5
|
|
| BLAKE2b-256 |
f74bbb74e90d2085640785e8e7cb531d5a02e7137dfe663479aabf80ce2b2476
|
Provenance
The following attestation bundles were made for universal_watcher-0.1.21.tar.gz:
Publisher:
release.yml on simon-ne/universal-watcher
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
universal_watcher-0.1.21.tar.gz -
Subject digest:
f66e2a0d5a66e84f68f46cbc59a4f26adfb8c88b36f664943970755dde82f28c - Sigstore transparency entry: 453838221
- Sigstore integration time:
-
Permalink:
simon-ne/universal-watcher@0c4178a831bec3899921a1e9365c1598e5e902d9 -
Branch / Tag:
refs/tags/v0.1.21 - Owner: https://github.com/simon-ne
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0c4178a831bec3899921a1e9365c1598e5e902d9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file universal_watcher-0.1.21-py3-none-any.whl.
File metadata
- Download URL: universal_watcher-0.1.21-py3-none-any.whl
- Upload date:
- Size: 36.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88ee62751b2c213e93e0c8893cf039029126af7b4c61d4e787ef2bcef1ad0042
|
|
| MD5 |
5593d5538269baff9a6161325306c7d5
|
|
| BLAKE2b-256 |
dadaceba01dcd36e703b4062dc7b6a6c2fab19ae9b0f50b96222b2a65c0daac3
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
universal_watcher-0.1.21-py3-none-any.whl -
Subject digest:
88ee62751b2c213e93e0c8893cf039029126af7b4c61d4e787ef2bcef1ad0042 - Sigstore transparency entry: 453838223
- Sigstore integration time:
-
Permalink:
simon-ne/universal-watcher@0c4178a831bec3899921a1e9365c1598e5e902d9 -
Branch / Tag:
refs/tags/v0.1.21 - Owner: https://github.com/simon-ne
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@0c4178a831bec3899921a1e9365c1598e5e902d9 -
Trigger Event:
push
-
Statement type: