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##############################################################################################################
|
#Functions##############################################################################################################
|
||||||
|
|
||||||
#move to pihole
|
#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() {
|
statsUpdateJSON() {
|
||||||
if [[ -z "${AdminLink}" ]] ; then
|
if [[ -z "${AdminLink}" ]] ; then
|
||||||
AdminLink="http://127.0.0.1/admin"
|
AdminLink="http://127.0.0.1/admin"
|
||||||
fi
|
fi
|
||||||
local x=$(curl -s ${AdminLink}/api.php?summaryRaw)
|
local x=$(curl -s ${AdminLink}/api.php?summaryRaw)
|
||||||
#check if json is valid
|
#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}"
|
echo "${x}"
|
||||||
else
|
else
|
||||||
echo "Error"
|
echo "Error"
|
||||||
|
@ -39,8 +33,7 @@ statsBlockedDomains() {
|
||||||
json=$(statsUpdateJSON)
|
json=$(statsUpdateJSON)
|
||||||
fi
|
fi
|
||||||
if [[ "${json}" != "Error" ]] ; then
|
if [[ "${json}" != "Error" ]] ; then
|
||||||
# local x=$(echo "${json}" | python -c "import sys, json; print json.load(sys.stdin)['domains_being_blocked']")
|
local x=$(python -c "import sys, json;print(json.loads('${json}')['domains_being_blocked'])")
|
||||||
local x=$(echo "${json}" | /opt/pihole/jq ".domains_being_blocked" | tr -d '"')
|
|
||||||
echo ${x}
|
echo ${x}
|
||||||
else
|
else
|
||||||
echo "Error"
|
echo "Error"
|
||||||
|
@ -53,7 +46,7 @@ statsQueriesToday() {
|
||||||
json=$(statsUpdateJSON)
|
json=$(statsUpdateJSON)
|
||||||
fi
|
fi
|
||||||
if [[ "${json}" != "Error" ]] ; then
|
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}
|
echo ${x}
|
||||||
else
|
else
|
||||||
echo "Error"
|
echo "Error"
|
||||||
|
@ -66,7 +59,7 @@ statsBlockedToday() {
|
||||||
json=$(statsUpdateJSON)
|
json=$(statsUpdateJSON)
|
||||||
fi
|
fi
|
||||||
if [[ "${json}" != "Error" ]] ; then
|
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}
|
echo ${x}
|
||||||
else
|
else
|
||||||
echo "Error"
|
echo "Error"
|
||||||
|
@ -79,7 +72,7 @@ statsPercentBlockedToday() {
|
||||||
json=$(statsUpdateJSON)
|
json=$(statsUpdateJSON)
|
||||||
fi
|
fi
|
||||||
if [[ "${json}" != "Error" ]] ; then
|
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}
|
echo ${x}
|
||||||
else
|
else
|
||||||
echo "Error"
|
echo "Error"
|
||||||
|
|
Loading…
Reference in a new issue