Skip to content
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

Add tracking of mentions to tweets #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions twitterscraper/tweet.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,34 @@ def __init__(self, user, fullname, id, url, timestamp, text, replies, retweets,
self.retweets = retweets
self.likes = likes
self.html = html
self.mentions = mentions
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are never passing the contents of 'mentions' in the from_soup method to this class. (see line 9)


@classmethod
def from_soup(cls, tweet):
mentions = []
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a bit cumbersome.
Would it work if you implemented mentions = tweet.find('div', 'tweet')['data-mentions'] or "" on line 47, and subsequently self.mentions = mentions.split() on line 20.
In this case, if the passed argument is an empty string, the applied split() operation will results in an empty list.

try:
mentions = tweet.find('div', 'tweet')['data-mentions'].split()
except e:
pass
return cls(
user=tweet.find('span', 'username').text[1:],
fullname=tweet.find('strong', 'fullname').text,
id=tweet['data-item-id'],
url = tweet.find('div', 'tweet')['data-permalink-path'],
url=tweet.find('div', 'tweet')['data-permalink-path'],
timestamp=datetime.utcfromtimestamp(
int(tweet.find('span', '_timestamp')['data-time'])),
text=tweet.find('p', 'tweet-text').text or "",
replies = tweet.find(
replies=tweet.find(
'span', 'ProfileTweet-action--reply u-hiddenVisually').find(
'span', 'ProfileTweet-actionCount')['data-tweet-stat-count'] or '0',
retweets = tweet.find(
retweets=tweet.find(
'span', 'ProfileTweet-action--retweet u-hiddenVisually').find(
'span', 'ProfileTweet-actionCount')['data-tweet-stat-count'] or '0',
likes = tweet.find(
likes=tweet.find(
'span', 'ProfileTweet-action--favorite u-hiddenVisually').find(
'span', 'ProfileTweet-actionCount')['data-tweet-stat-count'] or '0',
html=str(tweet.find('p', 'tweet-text')) or "",
mentions=mentions,
)

@classmethod
Expand Down