Skip to content

Instantly share code, notes, and snippets.

@jeroenboumans
Last active September 9, 2018 09:32
Show Gist options
  • Select an option

  • Save jeroenboumans/23c09b271b6b14ec8ecee504ebe1b359 to your computer and use it in GitHub Desktop.

Select an option

Save jeroenboumans/23c09b271b6b14ec8ecee504ebe1b359 to your computer and use it in GitHub Desktop.
Pihole-Counter for Pimononi LED Phat
# run command `$crontab -e` and add command below
0,30 * * * * /home/pi/webrequest.sh
#!/usr/bin/env python
import datetime
import time
import requests
import json
import urllib2
from microdotphat import write_string, set_decimal, clear, show, draw_tiny
def internet_on():
try:
urllib2.urlopen('http://pihole-address:7000', timeout=1)
return True
except urllib2.URLError as err:
return False
print("Starting PiHole-counter for 15 minutes")
i = 0
while i<900:
if internet_on():
r = requests.get('http://pihole-address:7000/admin/api.php')
if r.text:
print("has response")
try:
json_data = r.json()
message = str(json_data['ads_blocked_today'])
except ValueError:
message = 'Error'
print("encountered an error")
clear()
write_string(message, kerning=False)
print(str(i))
show()
i += 1
time.sleep(2)
python /home/pi/webrequest.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment