Pi-Hole app



  • Pi-Hole app that's available in Ocean (http://ocean.tingbot.com), isn't working.

    However, there is a quick fix to get the app running again

    Code:
    Line=83 if i == 2:
    Line=84 statText = state['stats'][stats_list[i]['json']] + "%"
    Line=85 else:
    Line=86 statText = state['stats'][stats_list[i]['json']]

    If you remove '+ "%"' from line 84, then the app will work as intended.
    I am fairly new to Python, but I think that the line 84 is trying to accomplish is to shorten the output of calculated results to two digits and adding an '%' as display(print?).

    Example, how it will look now: 'Blocked ads' = "33.333333"
    Trying to get result: 'Blocked ads' = "33.33%"

    I understand that the app is a year old, and perhaps haven't been checked for months, but has this ever worked?
    Could someone perhaps clarify?


  • Core team

    Hey Qake! Great to see people posting on the forums, sorry I'm just catching up with this :)

    If you're looking for something with two decimal places, you could write

    statText = '%.2f%%' % state['stats'][stats_list[i]['json']]
    

    ...which is a little confusing. I'll explain. In Python, the % operator when used in a string will substitute bits in.

    So you could write

    thing = 'Tingbot'
    print '%s is great!' % thing
    

    and the program would print to console Tingbot is great!. That's inserting a string into another string, but here you're inserting a number. And you want to print that number with only 2 decimal places. In that case, instead of writing %s, you write %.2f. The ".2" part means 'print with only 2 decimal places'. Check https://pyformat.info/ for more info on how to do this kind of thing!

    After that, you want to make the '%' sign. That requires %% because when using this style of formatting a single % has a special meaning.

    All in all, that makes '%.2f%%' % state['stats'][stats_list[i]['json']].
    Hope that's helpful!
    Joe



  • This post is deleted!

Log in to reply

Looks like your connection to Pi-Hole app was lost, please wait while we try to reconnect.