Exemple #1
0
    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)
Exemple #2
0
    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
Exemple #3
0
    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))
Exemple #4
0
 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