API parsing via Python (bitbar)


#1

@DL6ER

i am trying to add update notifications to my bitbar plugin, i have this, is it correct? will it say Update Available?

print("Core: %s (%s)" % (versions['core_current'],
                         versions['core_branch'])) + "| color=black"
if not versions['core_current']:
 print("Update available: %s" % versions['core_latest']) + "| color=red"
else:
 print("Up to date| color=green")

11%20AM


Expand API
#2

I don’t even know what language you wrote this in…


#3
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# <bitbar.title>Pi-hole status</bitbar.title>
# <bitbar.version>v3.2</bitbar.version>
# <bitbar.author>Felipe Martin</bitbar.author>
# <bitbar.author.github>fmartingr</bitbar.author.github>
# <bitbar.author>Siim Ots</bitbar.author>
# <bitbar.author.github>siimots</bitbar.author.github>
# <bitbar.desc>Show summary and manage Pi-Hole from menubar.</bitbar.desc>
# <bitbar.image>https://files.fmartingrlabs.com/github/bitbar-plugins/pihole.1m.png</bitbar.image>
# <bitbar.dependencies>pi-hole,python</bitbar.dependencies>
import json
import os
import urllib2

try:  # Python 3
    from urllib.request import urlopen
except ImportError:  # Python 2
    from urllib2 import urlopen  # noqa


PLUGIN_PATH = os.path.join(os.getcwd(), __file__)

# ---
# Variables
# ---

# URL to the pi-hole admin path without trailing slash
base_url = "http://pi-hole.local/admin"

# Your Pi-hole password hash (used for management)
# THIS IS NOT YOUR PIHOLE ADMIN PASSWORD
# You can find this password hash in the setupVars.conf file of your pihole
# server which is typically is found in /etc/pihole/setupVars.conf.
# Look for the PASSWORDHASH key.
password = ""

# Url to check the service status
url_status = "%s/api.php?status&auth=%s" % (base_url, password)

# Url to get the summary
url_summary = "%s/api.php?summary" % base_url

# Urls to enable/disable service
url_enable = "%s/api.php?enable&auth=%s" % (base_url, password)
url_disable = "%s/api.php?disable&auth=%s" % (base_url, password)

# Url to get versions
url_versions = "%s/api.php?versions" % base_url


# ---
# Helper methods
# ---
def convert_to_native(data):
    return json.loads(data)


def do_request(url, method='GET'):
    response = urlopen(url)
    return convert_to_native(response.read())


def get_summary():
    response = do_request(url_summary)
    return response


def get_status():
    response = do_request(url_status)
    return response['status']
    
def get_versions():
    response = do_request(url_versions)
    return response


def separator():
    print('---')


# Data
summary = get_summary()
versions = get_versions()
status = get_status()
enabled = status == 'enabled'

# Layout
def bitbar():
    # Menubar icon
    print "| image=iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAACXBIWXMAABYlAAAWJQFJUiTwAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzABhzBBdzBC/xgNoRCJMTCQhBCCmS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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAWBAAAAAAAAAAAAAAAAAAAAP8AAAL+AAAB/wAABwIAAOL8+wDP97sDDgO7CgUBAPTY+jEd4fpgLf0APQcGAPnV6P6u5t/7qfT0/eIAIAQAAWkTAAD1AAD/Af8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABPAAAAAAAAAAAAAAAAAAAAAAAAAf///wAAAAAAAAAAAAAAAAAAAAAAAWMSAAAAAAAAAAAAAAAAAAAAAAAAAf4AAAAAAAAOAgAAy/kAAMT2AAIAAABJAABPRwAAdWAAADsNAAAAAAAAAPwAAACrAADoeQAAfuEAAJsCAAAAAQAAAP0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////AAAAAAAAAAAAAAAAAAAAAAAA////AP///wD///8A////AP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAhM0AAP//AAD//wAA//8AAP//AAD//wAA//8AAP/YAAD/JgAAfwAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AAD///8A////AP///wD///8A////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADYAAIXqAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP+oAAD/DwAAegAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///wD///8A////AP///wD///8AAP///wD///8A////AP///wD///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAqAACB5QAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA/+wAAP+jAAD/MgAAcQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////AP///wD///8A////AP///wAA////AP///wD///8A////AP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALAAAf90AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD/4AAA/7gAAP/cAAD/JgAAbwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AAD///8A////AP///wD///8A////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADQAAHjdAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP/oAAD/kgAA/+wAAP/bAAD/JAAAawAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///wD///8A////AP///wD///8AAP///wD///8A////AP///wD///8AAAAAAAAAAAAAAAAAAAAAAAAAAAA2AAB14QAA//8AAP/6AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA/90AAP+UAAD/9gAA//8AAP/TAAD/HwAAXgAAAAADAAAAAQAAAAAAAAAAAAAA////AP///wD///8A////AP///wAA////AP///wD///8A////AP///wAAAAAAAAAAAAAAAAAAAAAADgAAbp8AAP/HAAD/mQAA/5cAAP++AAD/+QAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD/lgAA/5UAAP//AAD//wAA//8AAP/LAAD+IgAAVSAAAAAUAAAAAAAAAAAAAAD///8A////AP///wD///8A////AAD///8A////AP///wD///8A////AAAAAAAAAAAAAAAAAAgAAGyiAAD/6AAA/9UAAP/ZAAD/xQAA/3sAAP9PAAD/wwAA//8AAP//AAD//wAA//8AAP//AAD//wAA/8YAAP8/AAD/2wAA//8AAP//AAD//wAA//8AAP+9AAD6HwAATwkAAAAAAAAAAAAAAP///wD///8A////AP///wD///8AAP///wD///8A////AP///wD///8AAAAAAAAAAAAYAABcxQAA//8AAP//AAD//wAA//8AAP//AAD//wAA/44AAP8KAAD/dAAA/9sAAP//AAD//wAA//8AAP/AAAD/FQAA/5QAAP//AAD//wAA//8AAP//AAD//wAA//8AAP+oAADxBwAAPAAAAAAAAAAA////AP///wD///8A////AP///wAA////AP///wD///8A////AP///wAAAAAAAAAAG54AAOL/AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA/4YAAP8AAAD/EAAA/0IAAP9hAAD/QwAA/wAAAP9eAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP94AADKAAAAAAAAAAD///8A////AP///wD///8A////AAD///8A////AP///wD///8A////AAAAACwuAACI7AAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD/5QAA/yAAAP8AAAD/AAAA/wAAAP8AAAD/BQAA/9cAAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA/9sAAP0NAABVAAAAC////wD///8A////AP///wD///8AAP///wD///8A////AP///wD///8AGQAAiG0AAOX/AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP/9AAD/UAAA/wAAAP8AAAD/AAAA/wAAAP9IAAD/+QAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD/+gAA/0oAAM0DAABu////AP///wD///8A////AP///wACAAAAAAAAAAAAAAAAAAAAAAAAAAAJAAALCAAABwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPwAAAD4AAAAAAAAAAAAAAAAAAAAAAAAAB0AAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAEwAAIQcAACcAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAOAAALXPAAC++AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA5wAAAM4AAAAAAAAAAAAAAAAAAAAAAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPUAAADiAADI9gAAwwAAAAAAAAAAAAAAAAAAAAAAAAAAAP///wD///8A////AP///wD///8AAAAAAAIAADvSAADz/wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP+YAAD/AAAA/wgAAP8VAAD/CAAA/wAAAP8MAAD/2wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD/0gAA8wEAADsAAAAA////AP///wD///8A////AP///wAA////AP///wD///8A////AP///wAAAAAAAAAAAEkAAKH8AAD//wAA//8AAP//AAD//wAA//8AAP//AAD/1gAA/w8AAP9ZAAD/vQAA/9oAAP++AAD/gAAA/xAAAP87AAD/9AAA//8AAP//AAD//wAA//8AAP//AAD//wAA//wAAP9IAACeAAAAAAAAAAD///8A////AP///wD///8A////AAD///8A////AP///wD///8A////AAAAAAAAAAAAAAAAEnMAAL//AAD//wAA//8AAP//AAD//wAA//8AAP9JAAD/eAAA//8AAP//AAD//wAA//8AAP//AAD/5QAA/2AAAP9eAAD/1AAA//8AAP//AAD//wAA//8AAP/sAAD/VQAAugAAAA4AAAAAAAAAAP///wD///8A////AP///wD///8AAP///wD///8A////AP///wD///8AAAAAAAAAAAAAAAAAAAAAE3UAAMb/AAD//wAA//8AAP//AAD/oAAA/1kAAP/2AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA/78AAP+IAAD/mgAA/64AAP/GAAD/zAAA/zgAAMIAAAAPAAAAAAAAAAAAAAAA////AP///wD///8A////AP///wAA////AP///wD///8A////AP///wAAAAAAAAAAAAYAAAANAAAAAAAAF3cAAM//AAD//wAA//8AAP9/AAD/xwAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//gAAP/SAAD/xAAA//AAAP9kAADLAAAAFQAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AAD///8A////AP///wD///8A////AAAAAAAAAAAABAAAABUAAAAVAAAAAAAAHHIAAMr/AAD/4AAA/44AAP/rAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD/gAAAygkAABsJAAAAAAAAAAAAAAAAAAAAAAAAAP///wD///8A////AP///wD///8AAP///wD///8A////AP///wD///8AAAAAAAAAAAAEAAAAFAAAABYAAAATAAAAAAAAHIAAAMLzAAD/mAAA/+oAAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA/3cAAMYAAAAeHgAAAAkAAAAAAAAAAAAAAAAAAAAAAAAA////AP///wD///8A////AP///wAA////AP///wD///8A////AP///wAAAAAAAAAAAAQAAAAUAAAAFgAAABUAAAAMAAAAAQAAFHMAAMfFAAD/9QAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP9+AADNAAAAGREAAAAgAAAACQAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AAD///8A////AP///wD///8A////AAAAAAAAAAAABAAAABQAAAAWAAAAFAAAABQAAAANAAAADQAAF0QAAM/oAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD/hwAA2wMAAB0SAAAAGgAAACAAAAAJAAAAAAAAAAAAAAAAAAAAAAAAAP///wD///8A////AP///wD///8AAP///wD///8A////AP///wD///8AAAAAAAAAAAAEAAAAFAAAABYAAAAUAAAAEgAAABUAAAAiAAAAAAAAHV4AAMv/AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA/4cAANsMAAAnHgAAABkAAAAYAAAAIAAAAAkAAAAAAAAAAAAAAAAAAAAAAAAA////AP///wD///8A////AP///wAA////AP///wD///8A////AP///wAAAAAAAAAAAAQAAAAUAAAAFgAAABQAAAASAAAAFQAAACQAAAAKAAAAAAAAHGsAALz2AAD//wAA//8AAP//AAD//wAA//IAAP9tAAC/DAAAJyQAAAAfAAAAGQAAABgAAAAgAAAACQAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AAH///8AAAAAAAAAAAAAAAAAAAAAAAEBAQAAAAAABAAAABAAAAACAAAA/gAAAP4AAAADAAAADwAAAOcAAAD+AAAA9wAABioAAGtgAABeOQAAHPsAAP/BAADepQAAoNwAAJ4jAAD6AwAAAPkAAAD6AAAA/wAAAAgAAADpAAAA9wAAAAAAAAAAAAAAAAAAAP///wAAAAAAAAAAAAAAAAAAAAAAAQAA//8wabirP4J+hgAAAABJRU5ErkJggg=="
    separator()

    print("Open pi-hole admin UI | color=blue href=%s" % base_url)
    separator()

    print('Status: %s' % status) + "|  color=black"
    if enabled:
     print('Disable Pi-hole | color=red href=%s' % url_disable)
    else:
     print('Enable Pi-hole | color=green href=%s' % url_enable)
    separator()
    
    #print("Core: %s" % versions['core_current']) + "| color=black"
    print("Core: %s (%s)" % (versions['core_current'],
                             versions['core_branch'])) + "| color=black"
    if not versions['core_current']:
     print("Update available: %s" % versions['core_latest']) + "| color=red"
    else:
     print("Up to date| color=green")
    separator()
    #print("Web: %s" % versions['web_current']) + "| color=black"
    print("Web: %s (%s)" % (versions['web_current'],
                             versions['web_branch'])) + "| color=black"
    if not versions['web_current']:
     print("Update available: %s" % versions['web_latest']) + "| color=red"
    else:
     print("Up to date| color=green")
    separator()
    #print("FTL: %s" % versions['FTL_current']) + "| color=black"
    print("FTL: %s (%s)" % (versions['FTL_current'],
                             versions['FTL_branch'])) + "| color=black"
    if not versions['FTL_current']:
     print("Update available: %s" % versions['FTL_latest']) + "| color=red"
    else:
     print("Up to date| color=green")
    separator()
    
    print("Domains being blocked: %s" % summary['domains_being_blocked']) + "| color=black"
    print("Ads blocked today: %s (%s%%)" % (summary['ads_blocked_today'],
                                            summary['ads_percentage_today'])) + "| color=black"
    print("Unique domains today: %s" % summary['unique_domains']) + "| color=black"
    print("DNS queries today: %s" % summary['dns_queries_today']) + "| color=black"
    print("Queries cached today: %s" % summary['queries_cached']) + "| color=black"
    print("Queries forwarded today: %s" % summary['queries_forwarded']) + "| color=black"
    separator()
    print "Last Blocked Domain: | color=black"
    request = urllib2.Request(base_url + '/api.php?recentBlocked')
    response = urllib2.urlopen(request)
    html = response.read()
    print html + "| color=black"
    separator()

# Execution
try:
    bitbar()
except Exception as e:
    print('Script error:')
    print(e)
    separator()

#4

why not use

if not versions[‘web_current’] == versions[‘web_latest’]:

this way you’ll compare it to an actual variable


#5

because i didnt know any better, LOL


#6

i actually get invalid syntax with that


#7

I have little to no experience with Python but shouldnt it be:

if versions[‘web_current’] != versions[‘web_latest’]:

?


#8

In the above if condition, that would be the correct operator.


#9

still get invalid syntax, here is the complete code:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# <bitbar.title>Pi-hole status</bitbar.title>
# <bitbar.version>v3.2</bitbar.version>
# <bitbar.author>Felipe Martin</bitbar.author>
# <bitbar.author.github>fmartingr</bitbar.author.github>
# <bitbar.author>Siim Ots</bitbar.author>
# <bitbar.author.github>siimots</bitbar.author.github>
# <bitbar.desc>Show summary and manage Pi-Hole from menubar.</bitbar.desc>
# <bitbar.image>https://files.fmartingrlabs.com/github/bitbar-plugins/pihole.1m.png</bitbar.image>
# <bitbar.dependencies>pi-hole,python</bitbar.dependencies>
import json
import os
import urllib2

try:  # Python 3
    from urllib.request import urlopen
except ImportError:  # Python 2
    from urllib2 import urlopen  # noqa


PLUGIN_PATH = os.path.join(os.getcwd(), __file__)

# ---
# Variables
# ---

# URL to the pi-hole admin path without trailing slash
base_url = "http://pi-hole.local/admin"

# Your Pi-hole password hash (used for management)
# THIS IS NOT YOUR PIHOLE ADMIN PASSWORD
# You can find this password hash in the setupVars.conf file of your pihole
# server which is typically is found in /etc/pihole/setupVars.conf.
# Look for the PASSWORDHASH key.
password = ""

# Url to check the service status
url_status = "%s/api.php?status&auth=%s" % (base_url, password)

# Url to get the summary
url_summary = "%s/api.php?summary" % base_url

# Urls to enable/disable service
url_enable = "%s/api.php?enable&auth=%s" % (base_url, password)
url_disable = "%s/api.php?disable&auth=%s" % (base_url, password)

# Url to get versions
url_versions = "%s/api.php?versions" % base_url


# ---
# Helper methods
# ---
def convert_to_native(data):
    return json.loads(data)


def do_request(url, method='GET'):
    response = urlopen(url)
    return convert_to_native(response.read())


def get_summary():
    response = do_request(url_summary)
    return response


def get_status():
    response = do_request(url_status)
    return response['status']
    
def get_versions():
    response = do_request(url_versions)
    return response


def separator():
    print('---')


# Data
summary = get_summary()
versions = get_versions()
status = get_status()
enabled = status == 'enabled'

# Layout
def bitbar():
    # Menubar icon
    print "| image=iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAACXBIWXMAABYlAAAWJQFJUiTwAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzABhzBBdzBC/xgNoRCJMTCQhBCCmSAHHJgKayCQiiGzbAdKmAv1EAdNMBRaIaTcA4uwlW4Dj1wD/phCJ7BKLyBCQRByAgTYSHai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AAAAAAAAAAAAAAAAP8AAAL+AAAB/wAABwIAAOL8+wDP97sDDgO7CgUBAPTY+jEd4fpgLf0APQcGAPnV6P6u5t/7qfT0/eIAIAQAAWkTAAD1AAD/Af8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABPAAAAAAAAAAAAAAAAAAAAAAAAAf///wAAAAAAAAAAAAAAAAAAAAAAAWMSAAAAAAAAAAAAAAAAAAAAAAAAAf4AAAAAAAAOAgAAy/kAAMT2AAIAAABJAABPRwAAdWAAADsNAAAAAAAAAPwAAACrAADoeQAAfuEAAJsCAAAAAQAAAP0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////AAAAAAAAAAAAAAAAAAAAAAAA////AP///wD///8A////AP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAhM0AAP//AAD//wAA//8AAP//AAD//wAA//8AAP/YAAD/JgAAfwAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AAD///8A////AP///wD///8A////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADYAAIXqAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP+oAAD/DwAAegAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///wD///8A////AP///wD///8AAP///wD///8A////AP///wD///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAqAACB5QAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA/+wAAP+jAAD/MgAAcQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////AP///wD///8A////AP///wAA////AP///wD///8A////AP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALAAAf90AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD/4AAA/7gAAP/cAAD/JgAAbwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AAD///8A////AP///wD///8A////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADQAAHjdAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP/oAAD/kgAA/+wAAP/bAAD/JAAAawAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///wD///8A////AP///wD///8AAP///wD///8A////AP///wD///8AAAAAAAAAAAAAAAAAAAAAAAAAAAA2AAB14QAA//8AAP/6AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA/90AAP+UAAD/9gAA//8AAP/TAAD/HwAAXgAAAAADAAAAAQAAAAAAAAAAAAAA////AP///wD///8A////AP///wAA////AP///wD///8A////AP///wAAAAAAAAAAAAAAAAAAAAAADgAAbp8AAP/HAAD/mQAA/5cAAP++AAD/+QAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD/lgAA/5UAAP//AAD//wAA//8AAP/LAAD+IgAAVSAAAAAUAAAAAAAAAAAAAAD///8A////AP///wD///8A////AAD///8A////AP///wD///8A////AAAAAAAAAAAAAAAAAAgAAGyiAAD/6AAA/9UAAP/ZAAD/xQAA/3sAAP9PAAD/wwAA//8AAP//AAD//wAA//8AAP//AAD//wAA/8YAAP8/AAD/2wAA//8AAP//AAD//wAA//8AAP+9AAD6HwAATwkAAAAAAAAAAAAAAP///wD///8A////AP///wD///8AAP///wD///8A////AP///wD///8AAAAAAAAAAAAYAABcxQAA//8AAP//AAD//wAA//8AAP//AAD//wAA/44AAP8KAAD/dAAA/9sAAP//AAD//wAA//8AAP/AAAD/FQAA/5QAAP//AAD//wAA//8AAP//AAD//wAA//8AAP+oAADxBwAAPAAAAAAAAAAA////AP///wD///8A////AP///wAA////AP///wD///8A////AP///wAAAAAAAAAAG54AAOL/AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA/4YAAP8AAAD/EAAA/0IAAP9hAAD/QwAA/wAAAP9eAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP94AADKAAAAAAAAAAD///8A////AP///wD///8A////AAD///8A////AP///wD///8A////AAAAACwuAACI7AAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD/5QAA/yAAAP8AAAD/AAAA/wAAAP8AAAD/BQAA/9cAAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA/9sAAP0NAABVAAAAC////wD///8A////AP///wD///8AAP///wD///8A////AP///wD///8AGQAAiG0AAOX/AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP/9AAD/UAAA/wAAAP8AAAD/AAAA/wAAAP9IAAD/+QAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD/+gAA/0oAAM0DAABu////AP///wD///8A////AP///wACAAAAAAAAAAAAAAAAAAAAAAAAAAAJAAALCAAABwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPwAAAD4AAAAAAAAAAAAAAAAAAAAAAAAAB0AAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAEwAAIQcAACcAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAOAAALXPAAC++AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA5wAAAM4AAAAAAAAAAAAAAAAAAAAAAAAA8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPUAAADiAADI9gAAwwAAAAAAAAAAAAAAAAAAAAAAAAAAAP///wD///8A////AP///wD///8AAAAAAAIAADvSAADz/wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP+YAAD/AAAA/wgAAP8VAAD/CAAA/wAAAP8MAAD/2wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD/0gAA8wEAADsAAAAA////AP///wD///8A////AP///wAA////AP///wD///8A////AP///wAAAAAAAAAAAEkAAKH8AAD//wAA//8AAP//AAD//wAA//8AAP//AAD/1gAA/w8AAP9ZAAD/vQAA/9oAAP++AAD/gAAA/xAAAP87AAD/9AAA//8AAP//AAD//wAA//8AAP//AAD//wAA//wAAP9IAACeAAAAAAAAAAD///8A////AP///wD///8A////AAD///8A////AP///wD///8A////AAAAAAAAAAAAAAAAEnMAAL//AAD//wAA//8AAP//AAD//wAA//8AAP9JAAD/eAAA//8AAP//AAD//wAA//8AAP//AAD/5QAA/2AAAP9eAAD/1AAA//8AAP//AAD//wAA//8AAP/sAAD/VQAAugAAAA4AAAAAAAAAAP///wD///8A////AP///wD///8AAP///wD///8A////AP///wD///8AAAAAAAAAAAAAAAAAAAAAE3UAAMb/AAD//wAA//8AAP//AAD/oAAA/1kAAP/2AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA/78AAP+IAAD/mgAA/64AAP/GAAD/zAAA/zgAAMIAAAAPAAAAAAAAAAAAAAAA////AP///wD///8A////AP///wAA////AP///wD///8A////AP///wAAAAAAAAAAAAYAAAANAAAAAAAAF3cAAM//AAD//wAA//8AAP9/AAD/xwAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//gAAP/SAAD/xAAA//AAAP9kAADLAAAAFQAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AAD///8A////AP///wD///8A////AAAAAAAAAAAABAAAABUAAAAVAAAAAAAAHHIAAMr/AAD/4AAA/44AAP/rAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD/gAAAygkAABsJAAAAAAAAAAAAAAAAAAAAAAAAAP///wD///8A////AP///wD///8AAP///wD///8A////AP///wD///8AAAAAAAAAAAAEAAAAFAAAABYAAAATAAAAAAAAHIAAAMLzAAD/mAAA/+oAAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA/3cAAMYAAAAeHgAAAAkAAAAAAAAAAAAAAAAAAAAAAAAA////AP///wD///8A////AP///wAA////AP///wD///8A////AP///wAAAAAAAAAAAAQAAAAUAAAAFgAAABUAAAAMAAAAAQAAFHMAAMfFAAD/9QAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP9+AADNAAAAGREAAAAgAAAACQAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AAD///8A////AP///wD///8A////AAAAAAAAAAAABAAAABQAAAAWAAAAFAAAABQAAAANAAAADQAAF0QAAM/oAAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA//8AAP//AAD/hwAA2wMAAB0SAAAAGgAAACAAAAAJAAAAAAAAAAAAAAAAAAAAAAAAAP///wD///8A////AP///wD///8AAP///wD///8A////AP///wD///8AAAAAAAAAAAAEAAAAFAAAABYAAAAUAAAAEgAAABUAAAAiAAAAAAAAHV4AAMv/AAD//wAA//8AAP//AAD//wAA//8AAP//AAD//wAA/4cAANsMAAAnHgAAABkAAAAYAAAAIAAAAAkAAAAAAAAAAAAAAAAAAAAAAAAA////AP///wD///8A////AP///wAA////AP///wD///8A////AP///wAAAAAAAAAAAAQAAAAUAAAAFgAAABQAAAASAAAAFQAAACQAAAAKAAAAAAAAHGsAALz2AAD//wAA//8AAP//AAD//wAA//IAAP9tAAC/DAAAJyQAAAAfAAAAGQAAABgAAAAgAAAACQAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AAH///8AAAAAAAAAAAAAAAAAAAAAAAEBAQAAAAAABAAAABAAAAACAAAA/gAAAP4AAAADAAAADwAAAOcAAAD+AAAA9wAABioAAGtgAABeOQAAHPsAAP/BAADepQAAoNwAAJ4jAAD6AwAAAPkAAAD6AAAA/wAAAAgAAADpAAAA9wAAAAAAAAAAAAAAAAAAAP///wAAAAAAAAAAAAAAAAAAAAAAAQAA//8wabirP4J+hgAAAABJRU5ErkJggg=="
    separator()

    print("Open pi-hole admin UI | color=blue href=%s" % base_url)
    separator()

    print('Status: %s' % status) + "|  color=black"
    if enabled:
     print('Disable Pi-hole | color=red href=%s' % url_disable)
    else:
     print('Enable Pi-hole | color=green href=%s' % url_enable)
    separator()
    
    #print("Core: %s" % versions['core_current']) + "| color=black"
    print("Core: %s (%s)" % (versions['core_current'],
                             versions['core_branch'])) + "| color=black"
    if not versions[‘core_current’] == versions[‘core_latest’]:
     print("Update available: %s" % versions['core_latest']) + "| color=red"
    else:
     print("Up to date| color=green")
    separator()
    #print("Web: %s" % versions['web_current']) + "| color=black"
    print("Web: %s (%s)" % (versions['web_current'],
                            versions['web_branch'])) + "| color=black"
    if not versions[‘web_current’] == versions[‘web_latest’]:
     print("Update available: %s" % versions['web_latest']) + "| color=red"
    else:
     print("Up to date| color=green")
    separator()
    #print("FTL: %s" % versions['FTL_current']) + "| color=black"
    print("FTL: %s (%s)" % (versions['FTL_current'],
                            versions['FTL_branch'])) + "| color=black"
    if not versions[‘FTL_current’] == versions[‘FTL_latest’]:
     print("Update available: %s" % versions['FTL_latest']) + "| color=red"
    else:
     print("Up to date| color=green")
    separator()
    
    print("Domains being blocked: %s" % summary['domains_being_blocked']) + "| color=black"
    print("Ads blocked today: %s (%s%%)" % (summary['ads_blocked_today'],
                                            summary['ads_percentage_today'])) + "| color=black"
    print("Unique domains today: %s" % summary['unique_domains']) + "| color=black"
    print("DNS queries today: %s" % summary['dns_queries_today']) + "| color=black"
    print("Queries cached today: %s" % summary['queries_cached']) + "| color=black"
    print("Queries forwarded today: %s" % summary['queries_forwarded']) + "| color=black"
    separator()
    print "Last Blocked Domain: | color=black"
    request = urllib2.Request(base_url + '/api.php?recentBlocked')
    response = urllib2.urlopen(request)
    html = response.read()
    print html + "| color=black"
    separator()

# Execution
try:
    bitbar()
except Exception as e:
    print('Script error:')
    print(e)
    separator()

#10

Your still using the ‘not’ and ‘==’ in the expressions.
Not sure if its the right syntax.

Try these which to me (Python n00b) makes more sense ?

if versions[‘core_current’] != versions[‘core_latest’]:

if versions[‘web_current’] != versions[‘web_latest’]:

if versions[‘FTL_current’] != versions[‘FTL_latest’]:


#11

still get the synntax error


#12

Does python allow mixed single quotes like and ?
Try these instead:

if versions['core_current'] != versions['core_latest']:

if versions['web_current'] != versions['web_latest']:

if versions['FTL_current'] != versions['FTL_latest']:


#13

that did it!!!

my question is in this scenaro:

if versions['core_current'] != versions['core_latest']:
 print("Update available: %s" % versions['core_latest']) + "| color=red"
else:
 print("Up to date| color=green")

if current and latest are the same it prints up to date annd if current and latest are different it prints update available correct?


#14

Correct.

The if condition compares the current version to the latest.

Due to the != operator, if values of two operands are not equal, then condition becomes true as in:

If current version is different from latest, print update available, otherwise, (if both versions are identical, condition would be false) print up to date.


#15

thank you so much!!!

i have another questionn if you don’t mind?

