Skip to main content

Simple Twitter streaming API access

Project description

Introduction

tweetstream provides a class, TweetStream, that can be used to get tweets from Twitter’s streaming API. An instance of the class can be used as an iterator. In addition to fetching tweets, the object keeps track of the number of tweets collected and the rate at which tweets are received.

There’s also a ReconnectingTweetStream class that handles automatic reconnecting.

Twitter’s documentation about the streaming API can be found here: http://apiwiki.twitter.com/Streaming-API-Documentation .

Note that the API is blocking. If for some reason data is not immediatly available, calls will block until enough data is available to yield a tweet.

Examples

Printing all incomming tweets:

>>> stream = tweetstream.TweetStream("username", "password")
>>> for tweet in stream:
...     print tweet

The stream object can also be used as a context, as in this example that prints the author for each tweet as well as the tweet count and rate:

>>> with tweetstream.TweetStream("username", "password") as stream
...     for tweet in stream:
...         print "Got tweet from %-16s\t( tweet %d, rate %.1f tweets/sec)" % (
...                 tweet["user"]["screen_name"], stream.count, stream.rate )

Simple tweet fetcher that sends tweets to an AMQP message server using carrot:

>>> from carrot.messaging import Publisher
>>> from carrot.connection import AMQPConnection
>>> from tweetstream import TweetStream
>>> amqpconn = AMQPConnection(hostname="localhost", port=5672,
...                           userid="test", password="test",
...                           vhost="test")
>>> publisher = Publisher(connection=amqpconn,
...                       exchange="tweets", routing_key="stream")
>>> with TweetStream("username", "password") as stream:
...    for tweet in stream:
...        publisher.send(tweet)
>>> publisher.close()

Changelog

See the CHANGELOG file

Contact

The author is Rune Halvorsen <runefh@gmail.com>. The project resides at http://bitbucket.org/runeh/tweetstream . If you find bugs, or have feature requests, please report them in the project site issue tracker. Patches are also very welcome.

License

This software is licensed under the New BSD License. See the LICENCE file in the top distribution directory for the full license text.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tweetstream-0.2.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file tweetstream-0.2.tar.gz.

File metadata

  • Download URL: tweetstream-0.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for tweetstream-0.2.tar.gz
Algorithm Hash digest
SHA256 5639f02dc5181bd4a2e0ce3b4397b894ad586efe5d678b6563ea46f44e04c646
MD5 37bd151b90447586c665503ea026e8c6
BLAKE2b-256 03e230d1e484b67752a8c1a77e75276fb66fc0dd9eaa038d63e74282e8320494

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page