Ejemplo n.º 1
0
def start():
    device = oled.getDevice()

    font = oled.getFont()
    brands_font = oled.make_font("fa-brands.ttf", device.height - 30)
    icon = '\uf7bb'  #raspberry-pi

    if not readConfig():
        oled.scPrint(oled.center('ERROR'), '', 'Couldn\'t read config', '', '',
                     oled.center('Script stopped!'))
        time.sleep(5)
        exit()

    if not DEBUG:
        for i in range(33, 138):  #print fancy chars on startup
            oled.puts(chr(i))
            oled.flush()
            time.sleep(0.025)
        time.sleep(2)

        with canvas(device) as draw:
            w, h = draw.textsize(text=icon, font=brands_font)
            left = (device.width - w) / 2
            draw.text((left, 25), text=icon, font=brands_font)
            draw.text((0, 0), text=oled.center('StatusPi'), font=font)
            draw.text((0, 10),
                      text=oled.center('Version ' + VERSION),
                      font=font)

        time.sleep(5)
Ejemplo n.º 2
0
def timetable():
    haltestelle = "Koeln Hbf"
    try:
        fplan = fpl.getFahrplan()
    except Exception as e:
        oled.oPrint("\n" + oled.center("FEHLER (Fahrplan)") + "\n" + str(e))
        time.sleep(INTERVALL)
    else:
        if fplan:
            for i in range(0, len(fplan)):
                if ((fplan[i].dest == "") or
                    (fplan[i].train == "")):  #Fehlerhafte Daten nicht anzeigen
                    continue

                depart = fplan[i].timeDepart
                if (fplan[i].delay > 0):
                    depart = "(+" + str(
                        fplan[i].delay) + ")" + fplan[i].timeDepart
                oled.oPrint(
                    oled.concat(haltestelle, fplan[i].platform) +
                    "\n---------------------\n" +
                    oled.concat(fplan[i].train, depart) + "\n" + fplan[i].via +
                    "\n" + fplan[i].dest + "\n" + fplan[i].messages)
                time.sleep(INTERVALL / 2)
        else:
            oled.oPrint(haltestelle + "\n---------------------\n\n" +
                        oled.center("Keine Abfahrten") + "\n" +
                        oled.center("gefunden!"))
            time.sleep(INTERVALL / 2)
Ejemplo n.º 3
0
def piholeStatus():
    device = oled.getDevice()
    with canvas(device, dither=None) as draw:
        queries = pihole.getQueries()
        blocked = pihole.getBlocked()
        percentage = pihole.getPercentage()

        if pihole.getStatus():
            ph_status = "(Running)"
        else:
            ph_status = "(Stopped)"
        if ((queries == -1) or (blocked == -1) or (percentage == -1)):
            oled.oPrint(oled.center("PiHole") + "\n\n" + oled.center("Fehler"))
        else:
            fnt = oled.getFont()
            draw.text((0, 0),
                      font=fnt,
                      text=oled.center("PiHole " + ph_status))

            draw.text((0, 20), font=fnt, text=oled.concat("Queries:", queries))
            draw.text((0, 30),
                      font=fnt,
                      text=oled.concat("Blocking:", blocked))
            draw.text((0, 40),
                      font=fnt,
                      text=oled.concat("Percent:",
                                       str(percentage) + "%"))

            pct_bar = 127 * (percentage / 100)
            draw.rectangle((pct_bar, 63, 0, 50), fill="white")
            draw.rectangle((127, 63, 0, 50), outline="grey")

    time.sleep(INTERVALL)
Ejemplo n.º 4
0
def storm():
    try:
        u_in = open("storm.wtd", "r")
    except:
        oled.oPrint("\n" + oled.center("Fehler Unwetter") + "\n" +
                    oled.center("O"))
        w_in.close()
    else:

        #Amtliche Warnung
        try:
            w_count = u_in.readline().rstrip()
        except Exception as e:
            oled.oPrint("\n" + oled.center("Fehler Unwetter") + "\n" +
                        oled.center(str(e)))
            time.sleep(INTERVALL)
        else:
            if w_count > 0:
                try:
                    w_region = umlaute(u_in.readline().rstrip())
                    for i in range(0, int(w_count)):
                        w_headline = umlaute(u_in.readline().rstrip())
                        w_description = umlaute(u_in.readline().rstrip())
                        oled.oPrint(w_region + "\n\n" + w_headline + "\n" +
                                    w_description + "\n\n(" + str(i + 1) +
                                    "|" + w_count + ")")
                        time.sleep(INTERVALL / 2)
                except Exception as e:
                    oled.oPrint("\n" + oled.center("Fehler Unwetter") + "\n" +
                                oled.center(str(e)))
                    time.sleep(INTERVALL)

        #Vorwarnung
        try:
            v_count = u_in.readline().rstrip()
        except Exception as e:
            oled.oPrint("\n" + oled.center("Fehler Unwetter") + "\n" +
                        oled.center(str(e)))
            time.sleep(INTERVALL)
        else:
            if v_count > 0:
                try:
                    v_region = umlaute(u_in.readline().rstrip())
                    for i in range(0, int(v_count)):
                        v_headline = umlaute(u_in.readline().rstrip())
                        v_description = umlaute(u_in.readline().rstrip())
                        oled.oPrint(v_region + "\n\n" + v_headline + "\n" +
                                    v_description + "\n\n(" + str(i + 1) +
                                    "|" + v_count + ")")
                        time.sleep(INTERVALL / 2)
                except Exception as e:
                    oled.oPrint("\n" + oled.center("Fehler Unwetter") + "\n" +
                                oled.center(str(e)))
                    time.sleep(INTERVALL)
Ejemplo n.º 5
0
def start():
    oled.println("".join(chr(i) for i in range(32, 127)))
    time.sleep(2)

    oled.clear()
    oled.println(oled.center("StatusPi"))
    oled.println(oled.center("Version: " + VERSION + "\n"))
    oled.println(oled.center("Starting..."))
    for mill in range(0, 10001, 25):
        oled.puts(oled.center("\rPercent: {0:0.1f} %").format(mill / 100.0))
        oled.flush()
    time.sleep(2)
Ejemplo n.º 6
0
def nightMode():
    device = oled.getDevice()
    font = oled.getFont()
    splash = 5
    x = 40
    y = 53

    while (1):
        now = datetime.datetime.now()
        now_time = now.strftime("%H:%M:%S")

        f = "%H:%M:%S"
        d_str = '04:00:00'
        thr_clock = datetime.datetime.strptime(d_str, f)
        if now.time() > thr_clock.time():
            return

        with canvas(device) as draw:
            if (splash > 0):
                draw.text((0, 20),
                          text=oled.center('Night Mode'),
                          font=font,
                          fill="white")
                splash -= 1
            draw.text((x, y), text=now_time, font=font, fill="grey")
            if (now.strftime("%S") == '59') and (splash == 0):
                x = random.randint(0, 80)
                y = random.randint(0, 52)

        time.sleep(1)
Ejemplo n.º 7
0
def __oldPiholeStatus():
    queries = pihole.getQueries()
    blocked = pihole.getBlocked()
    percentage = pihole.getPercentage()
    if pihole.getStatus():
        ph_status = "(Running)"
    else:
        ph_status = "(Stopped)"
    if ((queries == -1) or (blocked == -1) or (percentage == -1)):
        oled.oPrint(
            oled.center("PiHole " + chr(4)) + "\n\n" + oled.center("Fehler"))
    else:
        oled.oPrint(
            oled.center("PiHole " + ph_status) + "\n" +
            oled.concat("Queries: ", str(queries)) + "\n" +
            oled.concat("Blocked: ", str(blocked)) + "\n" +
            oled.concat("Percentage: ",
                        str(percentage) + "%"))
    time.sleep(INTERVALL)
Ejemplo n.º 8
0
def pistatus():
    temp = os.popen('vcgencmd measure_temp').read()
    tempprint = temp[(temp.rfind("=") + 1):]
    tempprint = tempprint[:4]

    try:
        ip = url.urlopen('http://api.ipify.org').read()
    except:
        ip = "Offline"

    temp = os.popen('vcgencmd measure_volts').read()
    voltprint = temp[(temp.rfind("=") + 1):]
    voltprint = voltprint[:7]
    oled.oPrint(
        oled.center("Pi Status") + "\n\n" +
        oled.concat("CPU-Temp: ", str(tempprint + degreeSymbol)) + "\n" +
        oled.concat("CPU-Volt: ", str(voltprint)) + "\n" +
        oled.concat("IP: ", str(ip)))
    time.sleep(INTERVALL)