in this section:

print('Status: %s' % status) + "|  color=black"
if enabled:
 print('Disable Pi-hole | color=red href=%s' % url_disable)
else:
 print('Enable Pi-hole | color=green href=%s' % url_enable)

i have a clickable Enable or Disable, but it opens a webpage when clicked, is it possible to send the comannd without opening the page?


#16

Weird by quoting @C4Wiz code, we got and introduced and we just copied and pasted it :smiley:
Now we’re all Python experts :wink:


#17

Could play with the base_url as url_disable and url_enable are derived from it:

# URL to the pi-hole admin path without trailing slash
base_url = "http://pi-hole.local/admin"

Could try:

# URL to the pi-hole admin path without trailing slash
base_url = "./admin"

#18

Yeah I just noticed that. It changed the ' to ‘’ :slight_smile:

It’s supposed to open a page (from the code) to your instance of pihole and call enable/disable via the api.php and your hash key.

You are importing urllib2 and you are even checking for python version

You can use urllib.urlopen(for Python 2.x) and urllib.request.urlopen (for python 3.x) for “silent” behavior.


#19

am i close?
print('Disable Pi-hole | color=red href=%s' urllib.request.urlopen("% url_disable)")


#20

Test it :slight_smile:
Failure is not a bad thing. It is a guaranteed and inevitable part of learning.