Пример #1
0
def show_image(filepath):
    img = Image.open(filepath)

    pixel_font = get_font("SFPixelate.ttf", 9)
    medium_font = get_font("SFPixelate.ttf", 18)
    # large_font = get_font('SFPixelate.ttf', 36)

    d = ImageDraw.Draw(img)

    time_string = datetime.datetime.now().strftime("%H:%M")
    ip_address = check_output(["hostname", "-I"]).decode("utf-8").strip()
    info_string = f"{ip_address} / {time_string}"

    d.text((1, 95), info_string, font=pixel_font, fill=WHITE)

    quote_url = "https://notify.goude.se/quote"
    quote = requests.get(quote_url).text
    quote_font = pixel_font
    chunk_width = 35

    quote = "\n".join(chunkstring(quote, chunk_width))

    d.multiline_text((1, 1), quote, font=quote_font, fill=WHITE)

    inkyphat.set_colour("black")  # 'red' is much slower
    inkyphat.set_border(inkyphat.BLACK)
    inkyphat.set_image(img)
    inkyphat.show()
Пример #2
0
def render_error(error):
    try:
        print("Error while updating display, attempting to render:", error)
        inkyphat.clear()
        inkyphat.set_border(inkyphat.WHITE)
        inkyphat.text((1, 1), repr(error), inkyphat.BLACK, font_errors)
    except Exception as error2:
        print("Exception while trying to render error:", error2)
Пример #3
0
def cleaner():
    colours = (inkyphat.RED, inkyphat.BLACK, inkyphat.WHITE)
    for c in enumerate(colours):
        inkyphat.set_border(c)
        for x in range(inkyphat.WIDTH):
            for y in range(inkyphat.HEIGHT):
                inkyphat.putpixel((x, y), c)
    inkyphat.show()
Пример #4
0
    def update(self, temperature, weather):
        if temperature and weather:
            self.temp = temperature
            self.weather = weather
            self.active = True
        else:
            self.active = False
        self.update_colors()
        try:
            inkyphat.set_colour(self.color)
        except ValueError:
            print('Invalid colour "{}" for V{}\n'.format(
                self.color, inkyphat.get_version()))
            if inkyphat.get_version() == 2:
                sys.exit(1)
            print('Defaulting to "red"')

        inkyphat.set_border(inkyphat.BLACK)

        # Load our backdrop image
        inkyphat.set_image("resources/backdrop.png")

        # Let's draw some lines!
        inkyphat.line((69, 36, 69, 81))  # Vertical line
        inkyphat.line((31, 35, 184, 35))  # Horizontal top line
        inkyphat.line((69, 58, 174, 58))  # Horizontal middle line
        inkyphat.line((169, 58, 169, 58), 2)  # Red seaweed pixel :D

        # And now some text

        dt = (datetime.datetime.now() +
              datetime.timedelta(seconds=self.tz)).strftime("%m/%d %H:%M")

        inkyphat.text((36, 12), dt, inkyphat.WHITE, font=font)

        inkyphat.text((72, 34), "T", inkyphat.WHITE, font=font)
        inkyphat.text(
            (92, 34),
            u"{:.2f}°".format(self.temp),
            inkyphat.WHITE if self.temp < WARNING_TEMP else inkyphat.RED,
            font=font)

        inkyphat.text((72, 58),
                      "Active" if self.active else "Disconn",
                      inkyphat.WHITE,
                      font=font)

        # Draw the current weather icon over the backdrop
        if self.weather is not None:
            inkyphat.paste(icons[icon_mapping[self.weather]], (28, 36),
                           masks[icon_mapping[self.weather]])

        else:
            inkyphat.text((28, 36), "?", inkyphat.RED, font=font)

        self.display()
Пример #5
0
def updateDisplay(sunrise,  sunset, weather):
    fontSize = 16
    # Load the built-in FredokaOne font
    font = ImageFont.truetype(inkyphat.fonts.FredokaOne, fontSize)
    inkyphat.set_border(inkyphat.BLACK)
    inkyphat.text((0, fontSize * 0), "Tank", inkyphat.BLACK, font=font)
    inkyphat.text((0, fontSize * 1), "Sunrise: " + sunrise.isoformat(), inkyphat.BLACK, font=font)
    inkyphat.text((0, fontSize * 2), "Sunset: " + sunset.isoformat(), inkyphat.BLACK, font=font)
    inkyphat.text((0, fontSize * 3), "Weather: " + weather, inkyphat.BLACK, font=font)
    
    # And show it!
    inkyphat.show()
Пример #6
0
    def __init__(self, config):

        self.config = config

        # Basic Inky settings
        inkyphat.set_colour(self.config.inky_color)
        inkyphat.set_border(self.config.inky_border_color)
        inkyphat.set_rotation(self.config.inky_rotate)

        # startup vars
        self.api_key = self.config.api_key
        self.coin_id = self.config.coin_id
        self.currency = self.config.currency
        self.coin_invest = self.config.coin_invest
        self.coin_amount = self.config.coin_amount
        self.show_roi = self.config.show_roi
        self.font = self.config.font_path
Пример #7
0
def update_display():
    print("Getting train services...")
    services = national_rail_fetcher.get_next_services(station_from,
                                                       station_to)
    print("Got upcoming train services")

    print("Displaying results...")
    inkyphat.clear()
    inkyphat.set_border(inkyphat.WHITE)

    y = 0
    for service in services:
        render_service(service, y)
        y += LINE_HEIGHT

    inkyphat.show()
    print("Finished")
Пример #8
0
def displayStatus(statusString):
    # Prepare the String into two lines
    wrapped = textwrap.wrap(statusString, width=20)

    # Show the backdrop image
    inkyphat.set_colour(config["inkyphatConfig"]["colour"])
    inkyphat.set_border(inkyphat.RED)
    inkyphat.set_image("background.png")
    inkyphat.set_rotation(config["inkyphatConfig"]["rotation"])

    # Add the text
    font = ImageFont.truetype(inkyphat.fonts.FredokaOne, 21)

    # Title Line
    line_one = config["inkyphatConfig"]["line_one"]
    w, h = font.getsize(line_one)
    # Center the text and align it with the name strip
    x = (inkyphat.WIDTH / 2) - (w / 2)
    y = 18 - (h / 2)
    inkyphat.text((x, y), line_one, inkyphat.WHITE, font)

    if(len(wrapped) >= 1):
        # Status Line 1
        status_one = wrapped[0]
        w, h = font.getsize(status_one)
        # Center the text and align it with the name strip
        x = (inkyphat.WIDTH / 2) - (w / 2)
        y = 50 - (h / 2)
        inkyphat.text((x, y), status_one, inkyphat.BLACK, font)


    if(len(wrapped) >= 2):
        # Status Line 2
        status_two = wrapped[1]
        w, h = font.getsize(status_two)
        # Center the text and align it with the name strip
        x = (inkyphat.WIDTH / 2) - (w / 2)
        y = 80 - (h / 2)
        inkyphat.text((x, y), status_two, inkyphat.BLACK, font)


    inkyphat.show()
Пример #9
0
def main():
    fontSize = 16
    mySunrise = sunRiseSet() # Get sunrise and sunset from DB
    mySunrise.getSunriseset();
    
    myWeather  = weather()
    myWeather.getWeather()
    
    # Load the built-in FredokaOne font
    font = ImageFont.truetype(inkyphat.fonts.FredokaOne, fontSize)

    inkyphat.set_border(inkyphat.BLACK)
    
    inkyphat.text((0, fontSize * 0), "Tank", inkyphat.BLACK, font=font)
    inkyphat.text((0, fontSize * 1), "Sunrise: " + mySunrise.sunrise.isoformat(), inkyphat.BLACK, font=font)
    inkyphat.text((0, fontSize * 2), "Sunset: " + mySunrise.sunset.isoformat(), inkyphat.BLACK, font=font)
    inkyphat.text((0, fontSize * 3), "Weather: " + myWeather.weather, inkyphat.BLACK, font=font)
    
    # And show it!
    inkyphat.show()
Пример #10
0
def draw_weather():
    weather = get_weather()
    if weather == None:
        print 'No weather!'
        return

    if ROTATE_180 == True:
        inkyphat.set_rotation(180)
    # TODO configurable color
    inkyphat.set_colour('red')
    inkyphat.set_border(inkyphat.RED)

    # background
    inkyphat.rectangle((0, 0, inkyphat.WIDTH, inkyphat.HEIGHT), inkyphat.RED)

    # draw columns
    # (assuming get_weather has returned using NUM_COLS)
    for i in range(0, NUM_COLS):
        # draw time label
        time = weather['hours'][i]['time']
        w, h = timeFont.getsize(time)
        draw_shadowed_text(get_x(w, i), 4, time, timeFont)

        # draw icon
        try:
            # This could be optimized to not load the same file more than once
            img = Image.open('assets/' + weather['hours'][i]['icon'] + '.png')
            inkyphat.paste(img, (get_x(30, i), 22))
            # drawing icons without transparency as it didn't work with whatever gimp was producing
        except:
            print 'Error with icon:' + weather['hours'][i]['icon']

        # draw temperature label
        temp = weather['hours'][i]['temperature']
        w, h = temperatureFont.getsize(temp)
        draw_shadowed_text(get_x(w, i), 56, temp, temperatureFont)

    # TODO multiple lines if too long
    draw_shadowed_text(5, 84, weather['summary'], summaryFont)

    inkyphat.show()
Пример #11
0
    def update(self, status_id):
        try:
            inkyphat.set_colour("Black")
        except ValueError:
            print('Invalid colour "{}" for V{}\n'.format(self.color, inkyphat.get_version()))
            if inkyphat.get_version() == 2:
                sys.exit(1)
            print('Defaulting to "red"')
        inkyphat.clear()
        inkyphat.set_border(inkyphat.BLACK)

        # Load our backdrop image
        # inkyphat.set_image("resources/backdrop.png")

        # Let's draw some lines!
        # And now some text
        status = statuses[status_id]

        w, h = inkyphat._draw.multiline_textsize(status, font)
        x = (inkyphat.WIDTH / 2) - (w / 2)
        y = (inkyphat.HEIGHT / 2) - (h / 2)
        inkyphat._draw.multiline_text((x, y), status, inkyphat.BLACK, font)

        self.display()
Пример #12
0
# READ REMOTE JSON:
url = "https://nas.imeuro.io/temperino_v2/data/readings.json"
response = urllib.urlopen(url)
d = json.loads(response.read())
d = ast.literal_eval(json.dumps(d))
#print(d)

Rtime = roundTime(datetime.now(), timedelta(minutes=5))
Rdate = strftime('%a, %d %b', Rtime.timetuple())
Rhour = strftime('%H:%M', Rtime.timetuple())

degSign = u'\N{DEGREE SIGN}'

inkyphat.set_colour('red')
inkyphat.set_border(inkyphat.BLACK)

# Partial update if using Inky pHAT display v1
if inkyphat.get_version() == 1:
    inkyphat.show()

# FONTS
font10 = ImageFont.truetype(
    '/var/www/html/temperino_v2_data/fonts/Bitter-Regular.ttf', 10)
font10b = ImageFont.truetype(
    '/var/www/html/temperino_v2_data/fonts/Bitter-Bold.ttf', 10)
font22 = ImageFont.truetype(
    '/var/www/html/temperino_v2_data/fonts/Bitter-Bold.ttf', 22)
font28 = ImageFont.truetype(
    '/var/www/html/temperino_v2_data/fonts/Bitter-Bold.ttf', 28)
Пример #13
0
    if online:
        item['viewers'] = data['stream']['viewers']
    STATE.append(item)
    sys.stdout.write('Done\n')

img = Image.new('RGBA', IMG_SIZE)
fnt = ImageFont.truetype(FONT_PATH, FONT_SIZE)

title_text_w, title_text_h = fnt.getsize(TITLE)
date_text_w, date_text_h = fnt.getsize(NOW)

DATE_POSITION = ((IMG_WIDTH - date_text_w - MARGIN * 2), MARGIN)
TITLE_POSITION = (MARGIN * 2, MARGIN)

inkyphat.set_rotation(180)
inkyphat.set_border(config['FOREGROUND_COLOR'])
inkyphat.rectangle((0, 0, IMG_WIDTH, IMG_HEIGHT),
                   fill=config['BACKGROUND_COLOR'])

inkyphat.rectangle((0, 0, IMG_WIDTH, MARGIN_TOP - MARGIN),
                   fill=config['FOREGROUND_COLOR'])