Ejemplo n.º 9
0
def piholeStatus():
    if (DEBUG):
        print('piHole Status')

    device = oled.getDevice()

    try:
        piholeip = cfg['pihole']['ip']
    except Exception as e:
        oled.scPrint(oled.center('Error [PiHole]'), '',
                     oled.center('Could not'), oled.center('find config!'))
        time.sleep(INTERVALL)
        return

    for i in range(0, INTERVALL):  #refresh every second for INTERVALL times
        with canvas(device, dither=None) as draw:
            queries = pihole.getQueries(piholeip)
            blocked = pihole.getBlocked(piholeip)
            percentage = pihole.getPercentage(piholeip)

            if pihole.getStatus(piholeip):
                ph_status = "(Active)"
            else:
                ph_status = "(STOPPED)"
            if ((queries == -1) or (blocked == -1) or (percentage == -1)):
                oled.oPrint(
                    oled.center("PiHole") + "\n\n" + oled.center("Fehler"))
            else:
                fnt = oled.getFont()
                draw.text((0, 0),
                          font=fnt,
                          text=oled.center("PiHole " + ph_status))

                draw.text((0, 20),
                          font=fnt,
                          text=oled.concat("Queries:", queries))
                draw.text((0, 30),
                          font=fnt,
                          text=oled.concat("Blocking:", blocked))
                draw.text((0, 40),
                          font=fnt,
                          text=oled.concat("Percentage:",
                                           str(percentage) + "%"))

                pct_bar = 127 * (percentage / 100)
                draw.rectangle((pct_bar, 63, 0, 50), fill="white")
                draw.rectangle((127, 63, 0, 50), outline="grey")

        time.sleep(1)
Ejemplo n.º 10
0
def pistatus():
    if (DEBUG):
        print('PiStatus')

    temp = os.popen('vcgencmd measure_temp').read()
    tempprint = temp[(temp.rfind("=") + 1):]
    tempprint = tempprint[:4]

    try:
        ip = url.urlopen('https://api.ipify.org').read()

#ip = "-"
    except:
        ip = "Offline"

    temp = os.popen('vcgencmd measure_volts').read()
    voltprint = temp[(temp.rfind("=") + 1):]
    voltprint = voltprint[:7]
    oled.oPrint(
        oled.center("Pi Status") + "\n\n" +
        oled.concat("CPU-Temp: ", str(tempprint + '°C')) + "\n" +
        oled.concat("CPU-Volt: ", str(voltprint)) + "\n" +
        oled.concat("IP: ", str(ip.decode('utf-8'))))
    time.sleep(INTERVALL)
Ejemplo n.º 11
0
def timetable():
    if (DEBUG):
        print('Timetable')

    try:
        station = cfg['timetable']['station']
    except Exception as e:
        oled.scPrint(oled.center('Error [Timetable]'), '',
                     oled.center('Could not'), oled.center('find config!'))
        time.sleep(INTERVALL)
        return

    try:
        fplan = ttb.getFahrplan(station)
    except Exception as e:
        oled.scPrint(oled.center('Error [Timetable]', '', str(e)))
        time.sleep(INTERVALL)
    else:
        if fplan:
            for i in range(0, len(fplan)):
                if ((fplan[i].dest == "") or
                    (fplan[i].train == "")):  #Fehlerhafte Daten nicht anzeigen
                    continue

                depart = fplan[i].timeDepart
                if (fplan[i].delay > 0):
                    depart = "(+" + str(
                        fplan[i].delay) + ")" + fplan[i].timeDepart

                oled.scPrint(oled.concat(station, fplan[i].platform),
                             "---------------------",
                             oled.concat(fplan[i].train, depart),
                             umlaute(fplan[i].via), umlaute(fplan[i].dest),
                             umlaute(fplan[i].messages))
                time.sleep(INTERVALL / 2)
        else:
            oled.scPrint(station, "---------------------", "",
                         oled.center("No departures"), oled.center("found!"))
            time.sleep(INTERVALL / 2)
Ejemplo n.º 12
0
def storm():
    if (DEBUG):
        print('Storm')
    try:
        u_in = open("storm.wtd", "r")
    except Exception as e:
        oled.oPrint("\n" + oled.center("Fehler Unwetter") + "\n" + str(e))
        u_in.close()
    else:

        #Amtliche Warnung
        try:
            w_count = u_in.readline().rstrip()
        except Exception as e:
            oled.oPrint("\n" + oled.center("Fehler Unwetter") + "\n" +
                        oled.center(str(e)))
            time.sleep(INTERVALL)
        else:
            try:
                int(w_count)
            except:
                return
            if (str(w_count) == 'error'):
                oled.oPrint(
                    oled.center("Unwetter") + "\n\n" +
                    oled.center("Fehler beim Abrufen!"))
                time.sleep(INTERVALL / 2)
                return
            if int(w_count) > 0:
                try:
                    w_region = umlaute(u_in.readline().rstrip())
                    for i in range(0, int(w_count)):
                        w_headline = umlaute(u_in.readline().rstrip())
                        w_description = umlaute(u_in.readline().rstrip())
                        w_start = u_in.readline().rstrip()
                        w_end = u_in.readline().rstrip()

                        oled.oPrint(
                            w_region + "\n\n" + w_headline + "\n" +
                            w_description + "\n" + oled.concat('', w_start) +
                            "\n" +
                            oled.concat('(' + str(i + 1) + "|" + w_count +
                                        ")", w_end))
                        time.sleep(INTERVALL / 2)
                except Exception as e:
                    oled.oPrint("\n" + oled.center("Fehler Unwetter") + "\n" +
                                oled.center(str(e)))

                    time.sleep(INTERVALL)

        #Vorwarnung
        try:
            v_count = u_in.readline().rstrip()
        except Exception as e:
            oled.oPrint("\n" + oled.center("Fehler Unwetter") + "\n" +
                        oled.center(str(e)))
            time.sleep(INTERVALL)
        else:
            if int(v_count) > 0:
                try:
                    v_region = umlaute(u_in.readline().rstrip())
                    for i in range(0, int(v_count)):
                        v_headline = umlaute(u_in.readline().rstrip())
                        v_description = umlaute(u_in.readline().rstrip())
                        oled.oPrint(v_region + "\n\n" + v_headline + "\n" +
                                    v_description + "\n\n(" + str(i + 1) +
                                    "|" + v_count + ")")
                        time.sleep(INTERVALL / 2)
                except Exception as e:
                    oled.oPrint("\n" + oled.center("Fehler Unwetter") + "\n" +
                                oled.center(str(e)))

                    time.sleep(INTERVALL)
