def printBusTimes(times): prefix = ["82:", "Rosa:", bustimes.Either("158:", "82B:")] m = "min" op = [] toL5 = lambda s: " " * (max(5 - len(s), 0)) + s for i, ts in enumerate(times): if type(ts) is bustimes.Either: pf = prefix[i].left if ts.left else prefix[i].right next_times = ts.left if ts.left else ts.right else: pf = prefix[i] next_times = ts s = [pf, "-", "-"] for j, t in enumerate(next_times): s[j + 1] = "Núna!" if t == 0 else str(t) + m op.append(" ".join(map(toL5, s))) bt = "\n".join(op) inkyphat.clear() td = datetime.now().strftime("%Y-%m-%d %H:%M") inkyphat.text(((inkyphat.WIDTH - 16 * fontwidth) // 2, 18), td, inkyphat.RED, font) inkyphat.text((inkyphat.WIDTH // 2 - 14 * fontwidth // 2, 2), "Strætóferðir", inkyphat.RED, bigfont) printlines(bt) vtc = ((inkyphat.WIDTH - 10 * 14 - vt.size[0] - 10) // 2, inkyphat.HEIGHT - 2 - 14) inkyphat.text((vtc[0] + vt.size[0] + 2, vtc[1] - 4), "Västtrafik", inkyphat.RED, bigfont) inkyphat.paste(vt, ((vtc[0], vtc[1] - vt.size[1] + 14 - 2))) inkyphat.show()
def main(argv): global font fontsize = "" entry = "" try: opts, arg = getopt.getopt(argv, "he:f:", ["entry=", "fontsize="]) except getopt.GetoptError: print('argv.py -f <fontsize> -e <entry>') sys.exit(2) for opt, arg in opts: print("opt: ", opt) print("arg: ", arg) if opt == '-h': print('argv.py -f <fontsize> -e <entry>') sys.exit() elif opt in ("-e", "--entry"): entry = arg elif opt in ("-f", "--fontsize"): fontsize = int(arg) print('font size is ', fontsize) print('entry is ', entry) font = ImageFont.truetype(inkyphat.fonts.FredokaOne, fontsize) inkyphat.clear() inkyphat.set_colour('red') text(entry, inkyphat.BLACK)
def display_info(text, rotate = True): title = "%s %s" % (text, time.strftime('%d/%m %H:%M')) local_IP = "IP loc.: %s" % (read_local_ip()) public_IP = "IP pub.: %s" % (read_public_ip()) info_CPU = "CPU: T. {:2.0f} C, load {:2.0f} %".format(read_CPU_temp(), cpu_percent()) if has_inky: inkyphat.clear() font18 = inkyphat.ImageFont.truetype(inkyphat.fonts.FredokaOne, 18) font20 = inkyphat.ImageFont.truetype(inkyphat.fonts.FredokaOne, 20) font24 = inkyphat.ImageFont.truetype(inkyphat.fonts.FredokaOne, 24) if rotate: inkyphat.set_rotation(180) inkyphat.rectangle((0, 0, 212, 30), red, red) width, height = font20.getsize(title) d, r = divmod(width, 2) inkyphat.text((106-d, 3), title, white, font=font20) inkyphat.rectangle((0, 31, 212, 104), white, white) inkyphat.text((5, 31), local_IP, black, font=font18) inkyphat.text((5, 53), public_IP, black, font=font18) inkyphat.text((5, 78), info_CPU, red, font=font18) inkyphat.show() else: print(title) print(local_IP) print(public_IP) print(temp_CPU) return local_IP, public_IP, info_CPU
def clear_display(): if not has_inky: return inkyphat.clear() # inkyphat.rectangle((0, 31, 212, 104), inkyphat.WHITE, inkyphat.WHITE) return
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)
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")
def main (argv): global font file = "" try: opts, arg = getopt.getopt(argv,"hf:",["file="]) except getopt.GetoptError: print( 'image.py -f <filename> ') sys.exit(2) for opt, arg in opts: print("opt: ", opt) print("arg: ", arg) if opt == '-h': print( 'image.py -f <filename> ') sys.exit() elif opt in ("-f", "--file"): file = arg print( 'file is ', file ) inkyphat.clear() inkyphat.set_colour('red') image(file)
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()
def image(file): inkyphat.clear() inkyphat.set_colour('red') inkyphat.set_image(Image.open(file)) inkyphat.show()
def send_message(channel_id, message): slack_client.api_call("chat.postMessage", channel=channel_id, text=message, username='******') print("current temp:") while True: if sensor.get_sensor_data(): output = "{0} C".format(sensor.data.temperature) print(output) currentTemp = sensor.data.temperature if currentTemp > tempGoal and prevTemp < tempGoal: inkyphat.set_border(inkyphat.BLACK) inkyphat.clear() inkyphat.text((x, y), "FRESH POTS", inkyphat.RED, font) inkyphat.show() send_message('Channel Id Here', 'Coffee is ready') elif currentTemp < tempGoal and prevTemp > tempGoal: inkyphat.set_border(inkyphat.BLACK) inkyphat.clear() inkyphat._draw.multiline_text((x2, y2), "STALE POT,\n AVOID BRO", inkyphat.RED, font) inkyphat.show() send_message('Channel Id Here', 'Coffee is now cold') prevTemp = currentTemp time.sleep(5)
def on_status(self, tweet): tweet_to_check = tweet.text # checks the tweet does_the_tweet_contain_key_word = tweet_to_check.find( "@Dan_Aldred") ### find MENTIONS replace with your Twitter handle does_the_tweet_contain_STAR_WARS = tweet_to_check.find( "#StarWars") ### find star wars hash tag print(does_the_tweet_contain_key_word) try: if does_the_tweet_contain_key_word >= 0: user = tweet.user.screen_name #gets the user name print(user) ###prints the user's name # responds to a mention @dan_aldred inkyphat.set_image(Image.open("/home/pi/StarWars/MENTION.png")) inkyphat.show() inkyphat.clear() ###### display message #### print(tweet_to_check) message = tweet_to_check txt = textwrap.fill(message, 31) w, h = inkyphat._draw.multiline_textsize(txt, font) x = (inkyphat.WIDTH / 2) - (w / 2) y = (inkyphat.HEIGHT / 2) - (h / 2) inkyphat._draw.multiline_text((x, y), txt, inkyphat.BLACK, font) inkyphat.show() time.sleep(2) inkyphat.clear() ### STAR WARS response elif does_the_tweet_contain_STAR_WARS >= 0: ### display SW intro picture ### print("star wars picture") print("star wars rleated tweet") inkyphat.set_image(Image.open("/home/pi/StarWars/STAR.png")) inkyphat.show() time.sleep(1) inkyphat.clear() # SHOW MESSAGE print(tweet_to_check) message = tweet_to_check txt = textwrap.fill(message, 31) w, h = inkyphat._draw.multiline_textsize(txt, font) x = (inkyphat.WIDTH / 2) - (w / 2) y = (inkyphat.HEIGHT / 2) - (h / 2) inkyphat._draw.multiline_text((x, y), txt, inkyphat.BLACK, font) inkyphat.show() time.sleep(10) inkyphat.clear() else: inkyphat.clear() pass except: ### if there is an emoji and the tweet cannot be displayed print("Cannot render tweet") inkyphat.set_image(Image.open("/home/pi/StarWars/FAIL.png")) inkyphat.show() time.sleep(1) inkyphat.clear()
def printQRcode(text): inkyphat.clear() qr.add_data("http://128.143.67.97:44104/link_your_id/" + text) qr.make(fit=True) qr.make_image() inkyphat.show()
def image(file): inkyphat.clear() inkyphat.set_image(Image.open(file)) inkyphat.show()