Last active
September 9, 2018 09:32
-
-
Save jeroenboumans/23c09b271b6b14ec8ecee504ebe1b359 to your computer and use it in GitHub Desktop.
Pihole-Counter for Pimononi LED Phat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # run command `$crontab -e` and add command below | |
| 0,30 * * * * /home/pi/webrequest.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| python /home/pi/webrequest.py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment