def showYoutubeStats(channelId): global rootDirectory global statusNeopixel global setBackground global jsonTraverse global board global collegiateFont global primaryDisplayGroup url = "https://www.googleapis.com/youtube/v3/channels/?part=statistics&id=" + channelId + "&key=" + secrets['youtube_token'] countJsonPropPath = ["items", 0, "statistics", "viewCount"] count2JsonPropPath = ["items", 0, "statistics", "subscriberCount"] # get data from url statusNeopixel.fill((100, 100, 0)) # yellow = fetching data gc.collect() r = requests.get(url) gc.collect() statusNeopixel.fill((0, 0, 100)) # green = got data jsonData = r.json() r.close() gc.collect() count = jsonTraverse(jsonData, countJsonPropPath) count2 = jsonTraverse(jsonData, count2JsonPropPath) # display data countLabel = Label(collegiateFont, text=str(count)) countLabel.x = 100 countLabel.y = 129 countLabel.color = 0xFFFFFF countLabel2 = Label(collegiateFont, text=str(count)) countLabel2.x = 155 countLabel2.y = 180 countLabel2.color = 0xFFFFFF primaryDisplayGroup.append(countLabel) primaryDisplayGroup.append(countLabel2) # load github stat background setBackground(rootDirectory + "/youtube_background.bmp") # wait time.sleep(60) # cleanup! while countLabel: countLabel.pop() while countLabel2: countLabel.pop()
def updateBootProgress(phrase, step): global progressLabel if progressLabel is None: progressLabel = Label(arialFont, text = str(phrase)) progressLabel.x = 30 progressLabel.y = 30 progressLabel.color = 0xFFFFFF primaryDisplayGroup.append(progressLabel) else: progressLabel._update_text(str(phrase)) board.DISPLAY.refresh_soon() board.DISPLAY.wait_for_frame() pass
def showTwitterStats(twitterName): global rootDirectory global statusNeopixel global setBackground global jsonTraverse global board global collegiateFont global primaryDisplayGroup url = "https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names=" + twitterName countJsonPropPath = [0, "followers_count"] # get data from url statusNeopixel.fill((100, 100, 0)) # yellow = fetching data gc.collect() r = requests.get(url) gc.collect() statusNeopixel.fill((0, 0, 100)) # green = got data jsonData = r.json() r.close() gc.collect() count = jsonTraverse(jsonData, countJsonPropPath) # display data countLabel = Label(collegiateFont, text=str(count)) countLabel.x = 200 countLabel.y = 100 countLabel.color = 0xFFFFFF primaryDisplayGroup.append(countLabel) # load github stat background setBackground(rootDirectory + "/twitter_background.bmp") # wait time.sleep(60) # cleanup! while countLabel: countLabel.pop()
def showRedditStats(subreddit): global rootDirectory global statusNeopixel global setBackground global jsonTraverse global board global collegiateFont global primaryDisplayGroup url = "https://www.reddit.com/r/" + subreddit + "/about.json" countJsonPropPath = ["data", "subscribers"] # get data from url statusNeopixel.fill((100, 100, 0)) # yellow = fetching data gc.collect() r = requests.get(url) gc.collect() statusNeopixel.fill((0, 0, 100)) # green = got data jsonData = r.json() r.close() gc.collect() count = jsonTraverse(jsonData, countJsonPropPath) # display data countLabel = Label(collegiateFont, text=str(count)) countLabel.x = 200 countLabel.y = 100 countLabel.color = 0xFFFFFF primaryDisplayGroup.append(countLabel) # load github stat background setBackground(rootDirectory + "/reddit_background.bmp") # wait time.sleep(60) # cleanup! while countLabel: countLabel.pop()
def showGithubStats(repo): global rootDirectory global statusNeopixel global setBackground global jsonTraverse global board global collegiateFont global primaryDisplayGroup url = "https://api.github.com/repos" + repo + "?access_token="+secrets['github_token'] countJsonPropPath = ["stargazers_count"] # get data from url statusNeopixel.fill((100, 100, 0)) # yellow = fetching data gc.collect() r = requests.get(url) gc.collect() statusNeopixel.fill((0, 0, 100)) # green = got data jsonData = r.json() r.close() gc.collect() count = jsonTraverse(jsonData, countJsonPropPath) # display data countLabel = Label(collegiateFont, text=str(count)) countLabel.x = 200 countLabel.y = 100 countLabel.color = 0xFFFFFF primaryDisplayGroup.append(countLabel) # load github stat background setBackground(rootDirectory + "/githubstar.bmp") # wait time.sleep(60) # cleanup! while countLabel: countLabel.pop()
def showLocalTemperature(LogToSd): global rootDirectory global setBackground global board global collegiateFont global primaryDisplayGroup temp = # display data countLabel = Label(collegiateFont, text=str(count)) countLabel.x = 100 countLabel.y = 129 countLabel.color = 0xFFFFFF countLabel2 = Label(collegiateFont, text=str(count)) countLabel2.x = 155 countLabel2.y = 180 countLabel2.color = 0xFFFFFF primaryDisplayGroup.append(countLabel) primaryDisplayGroup.append(countLabel2) # load github stat background setBackground(rootDirectory + "/youtube_background.bmp") # wait time.sleep(60) # cleanup! while countLabel: countLabel.pop() while countLabel2: countLabel.pop()
# needed so we know where to find files cwd = ("/" + __file__).rsplit('/', 1)[0] # Initialize the pyportal object and let us know what data to fetch and where # to display it mogwai_image = cwd + "/mogwai_background.bmp" mogwai_sound = cwd + "/mogwai_alarm.wav" gremlin_image = cwd + "/gremlin_background.bmp" gremlin_sound = cwd + "/gremlin_alarm.wav" pyportal = PyPortal(status_neopixel=board.NEOPIXEL, default_bg="pyportal_startup.bmp") big_font = bitmap_font.load_font(cwd + "/fonts/DSEG14ModernMiniBI-44.bdf") big_font.load_glyphs(b'0123456789:AP') # pre-load glyphs for fast printing time_textarea = Label(big_font) time_textarea.x = 0 time_textarea.y = 130 time_textarea.color = 0xFF0000 pyportal.splash.append(time_textarea) # To help us know if we've changed the times, print them out! gremlin_hour, gremlin_min = gremlin_time[3:5] print("Gremlin time: %02d:%02d" % (gremlin_hour, gremlin_min)) mogwai_hour, mogwai_min = mogwai_time[3:5] print("Mogwai time: %02d:%02d" % (mogwai_hour, mogwai_min)) gremlin_since_midnite = gremlin_hour * 60 + gremlin_min mogwai_since_midnite = mogwai_hour * 60 + mogwai_min # this is how we track whether to flip images is_gremlin_time = None last_gremlin_time = is_gremlin_time
pages.append(pp) desc_label = Label(font1, max_glyphs=200, color=0xbbbbff, x=0, y=120) pp.append(desc_label) pixel_around() try: pyportal.get_local_time() except: microcontroller.reset() last_time = time.monotonic() pyportal.set_background(cwd + "/background.bmp") date_label.text = "Almost Ready..." date_label.x = 160 - int(date_label.bounding_box[2] / 2) pixel_around() prior_day = 0 prior_sec = 0 prior_hpixel = 0 prior_mpixel = 0 prior_spixel = 0 while True: if (time.monotonic() - last_time) > 3600: last_time = time.monotonic() try: pyportal.get_local_time() except: