Skip to content

Instantly share code, notes, and snippets.

@WayneKeenan
Created October 20, 2017 16:46
Show Gist options
  • Save WayneKeenan/67fa462c5a0b1d57335efa59024c930f to your computer and use it in GitHub Desktop.
Save WayneKeenan/67fa462c5a0b1d57335efa59024c930f to your computer and use it in GitHub Desktop.
import re
import json
import requests
from pprint import pformat
from time import sleep
from gpiozero import Energenie
lamp = Energenie(1)
QUERY_URL='https://www.govtrack.us/api/v2/role?current=true&role_type=president'
while True:
response = requests.get(QUERY_URL)
json_data = json.loads(response.text)
print(pformat(json_data))
name = json_data['objects'][-1]['person']['name']
if re.findall(r'Trump', name):
print("lights off")
lamp.off()
else:
print("lights on")
lamp.on()
sleep(60) # check often, a change could happen anytime.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment