示例#1
0
文件: svc.py 项目: olix0r/vtwt
    def getTimeline(self, user=None, params={}):
        """Get recent updates from a user's timeline.
        """
        log.trace("Getting home timeline.")

        messages = []
        def addMessage(msg):
            msg.text = self._recodeText(msg.text)
            messages.insert(0, msg)

        if user in (None, "home"):
            yield self._twt.home_timeline(addMessage, params)
        else:
            yield self._twt.user_timeline(addMessage, user, params)

        returnValue(messages)
示例#2
0
文件: watch.py 项目: olix0r/vtwt
    def execute(self):
        log.trace("Executing watcher.")

        self._lastPrintedId = None
        self._lastError = None
        if self.config["interval"]:
            svc = TimerService(self.config["interval"], self.showTimeline)
            svc.setServiceParent(self)

            # Since this runs ~forever, just return a Deferred that doesn't call
            # back.  A swift SIGINT will kill it.
            d = Deferred()

        else:
            # Print it once and exit
            d = self.showTimeline()

        return d
示例#3
0
文件: watch.py 项目: olix0r/vtwt
    def _printMessage(self, msg, screenNameWidth=14):
        if self.config["long"]:
            fmt = "--- {0.user.screen_name:{2}} {0.created_at} [{0.id}]\n" \
                  "    {1}"
            paddingLen = 4

        else:
            fmt = "{0.user.screen_name:{2}}  {1}"
            paddingLen = screenNameWidth + 2

        width = self.config.parent["COLUMNS"] - paddingLen

        log.trace("Formatting {0} at {1} characters.".format(
                "long message" if self.config["long"] else "message",
                width))
        joiner = "\n" + (" " * paddingLen)
        text = joiner.join(greedyWrap(msg.text, width))
        try:
            print fmt.format(msg, text, screenNameWidth)
        except UnicodeEncodeError, uee:
            # Ignore messages with Unicode errors.  Sahri Charlie.
            log.warn("Unicode error printing message {0.id}".format(msg))
示例#4
0
文件: watch.py 项目: olix0r/vtwt
 def _limitMessages(messages, limit=None):
     if limit and limit < len(messages):
         log.trace("Limiting messages: {0}".format(", ".join(
                 m.id for m in messages[:-limit])))
         del messages[:-limit]
     return messages