mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2025-12-11 18:45:34 +00:00
Some checks failed
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Build distribution 📦 (push) Has been cancelled
ChangeDetection.io App Test / lint-code (push) Has been cancelled
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Test the built 📦 package works basically. (push) Has been cancelled
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Publish Python 🐍 distribution 📦 to PyPI (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-10 (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-11 (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-12 (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-13 (push) Has been cancelled
52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
import pluggy
|
|
from price_parser import Price
|
|
from loguru import logger
|
|
|
|
hookimpl = pluggy.HookimplMarker("changedetectionio_conditions")
|
|
|
|
|
|
@hookimpl
|
|
def register_operators():
|
|
def starts_with(_, text, prefix):
|
|
return text.lower().strip().startswith(prefix.lower())
|
|
|
|
def ends_with(_, text, suffix):
|
|
return text.lower().strip().endswith(suffix.lower())
|
|
|
|
return {
|
|
"starts_with": starts_with,
|
|
"ends_with": ends_with
|
|
}
|
|
|
|
@hookimpl
|
|
def register_operator_choices():
|
|
return [
|
|
("starts_with", "Text Starts With"),
|
|
("ends_with", "Text Ends With"),
|
|
]
|
|
|
|
@hookimpl
|
|
def register_field_choices():
|
|
return [
|
|
("extracted_number", "Extracted number after 'Filters & Triggers'"),
|
|
# ("meta_description", "Meta Description"),
|
|
# ("meta_keywords", "Meta Keywords"),
|
|
("page_filtered_text", "Page text after 'Filters & Triggers'"),
|
|
("page_title", "Page <title>"), # actual page title <title>
|
|
]
|
|
|
|
@hookimpl
|
|
def add_data(current_watch_uuid, application_datastruct, ephemeral_data):
|
|
|
|
res = {}
|
|
if 'text' in ephemeral_data:
|
|
res['page_text'] = ephemeral_data['text']
|
|
|
|
# Better to not wrap this in try/except so that the UI can see any errors
|
|
price = Price.fromstring(ephemeral_data.get('text'))
|
|
if price and price.amount != None:
|
|
res['extracted_number'] = float(price.amount)
|
|
logger.debug(f"Extracted price result: '{price}' - returning float({res['extracted_number']})")
|
|
|
|
return res
|