-
Notifications
You must be signed in to change notification settings - Fork 17
Support for entities in profile #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Bouska
wants to merge
5
commits into
satanas:development
Choose a base branch
from
Bouska:feature/profile_entities
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f8cc276
[enh] Add entities attibut to Profile() class
Bouska b3c437c
[enh] Refactor get_entities() method to be generic
Bouska 43f3df8
[enh] Add data to the entities' Profile() attribut
Bouska 2da17d0
[enh] Request a profile JSON with entities from Twitter
Bouska 566be03
[bugfix] Need to check if a field is present in entities before tryin…
Bouska File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -277,7 +277,7 @@ def get_following(self, only_id=False): | |
| return following | ||
|
|
||
| def get_profile(self, user): | ||
| rtn = self.http.get('/users/show', {'screen_name': user}) | ||
| rtn = self.http.get('/users/show', {'screen_name': user, 'include_entities': True}) | ||
| profile = self.json_to_profile(rtn) | ||
| rtn = self.http.get('/statuses/user_timeline', | ||
| {'screen_name': user, 'count': 10, | ||
|
|
@@ -461,6 +461,8 @@ def json_to_profile(self, response): | |
| profile.location = response['location'] | ||
| profile.url = response['url'] | ||
| profile.bio = response['description'] | ||
| if 'url' in response['entities']: | ||
| profile.entities = self.get_entities(response['entities']['url']) | ||
| profile.following = response['following'] | ||
| profile.followers_count = response['followers_count'] | ||
| profile.friends_count = response['friends_count'] | ||
|
|
@@ -548,7 +550,7 @@ def json_to_status(self, response, column_id='', type_=Status.NORMAL): | |
| status.repeated_by = repeated_by | ||
| status.datetime = self.get_str_time(post['created_at']) | ||
| status.timestamp = self.get_int_time(post['created_at']) | ||
| status.entities = self.get_entities(post) | ||
| status.entities = self.get_entities(post['entities']) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't be changed |
||
| status.type_ = type_ | ||
| status.account_id = self.account_id | ||
| status.is_own = (username.lower() == self.uname.lower()) | ||
|
|
@@ -608,44 +610,47 @@ def json_to_trend_location(self, response): | |
| location.placetype_name = response['placeType']['name'] | ||
| return location | ||
|
|
||
| def get_entities(self, tweet): | ||
| if 'entities' in tweet: | ||
| def get_entities(self, raw_entities): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change nothing in this method |
||
| if raw_entities: | ||
| entities = { | ||
| 'urls': [], | ||
| 'hashtags': [], | ||
| 'mentions': [], | ||
| 'groups': [], | ||
| } | ||
| for mention in tweet['entities']['user_mentions']: | ||
| text = '@' + mention['screen_name'] | ||
| entities['mentions'].append(Entity(self.account_id, | ||
| mention['screen_name'], text, | ||
| text)) | ||
|
|
||
| for url in tweet['entities']['urls']: | ||
| try: | ||
| expanded_url = url['expanded_url'] | ||
| except KeyError: | ||
| expanded_url = url['url'] | ||
|
|
||
| try: | ||
| display_url = ''.join(['http://', url['display_url']]) | ||
| except KeyError: | ||
| display_url = url['url'] | ||
|
|
||
| entities['urls'].append(Entity(self.account_id, expanded_url, | ||
| display_url, url['url'])) | ||
|
|
||
| if 'media' in tweet['entities']: | ||
| for url in tweet['entities']['media']: | ||
| if 'user_mentions' in raw_entities: | ||
| for mention in raw_entities['user_mentions']: | ||
| text = '@' + mention['screen_name'] | ||
| entities['mentions'].append(Entity(self.account_id, | ||
| mention['screen_name'], text, | ||
| text)) | ||
|
|
||
| if 'urls' in raw_entities: | ||
| for url in raw_entities['urls']: | ||
| try: | ||
| expanded_url = url['expanded_url'] | ||
| except KeyError: | ||
| expanded_url = url['url'] | ||
|
|
||
| try: | ||
| display_url = ''.join(['http://', url['display_url']]) | ||
| except KeyError: | ||
| display_url = url['url'] | ||
|
|
||
| entities['urls'].append(Entity(self.account_id, expanded_url, | ||
| display_url, url['url'])) | ||
|
|
||
| if 'media' in raw_entities: | ||
| for url in raw_entities['media']: | ||
| display_url = ''.join(['http://', url['display_url']]) | ||
| entities['urls'].append(Entity(self.account_id, | ||
| url['media_url'], display_url, | ||
| url['url'])) | ||
|
|
||
| for ht in tweet['entities']['hashtags']: | ||
| text = ''.join(['#', ht['text']]) | ||
| url = "%s%s" % (self.hashtags_url, ht['text']) | ||
| entities['hashtags'].append(Entity(self.account_id, url, text, | ||
| text)) | ||
| if 'hashtags' in raw_entities: | ||
| for ht in raw_entities['hashtags']: | ||
| text = ''.join(['#', ht['text']]) | ||
| url = "%s%s" % (self.hashtags_url, ht['text']) | ||
| entities['hashtags'].append(Entity(self.account_id, url, text, | ||
| text)) | ||
| return entities | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you just need to do:
profile.entities = self.get_entities(response)