コード例 #1
0
ファイル: code.py プロジェクト: richgb/pyportal-soundcloud
                    caption_text=CAPTION,
                    caption_font=cwd + "/fonts/Collegiate-24.bdf",
                    caption_position=(10, 220),
                    caption_color=0x000000)

# track the last value so we can play a sound when it updates
last_follower = 0

while True:
    # Followers:
    # A limitation of the PyPortal object is it must have an equal number of
    # text objects and json fields. So in this case, get some dummy information,
    # then replace the text with the word followers after. It's a bit ugly.
    # Alternatively, do this outside of a pyportal object manually.
    try:
        pyportal._json_path = main_json_path
        dummy, followers = pyportal.fetch(MAIN_DATA_SOURCE)
        pyportal.set_text("Followers:", index=0)
        followers = int(followers)
        print("followers:", followers)
        if last_follower < followers:  # another follower
            print("New Follower!")
            pyportal.play_file(cwd + "/coin.wav")
        last_follower = followers
    except RuntimeError as e:
        print("Some error occured, retrying! -", e)
    except ValueError as e:
        print("Value error occured, retrying! -", e)
    except:
        print("An unknown error occured, retrying!")
コード例 #2
0
        0,  # characters to wrap for text
        0,
        28),
    text_maxlen=(180, 30,
                 115),  # max text size for word, part of speech and def
    caption_text=CAPTION,
    caption_font=cwd + "/fonts/Arial-ItalicMT-17.bdf",
    caption_position=(50, 220),
    caption_color=0x808080)

print("loading...")  # print to repl while waiting for font to load
pyportal.preload_font()  # speed things up by preloading font
pyportal.set_text("\nWord of the Day")  # show title

while True:
    if pyportal.touchscreen.touch_point:
        try:
            #set the JSON path here to be able to change between definition and example
            # pylint: disable=protected-access
            pyportal._json_path = (['word'], PART_OF_SPEECH,
                                   DEFINITION_EXAMPLE_ARR[definition_example])
            value = pyportal.fetch()
            print("Response is", value)
        except RuntimeError as e:
            print("Some error occured, retrying! -", e)
        #Change between definition and example
        if definition_example == 0:
            definition_example = 1
        elif definition_example == 1:
            definition_example = 0