Parsing Stream Output

class sitebucket.parser.BaseParser

BaseParser is a prototype for Stream Parser objects. All parsers should extend this class.


This method must be overridden. It raises a NotImplementedError.

class sitebucket.parser.DefaultParser

A simple Stream parser that converts the returned data to JSON and prints tweets.


Converts input data to JSON and calls the tweet method if the input is a tweet.

Input that isn’t a tweet:

>>> parser = DefaultParser()
>>> parser.parse('{"some":"json"}')

Input that would be considered a tweet:

>>> parser.parse('{"for_user":1, "message":{"text":"hi!"}}')
For user 1: hi!
tweet(for_user, tweet)

Prints a tweet based on a tweet message and who the user is for.

  • for_user – the id of the user the tweet is for.
  • tweet – a dictionary containing a ‘text’ entry
>>> parser = DefaultParser()
>>> parser.tweet(1, {'text':'hi!'})
For user 1: hi!

Previous topic

Monitoring Streams and Automatically Reconnecting

Next topic


This Page