当前位置: 首页>>代码示例>>Python>>正文


Python Twitter.latestTweet方法代码示例

本文整理汇总了Python中twitter.Twitter.latestTweet方法的典型用法代码示例。如果您正苦于以下问题:Python Twitter.latestTweet方法的具体用法?Python Twitter.latestTweet怎么用?Python Twitter.latestTweet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twitter.Twitter的用法示例。


在下文中一共展示了Twitter.latestTweet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import latestTweet [as 别名]
class RaspberryStatus:
    def __init__(self):
        self.__screen = None
        self.__weather = Weather()
        self.__brewskeeball = Brewskeeball()
        self.__twitter = Twitter()

    def printScreen(self):
        scn = self.__screen
        scn.clear()
        scn.border(0)

        # Title
        scn.addstr(0, 31, "RASPBERRY STATUS", curses.A_STANDOUT)

        # construct inner Window
        begin_x = 1 ; begin_y = 1
        height = 22 ; width = 78
        win = curses.newwin(height, width, begin_y, begin_x)

        # Weather
        win.clear()
        win.addstr(0, 0, "Weather For Today - Data provided by NOAA", curses.A_BOLD)
        weather_text = self.wordwrapStringAt(self.__weather.description() , width)
        win.addstr(1, 0, weather_text)
        win.hline( 3, 0, "-", width)

        # Brewskeeball
        win.addstr(4, 0, "Brewskeeball", curses.A_BOLD)
        win.addstr(5, 4, "Next Matchup:")
        win.addstr(6, 0, Util.centerString(self.__brewskeeball.matchupTeams(), width))
        win.addstr(7, 0, Util.centerString("%s at %s" % (self.__brewskeeball.matchupDate(), self.__brewskeeball.matchupTime()), width))
        win.hline( 8, 0, "-", width)

        # Twitter
        win.addstr(9,  0, Util.centerString("TWITTER @tom_g_", width), curses.A_BOLD)
        latest_tweet = self.__twitter.latestTweet()
        author_name = "@%s" % latest_tweet.author.screen_name
        win.addstr(10, 0, author_name, curses.A_BOLD)
        win.addstr(10, len(author_name)+1, latest_tweet.text )
        
        # Render screen
        scn.refresh()
        win.refresh()
    
    """
    Setup & Teardown Methods for the curses screen
    """
    def setupScreen(self, scr = None):
        curses.noecho()
        curses.cbreak()
        if scr:
            self.__screen = scr
        else:
            self.__screen = curses.initscr()
        self.__screen.keypad(1)
        curses.use_default_colors()


    def teardownScreen(self):
        curses.nocbreak()
        self.__screen.keypad(0)
        curses.echo()
        curses.endwin()

    def wordwrapStringAt(self, text, width):
        """ 
        Inject spaces into a string to cause curses to wordwrap at <width>
        BUG: Only does it for the first line.
        BUG: Untested
        """
        text = list(text)
        if len(text) > width:
            while text[width] != " ": # if last char isn't a space
                for x in range(0, width):
                    if text[width-x] == " ": # go backwards
                        text[width-x] = text[width-x] + " "
                        text = ''.join(text)
                        text = list(text)
                        break
        return ''.join(text)
            

    def mainLoop(self, stdscr):
        # Init Param from wrapper
        self.setupScreen(stdscr)
        user_input = 0
        while user_input != ord('q'):
            self.printScreen()
            user_input = self.__screen.getch()
        self.teardownScreen()
开发者ID:trg,项目名称:raspberrystatus,代码行数:93,代码来源:raspberrystatus.py


注:本文中的twitter.Twitter.latestTweet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。