Exemple #1
0
    def test_write_update(self):
        from carson.utils import write_update
        from cStringIO import StringIO
        from datetime import datetime

        buf = StringIO()
        write_update("foo", buf)
        buf.seek(0)
        self.assertTrue(re.search(r"\033\[2Kfoo (.+)\r", buf.read()))

        buf = StringIO()
        write_update("foo", buf, newline=True)
        buf.seek(0)
        self.assertTrue("\n" in buf.read())
Exemple #2
0
    def main(self, **kwargs):
        kwargs['delimited'] = 'length'

        url = self.url + "/statuses/filter.json"
        data = generate_signed_request(url, kwargs)
        headers = {"Content-Type": "application/x-www-form-urlencoded"}

        connection = httplib.HTTPSConnection("stream.twitter.com")
        if http_debug():
            connection.set_debuglevel(1)

        connection.request(
            method = "POST",
            url = "/1/statuses/filter.json",
            body = urllib.urlencode(data),
            headers = headers)

        self.response = connection.getresponse()

        # Placed here because otherwise it would trigger a circular-import
        from carson.models import Tweet, Account

        twitter_ids = Account.objects.values_list('twitter_id', flat=True)

        while True:
            length = self._get_length()
            if length:
                update = self.response.read(length)
                update = json.loads(update)

                if 'in_reply_to_status_id' in update:
                    Tweet.add(update, twitter_ids)
                    write_update("Added #%d" % update['id'], newline=True)

            else:
                write_update("Ping!")
Exemple #3
0
    def main(self, **kwargs):
        kwargs['delimited'] = 'length'

        url = self.url + "/statuses/filter.json"
        data = generate_signed_request(url, kwargs)
        headers = {"Content-Type": "application/x-www-form-urlencoded"}

        connection = httplib.HTTPSConnection("stream.twitter.com")
        if http_debug():
            connection.set_debuglevel(1)

        connection.request(
            method = "POST",
            url = "/1/statuses/filter.json",
            body = urllib.urlencode(data),
            headers = headers)

        self.response = connection.getresponse()

        # Placed here because otherwise it would trigger a circular-import
        from carson.models import Tweet, Account

        twitter_ids = Account.objects.values_list('twitter_id', flat=True)

        while True:
            length = self._get_length()
            if length:
                update = self.response.read(length)
                update = json.loads(update)

                if 'in_reply_to_status_id' in update:
                    Tweet.add(update, twitter_ids)
                    write_update("Added #%d" % update['id'], newline=True)

            else:
                write_update("Ping!")