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

Returning reddit user IDs for submissions and comments #556

Open
wants to merge 2 commits 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
9 changes: 9 additions & 0 deletions snscrape/modules/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
@dataclasses.dataclass
class Submission(snscrape.base.Item):
author: typing.Optional[str] # E.g. submission hf7k6
author_id: typing.Optional[str]

Choose a reason for hiding this comment

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

I use camelCase for variables/attributes (cf. Comment.parentId), so this should be authorId, and likewise on the other lines.

date: datetime.datetime
id: str
link: typing.Optional[str]
selftext: typing.Optional[str]
subreddit: typing.Optional[str] # E.g. submission 617p51
subreddit_id: typing.Optional[str]
score: int

Choose a reason for hiding this comment

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

The score is intentionally not included. Pushshift's data is almost always outdated and therefore completely wrong. This also wasn't mentioned in either the commit message or the PR...?

title: str
url: str

Expand All @@ -37,11 +40,14 @@ def __str__(self):
@dataclasses.dataclass
class Comment(snscrape.base.Item):
author: typing.Optional[str]
author_id: typing.Optional[str]
body: str
date: datetime.datetime
id: str
parentId: typing.Optional[str]
subreddit: typing.Optional[str]
subreddit_id: typing.Optional[str]
score: int
url: str

created = snscrape.base._DeprecatedProperty('created', lambda self: self.date, 'date')
Expand Down Expand Up @@ -115,9 +121,12 @@ def _api_obj_to_item(self, d):

kwargs = {
'author': d.get('author'),
'author_id': d.get('author_fullname'),
'date': datetime.datetime.fromtimestamp(d['created_utc'], datetime.timezone.utc),
'url': f'https://old.reddit.com{permalink}',
'subreddit': d.get('subreddit'),
'subreddit_id': d.get('subreddit_id'),
'score': int(d.get('score'))
}
if cls is Submission:
kwargs['selftext'] = d.get('selftext') or None
Expand Down