This is a very, very dirty way of turning ChangeDetection.io's price-mode output, which is JSON, into a more friendly markdown format. Using Jinja2, which is currently lacking a from_json
function, we replace parts of the JSON output to form a markdown message. This will only work correctly as long as ChangeDetection.io's price-mode override JSON format stays EXACTLY the same. Any non HTTP 200 response might trigger such a change in which case a malformed message might be produced and send. Not something that could (should) "break" your ChangeDetection.io or notification service. Which is Gotify in this example gist. Tested with Tweakers.net Pricewatch product pages.
Some Product has changed!
- Lowest: 235.67 → 235.65
- Highest: 482.57
- Sellers: 33
- Currency: EUR
https://tracking-and-comparing-web.site/some-product.html
A malformed message will be send out when either lowPrice + highPrice
, highPrice + offerCount
or offerCount + priceCurrency
changes at the same time. This is due to the implementation of jsdiff. A working solution for this problem has currently not yet been found.
gotify://HOSTNAME/TOKEN?format=markdown&priority=moderate
Pricewatch update
**[{{watch_title}}]({{diff_url}})** has changed!
{{diff_full|replace("\n", "\n- ")|replace(",\n", "\n")|replace("{\n", "")|replace("\n- }", "")|replace("(changed) ", "")|replace("\n- (into) ", " -> ")|replace('- "@type": "AggregateOffer"\n', '')|replace(' "lowPrice": ', 'Lowest: ')|replace(' "highPrice": ', 'Highest: ')|replace(' "offerCount": ', 'Sellers: ')|replace(' "priceCurrency": ', 'Currency: ')|replace(" -> Lowest: ", " -> ")|replace(" -> Highest: ", " -> ")|replace(" -> Sellers: ", " -> ")|replace(" -> Currency: ", " -> ")|replace(" -> ", " → ")|replace('"', '')|truncate(32768)}}
*[{{watch_url}}]({{watch_url}})*
Line 2 explanation:
{{
# Use the full differential result
diff_full
# Place list item after every newline (all except the first line)
|replace("\n", "\n- ")
# Remove all commas before newlines
|replace(",\n", "\n")
# Remove JSON opening tag (the first line)
|replace("{\n", "")
# Remove JSON closing tag
|replace("\n- }", "")
# Remove changed-prefix
|replace("(changed) ", "")
# Turn into-prefix, including the leading newline, into arrow
|replace("\n- (into) ", " -> ")
# Remove "@type" line
|replace('- "@type": "AggregateOffer"\n', '')
# Change key names to friendly names
|replace(' "lowPrice": ', 'Lowest: ' )
|replace(' "highPrice": ', 'Highest: ' )
|replace(' "offerCount": ', 'Sellers: ' )
|replace(' "priceCurrency": ', 'Currency: ')
# Remove key names for changed values
|replace(" -> Lowest: ", " -> ")
|replace(" -> Highest: ", " -> ")
|replace(" -> Sellers: ", " -> ")
|replace(" -> Currency: ", " -> ")
# Turn "->" into character
|replace(" -> ", " → ")
# Remove quotes
|replace('"', '')
# Truncate lenght
|truncate(32768)
}}
Markdown