Proposed feature: handle Tweet entities #224
Labels
No labels
Bug
Enhancement
Feature Suggestion
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: code/twython#224
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Twython does a great job of allowing you to access the data from Twitter. Would it be appropriate to take it a step further and add a bit of processing of Tweet data?
In particular, how about a function for obtaining Tweet text with the entities substituted in? (https://dev.twitter.com/docs/tweet-entities).
Note that URL's in Tweet text are always t.co links, but this is not what is shown by Twitter clients. Instead there is a display_url and the expanded_url. It would be nice to have the library access the text as HTML with all of this taken care of.
Re-Tweets may have a URL at the end of the text truncated, e.g. "http://t.co/abc...", so if you don't do the entity substitution you could be displaying a broken link.
Making things more complex, for a re-Tweet, entities.urls is empty, and you have to refer to retweeted_status.entities.urls.
Here's a start at how to deal with some of those issues without changes to Twython:
It may be a nice function, but there is so much stuff could be customized.
My understanding is you want the returned tweet to look like this:
Hey, this is a tweet with a link in it, check it out <a href="http://t.co/fasf">http://t.co/fasf</a>Check out <a href="http://t.co/fasf">@mikehelmick</a> on Twitteror something like that?
What if people want to add classes to each
<a>specifically, or add other attributes like (onClickoridortarget)I feel it may be best to keep it up to the user to find and replace media entities
In my particular case, I was running Tweet.text through Django's urlize, which gave me broken links in some cases, and didn't show the display_url. So my argument is:
Therefore, how about a function for the basic case of dealing with entities? Users who want more customization can code it themselves. (Or add onClick etc using DOM manipulation as I do.)
I think Mike raises a valid point, but I can also see the use case. I wouldn't be against a convenience function to do this, provided it's essentially a "this is what you get, if you need more you're on your own" type of deal.
e.g, a
@staticmethodTwython.html_for_tweet(tweet).Not saying let's implement this, moreso just weighing in. I could go either way on this one.
^^^^ I was just going to say that haha
Hrm, I see your point. Maybe after they get the timeline.
and
Twython.html_for_tweet(tweet)would look something like:Thanks for the discussion. It is not trivial... there's a learning curve here for someone who is not a Twitter expert and just looking for basic functionality. I'm sure many others have missed cases like handling truncated retweets. If we don't add it to Twython, it could end up being another library project.
It's definitely something I'd like in Twython! I'm a bit busy this week. I'll try to mock something up Saturday! :) Thanks for the suggestion!
Awesome! :)
ps. This hack of mine loses the "RT " at the beginning of the tweet. I don't like the idea of just prepending a hardcoded string back in (what if the Twitter convention changes?). But you have to work with the retweet's original text since that's what the 'indices' refer to.
Sorry, just trying to make sure this uses up your whole Saturday. :)
Just checked my Django Mezzanine site's Twitter feed: there must be Python code for this in that project.