Skip to content

Instantly share code, notes, and snippets.

@jpwsutton
Created April 22, 2016 09:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpwsutton/e3ee240b24b0b63ea44cf26f39944bfa to your computer and use it in GitHub Desktop.
Save jpwsutton/e3ee240b24b0b63ea44cf26f39944bfa to your computer and use it in GitHub Desktop.
Get Growl Notifications following a UK Gov petition

For those of us in the UK, there are occasionally some interesting petitions that are started on the UK Government petitions website: https://petition.parliament.uk/

If you want to keep an eye on it without going to the page and clicking refresh once a day, you can easily set up a Node-Red flow to follow the number of signatures on the petition.

In this flow, I'm using the growl node to get notifications on my Ubuntu desktop, but you could quite easily substitute it for a PushBullet / Pushover / MQTT node as well!

[{"id":"7f1d4170.ba2e4","type":"inject","z":"17e6be9f.7c0251","name":"Trigger Check","topic":"","payload":"true","payloadType":"bool","repeat":"120","crontab":"","once":false,"x":168.5,"y":60,"wires":[["12bca2b4.3f6e8d"]]},{"id":"12bca2b4.3f6e8d","type":"http request","z":"17e6be9f.7c0251","name":"Get Petition JSON","method":"GET","ret":"txt","url":"https://petition.parliament.uk/petitions/126512.json","x":365.5,"y":60,"wires":[["e5d8f88d.05fef8"]]},{"id":"e5d8f88d.05fef8","type":"json","z":"17e6be9f.7c0251","name":"","x":530,"y":60,"wires":[["bb109835.b29338"]]},{"id":"d9465227.8cfcd","type":"notify","z":"17e6be9f.7c0251","title":"Petition Signatures","name":"Petition Signatures","x":907.5,"y":60,"wires":[]},{"id":"bb109835.b29338","type":"function","z":"17e6be9f.7c0251","name":"Create Message","func":"var count = msg.payload.data.attributes[\"signature_count\"];\nmsg.payload = \"There have been \" + count + \" signatures so far!\";\n\nreturn msg;","outputs":1,"noerr":0,"x":700,"y":60,"wires":[["d9465227.8cfcd"]]}]
@TotallyInformation
Copy link

https://petition.parliament.uk/petitions.json gets the first page of the list of petitions. Add the query params: page=n to get specific pages. The JSON contains links to the next and last page & links to each individual petition.

You can also use the query param state=xxxx so: https://petition.parliament.uk/petitions.json?state=open gives a list of open petitions. Cant see a way to change the sort order which appears to be number of votes descending.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment