forked from mendhak/waveshare-epaper-display
-
Notifications
You must be signed in to change notification settings - Fork 0
/
screen-pihole-get.py
48 lines (34 loc) · 1.2 KB
/
screen-pihole-get.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python
import json
import requests
from xml.dom import minidom
import datetime
import codecs
import os.path
import time
import sys
import os
import html
template = 'screen-output-weather.svg'
pihole_address=os.getenv("PIHOLE_ADDR","")
if pihole_address=="":
print("PIHOLE_ADDR is missing")
sys.exit(1)
if sys.argv[1] == "hide":
print("Hiding pihole data")
output = codecs.open(template , 'r', encoding='utf-8').read()
output = output.replace('PIHOLE_DISPLAY_VALUE', "none")
codecs.open('screen-output-weather.svg', 'w', encoding='utf-8').write(output)
sys.exit(0)
url= "http://" + pihole_address + "/admin/api.php"
pihole_json = requests.get(url).json()
ads_blocked = pihole_json['ads_blocked_today']
dns_queries = pihole_json['dns_queries_today']
print("Pihole stats")
print(ads_blocked, dns_queries)
# Process the SVG
output = codecs.open(template , 'r', encoding='utf-8').read()
#output = output.replace('ICON_ONE',icon_dict[icon_one])
output = output.replace('PIHOLE_ADS_BLOCKED', str(ads_blocked) + " blocked")
output = output.replace('PIHOLE_DNS_QUERIES', str(dns_queries) + " queries")
codecs.open('screen-output-weather.svg', 'w', encoding='utf-8').write(output)