API parsing via Python (bitbar)


been trying different variation for a while, still no luck

synntax is my enemy


try defining urllib.request.urlopen at url_enable = :wink:



url_enable = urllib.request.urlopen("%s/api.php?enable&auth=%s" % (base_url, password))

i get NameError: name urllib is not defined


url_enable = urlopen("%s/api.php?enable&auth=%s" % (base_url, password))

since you already imported urlopen directly.


that does work to disable but breaks the status check so i never get the option to enable, also the pihole is now disabled everytime the script runs


That shouldn’t happen. Unless you altered the get_status() function.


only changed what you posted


It’s because of this.

Every time the scrip is executed, it checks for the status and because Pi-hole is enabled it auto executes the disable function (because of the new urlopen parameter and thus disabling Pi-hole).

You’ll have to adapt the code to execute onl when needed.

Now that you know how to silently send the parameters, go ahead and explore and tinker with the code.

You could implement an added condition to make it more strict …


disabled = status == 'disabled'

print(‘Status: %s’ % status) + “| color=black”
if enabled:
print(‘Disable Pi-hole | color=red href=%s’ % url_disable)
if disabled:
print(‘Enable Pi-hole | color=green href=%s’ % url_enable)


That won’t help, it does nothing at all.

the url_disable gets executed when the function checks for status and sees the status is enabled.
It was designed and implemented as a click that opens the page when clicked (executes url_disable at click - original behavior).

Since we altered the disable code and added urlopen to it, the url_disable when invoked by the IF condition (automatically) disables it (doesn’t wait for click).

You’ll have to write that whole condition differently somehow.


still can’t seem to figure this one out