inkyphat.text(DATE_POSITION, NOW, font=fnt, fill=config['BACKGROUND_COLOR'])
inkyphat.text(TITLE_POSITION, TITLE, font=fnt, fill=config['BACKGROUND_COLOR'])

index = 0
for stream in STATE:
    magic = (MARGIN * 2)
    right_offset = 40
    text_x = MARGIN * 3 + FONT_SIZE + right_offset
    text_y = MARGIN_TOP + (FONT_SIZE + MARGIN) * index + magic
Пример #14
0
#inkyphat.set_rotation(180)

if len(sys.argv) < 3:
    print("""Usage: {} <your name> <colour>
       Valid colours for v2 are: red, yellow or black
       Inky pHAT v1 is only available in red.
""".format(sys.argv[0]))
    sys.exit(1)

colour = sys.argv[2]
inkyphat.set_colour(colour)

# Show the backdrop image

inkyphat.set_border(inkyphat.RED)
inkyphat.set_image("resources/hello-badge.png")

# Partial update if using Inky pHAT display v1

if inkyphat.get_version() == 1:
    inkyphat.show()

# Add the text

font = ImageFont.truetype(inkyphat.fonts.AmaticSCBold, 38)

name = sys.argv[1]

w, h = font.getsize(name)
Пример #15
0
def display_happy(filename):
    inkyphat.set_border(inkyphat.BLACK)
    inkyphat.set_image(Image.open(filename))

    inkyphat.show()
    return
Пример #16
0
try:

    parser = SafeConfigParser()
    parser.read('/etc/pithermostat.conf')
    redishost=parser.get('redis','broker')
    redisport=int(parser.get('redis','port'))
    redisdb=parser.get('redis','db')
    redistimeout=float(parser.get('redis','timeout'))
    room_location = parser.get('locale','location')
    redthis=redis.StrictRedis(host=redishost,
                              port=redisport,  
                              db=redisdb, 
                              socket_timeout=redistimeout)
except:
    import inkyphat
    inkyphat.set_border(inkyphat.BLACK)
    inkyphat.text((36, 12), "No WiFi", inkyphat.WHITE, font=font)
    inkyphat.show()
    exit("Unable to read from /etc/pithermostat.conf")

try:
    import requests
except ImportError:
    exit("This script requires the requests module\nInstall with: sudo pip install requests")

import inkyphat


inkyphat.set_border(inkyphat.BLACK)

CITY = "Bradford"
Пример #17
0
if len(sys.argv) < 2:
    print("""Usage: {} <colour> <number of cycles>
       Valid colours: red, yellow, black
""".format(sys.argv[0]))
    sys.exit(0)

colour = sys.argv[1].lower()
inkyphat.set_colour(colour)

if len(sys.argv) > 2:
    cycles = int(sys.argv[2])
else:
    cycles = 3

colours = (inkyphat.RED, inkyphat.BLACK, inkyphat.WHITE)
colour_names = (colour, "black", "white")

for i in range(cycles):
    print("Cleaning cycle %i\n" % (i + 1))
    for j, c in enumerate(colours):
        print("- updating with %s" % colour_names[j])
        inkyphat.set_border(c)
        for x in range(inkyphat.WIDTH):
            for y in range(inkyphat.HEIGHT):
                inkyphat.putpixel((x, y), c)
        inkyphat.show()
        time.sleep(1)
    print("\n")

print("Cleaning complete!")
Пример #18
0
if line_1_status_code != 10:
    TRAINS_DISRUPTED = True

# Get line 2 status
r = requests.get(OVERGROUND_STATUS)

for status in r.json():
    line_2_name = RENAMES.get(status['name'], status['name'])
    line_2_status_text = status['lineStatuses'][0]['statusSeverityDescription']
    line_2_status_code = status['lineStatuses'][0]['statusSeverity']
    line_2_status_w, line_2_status_h = BOOK_MEDIUM.getsize(line_1_status_text)

if line_1_status_code != 10:
    TRAINS_DISRUPTED = True

inkyphat.set_border(inkyphat.RED if TRAINS_DISRUPTED else inkyphat.WHITE)

inkyphat.set_rotation(180)

# Show the backdrop image

#inkyphat.set_image("resources/hello-badge.png")
#inkyphat.show()

# Add the text

station = 'Euston'

# Center the text and align it with the name strip

#x = (inkyphat.WIDTH / 2) - (w / 2)