-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to use our own plugins to scrape extra data
- Loading branch information
Showing
5 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pluggy | ||
from typing import Dict | ||
from changedetectionio.model import Watch as Watch | ||
|
||
plugin_namespace = "changedetectionio.restock_price_scraper" | ||
hookspec = pluggy.HookspecMarker(plugin_namespace) | ||
|
||
class HookSpec: | ||
@hookspec | ||
def scrape_price_restock(self, watch: Watch.model, html_content: str, screenshot: bytes, update_obj: Dict) -> Dict: | ||
""" | ||
Scrape price and restock data from html_content and/or screenshot and return via update_obj | ||
Args: | ||
watch (Watch.model): The watch object containing watch configuration. | ||
html_content (str): The HTML content to scrape. | ||
screenshot (bytes): The screenshot data. | ||
update_obj (Dict): The dictionary to update with scraped data. | ||
Returns: | ||
Optional[Dict]: The updated dictionary with the scraped price data, or None if no update is made. | ||
""" | ||
|
17 changes: 17 additions & 0 deletions
17
changedetectionio/processors/restock_diff/plugin_manager.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pluggy | ||
from .hookspecs import HookSpec | ||
import importlib.metadata | ||
|
||
# Define the plugin namespace | ||
plugin_namespace = "changedetectionio.restock_price_scraper" | ||
|
||
# Create a pluggy.PluginManager instance | ||
pm = pluggy.PluginManager(plugin_namespace) | ||
|
||
# Register the hook specifications | ||
pm.add_hookspecs(HookSpec) | ||
|
||
# Automatically discover and register plugins using entry points | ||
for entry_point in importlib.metadata.entry_points().get(plugin_namespace, []): | ||
plugin = entry_point.load() | ||
pm.register(plugin()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters