tweet_text_parser 0.1

Adds tweet entities to a tweets text in HTML

  Add it to your Download Basket!

 Add it to your Watch List!

0/5

Rate it!
send us
an update
LICENSE TYPE:
Freeware 
USER RATING:
UNRATED
  0.0/5
DEVELOPED BY:
Sym Roe
HOMEPAGE:
github.com
CATEGORY:
ROOT \ Internet \ HTTP (WWW)
tweet_text_parser takes the JSON returned from Twitter's API and converts the tweet text in to HTML using the entities from the API, rather than trying to parse the text manually.

Basic usage

tweet = {
 "text" : "Some tweet",
 "entities" {
 #See the API example https://dev.twitter.com/docs/tweet-entities
 }
}
t = TweetTextParser(tweet)
parsed_tweet = t.parse_all()[0]
parsed_tweet['html]


Note, the whole tweet is returned, with an additional key called html.

Alternatively, a list of tweets can be passed, and each one will have an HTML key added to it.

Templates

If you'd like to change the HTML output of the tweet, you can use pythons string.Template to edit them. At the moment, only the first half of the replacement is templated, as the second half is always "" by default.

There are 4 templates that correspond to the different types of entity:

- media_template
- hashtags_template
- user_mentions_template
- url_template

To changes a template:

from string import Template
t = TweetTextParser(tweet)
t.media_template = Template("""""")

parsed_tweet = t.parse_all()[0]
parsed_tweet['html]

Last updated on August 25th, 2012

requirements

#tweet entities #text parser #tweets text #tweet #text #parser #HTML

Add your review!

SUBMIT