mirror of
https://github.com/pi-hole/pi-hole.git
synced 2024-11-28 17:13:17 +00:00
back to python works with 2 and 3
This commit is contained in:
parent
33285d8d8c
commit
40fdaea099
1 changed files with 5 additions and 12 deletions
|
@ -14,19 +14,13 @@
|
|||
#Functions##############################################################################################################
|
||||
|
||||
#move to pihole
|
||||
|
||||
if [ ! -f "/opt/pihole/jq" ] ; then
|
||||
curl -s http://stedolan.github.io/jq/download/linux64/jq -o /opt/pihole/jq
|
||||
chmod 755 /opt/pihole/jq
|
||||
fi
|
||||
|
||||
statsUpdateJSON() {
|
||||
if [[ -z "${AdminLink}" ]] ; then
|
||||
AdminLink="http://127.0.0.1/admin"
|
||||
fi
|
||||
local x=$(curl -s ${AdminLink}/api.php?summaryRaw)
|
||||
#check if json is valid
|
||||
if echo "${x}" | /opt/pihole/jq "." > /dev/null ; then
|
||||
if python -c "import sys, json;json.loads('${x}')" ; then
|
||||
echo "${x}"
|
||||
else
|
||||
echo "Error"
|
||||
|
@ -39,8 +33,7 @@ statsBlockedDomains() {
|
|||
json=$(statsUpdateJSON)
|
||||
fi
|
||||
if [[ "${json}" != "Error" ]] ; then
|
||||
# local x=$(echo "${json}" | python -c "import sys, json; print json.load(sys.stdin)['domains_being_blocked']")
|
||||
local x=$(echo "${json}" | /opt/pihole/jq ".domains_being_blocked" | tr -d '"')
|
||||
local x=$(python -c "import sys, json;print(json.loads('${json}')['domains_being_blocked'])")
|
||||
echo ${x}
|
||||
else
|
||||
echo "Error"
|
||||
|
@ -53,7 +46,7 @@ statsQueriesToday() {
|
|||
json=$(statsUpdateJSON)
|
||||
fi
|
||||
if [[ "${json}" != "Error" ]] ; then
|
||||
local x=$(echo "${json}" | /opt/pihole/jq ".dns_queries_today" | tr -d '"')
|
||||
local x=$(python -c "import sys, json;print(json.loads('${json}')['dns_queries_today'])")
|
||||
echo ${x}
|
||||
else
|
||||
echo "Error"
|
||||
|
@ -66,7 +59,7 @@ statsBlockedToday() {
|
|||
json=$(statsUpdateJSON)
|
||||
fi
|
||||
if [[ "${json}" != "Error" ]] ; then
|
||||
local x=$(echo "${json}" | /opt/pihole/jq ".ads_blocked_today" | tr -d '"')
|
||||
local x=$(python -c "import sys, json;print(json.loads('${json}')['ads_blocked_today'])")
|
||||
echo ${x}
|
||||
else
|
||||
echo "Error"
|
||||
|
@ -79,7 +72,7 @@ statsPercentBlockedToday() {
|
|||
json=$(statsUpdateJSON)
|
||||
fi
|
||||
if [[ "${json}" != "Error" ]] ; then
|
||||
local x=$(echo "${json}" | /opt/pihole/jq ".ads_percentage_today" | tr -d '"' | xargs printf "%.*f\n" 2)
|
||||
local x=$(python -c "import sys, json;print(round(float(json.loads('${json}')['ads_percentage_today']), 2))")
|
||||
echo ${x}
|
||||
else
|
||||
echo "Error"
|
||||
|
|
Loading…
Reference in a new issue