Ejemplo n.º 13
0
def weather():
    if (DEBUG):
        print('Weather')

    MAX_LENGTH = oled.getWidth()
    device = oled.getDevice()

    regulator = framerate_regulator(fps=1)

    weather_font = oled.make_font("fa-solid.ttf", device.height - 40)
    font = oled.getFont()

    try:
        w_in = open("weather.wtd", "r")

        #Weather City1
        name1 = oled.center(w_in.readline().rstrip())
        temp1 = w_in.readline().rstrip()
        condition1 = oled.center(umlaute(w_in.readline().rstrip()))
        icon1 = w_in.readline().rstrip()
        #Weather City2
        name2 = oled.center(w_in.readline().rstrip())
        temp2 = w_in.readline().rstrip()
        condition2 = oled.center(umlaute(w_in.readline().rstrip()))
        icon2 = w_in.readline().rstrip()
        #Forecast
        f_name = oled.center(w_in.readline().rstrip())
        f_icon1 = w_in.readline().rstrip()
        f_temp1_min = w_in.readline().rstrip()
        f_temp1_max = w_in.readline().rstrip()
        f_icon2 = w_in.readline().rstrip()
        f_temp2_min = w_in.readline().rstrip()
        f_temp2_max = w_in.readline().rstrip()
        w_in.close()

    except Exception as e:
        oled.scPrint('Error [Weather]', '', str(e))
        time.sleep(INTERVALL)
    else:
        code1 = getIcon(icon1)
        code2 = getIcon(icon2)

        if not condition1:
            condition1 = oled.center("Error!")
            code1 = '\uf00d'

        if not condition2:
            condition2 = oled.center("Error!")
            code2 = '\uf00d'

        #WETTER1
        diff = (len(condition1) - MAX_LENGTH) * 6

        if diff <= 0:
            diff = 1  #Print strings that are <21 chars long
        a = 0
        with regulator:
            for x in range(0, diff):
                with canvas(device) as draw:
                    w, h = draw.textsize(text=code1, font=weather_font)
                    left = (device.width - w) / 2
                    top = ((device.height - h) / 2) - 5
                    draw.text((left, top), text=code1, font=weather_font)
                    draw.text((0, 0), text=name1, font=font)
                    draw.text((a, 43), text=condition1, font=font)
                    draw.text((0, 53),
                              text=oled.center(temp1 + '°C'),
                              font=font)

                if (
                        x == 0
                ):  #Don't scroll in the first seconds, for enough time to read
                    time.sleep(2)

                if (diff > 0):
                    a -= 1
                    diff -= 1

        time.sleep(INTERVALL / 2)

        #WETTER2
        diff = (len(condition2) - MAX_LENGTH) * 6

        if diff <= 0:
            diff = 1  #Print strings that are <21 chars long
        a = 0
        with regulator:
            for x in range(0, diff):
                with canvas(device) as draw:
                    w, h = draw.textsize(text=code2, font=weather_font)
                    left = (device.width - w) / 2
                    top = ((device.height - h) / 2) - 5
                    draw.text((left, top), text=code2, font=weather_font)
                    draw.text((0, 0), text=name2, font=font)
                    draw.text((a, 43), text=condition2, font=font)
                    draw.text((0, 53),
                              text=oled.center(temp2 + '°C'),
                              font=font)

                if (
                        x == 0
                ):  #Don't scroll in the first seconds, for enough time to read
                    time.sleep(2)

                if (diff > 0):
                    a -= 1
                    diff -= 1

        time.sleep(INTERVALL / 2)

        #Forecast
        if DEBUG:
            print('Forecast')

        with canvas(device) as draw:
            weather_font = oled.make_font("fa-solid.ttf", device.height - 45)

            width = device.width
            height = device.height

            icon1 = getIcon(f_icon1)
            icon2 = getIcon(f_icon2)

            today = datetime.date.today()
            tomorrow = today + datetime.timedelta(days=1)
            d_a_tomorrow = tomorrow + datetime.timedelta(days=1)

            draw.line((63, 20, 63, 64), fill="white")

            draw.text((0, 0), font=font, text=f_name)

            w1, h1 = draw.textsize(text=icon1, font=weather_font)
            left = (width / 4) - (w1 / 2)
            top = ((height - h1) / 2) - 2

            w2, h2 = draw.textsize(text=icon2, font=weather_font)
            right = ((width / 4) * 3) - (w2 / 2)

            draw.text((left, top), text=icon1, font=weather_font)
            draw.text((right, top), text=icon2, font=weather_font)

            draw.text((0, height - 20),
                      font=font,
                      text=oled.half(f_temp1_max + '/' + f_temp1_min + '°C',
                                     f_temp2_max + '/' + f_temp2_min + '°C'))
            draw.text((0, height - 10),
                      font=font,
                      text=oled.half(findDay(str(tomorrow), True),
                                     findDay(str(d_a_tomorrow), True)),
                      fill="orange")
        time.sleep(INTERVALL)
Ejemplo n.º 14
0
def weather():
    try:
        w_in = open("weather.wtd", "r")

        #Wetter 1
        name1 = oled.center("")
        temp1 = w_in.readline().rstrip()
        condition1 = oled.center(umlaute(w_in.readline().rstrip()))
        #Wetter 2
        name2 = oled.center("")
        temp2 = w_in.readline().rstrip()
        condition2 = oled.center(umlaute(w_in.readline().rstrip()))
        w_in.close()
        if not condition1:
            condition1 = oled.center("Fehler!")
        if not condition2:
            condition2 = oled.center("Fehler!")

        oled.oPrint(
            oled.center("Wetter") + "\n\n" + name1 + "\n" + condition1 + "\n" +
            oled.center(temp1 + degreeSymbol))
        time.sleep(INTERVALL / 2)
        oled.oPrint(
            oled.center("Wetter") + "\n\n" + name2 + "\n" + condition2 + "\n" +
            oled.center(temp2 + degreeSymbol))
        time.sleep(INTERVALL / 2)
    except Exception as e:
        print(e)
        oled.oPrint("\n" + oled.center("Wetter") + "\n" +
                    oled.center("Fehler"))
        time.sleep(INTERVALL)