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

Update reader.py strip html tags from content, example.py #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 3 additions & 4 deletions example/example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pprint
from datetime import datetime, timedelta

from datetime import datetime, timedelta, timezone
import
import pytz as pytz

from reddit_rss_reader.reader import RedditRSSReader
Expand All @@ -12,8 +12,7 @@
)

# To consider comments entered in past 5 days only
since_time = datetime.utcnow().astimezone(pytz.utc) + timedelta(days=-5)

since_time = datetime.now(timezone.utc).astimezone(pytz.utc) + timedelta(days=-5)
# fetch_content will fetch all contents if no parameters are passed.
# If `after` is passed then it will fetch contents after this date
# If `since_id` is passed then it will fetch contents after this id
Expand Down
8 changes: 6 additions & 2 deletions reddit_rss_reader/reader.py
Copy link
Author

Choose a reason for hiding this comment

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

Just realized that this is probably not needed, my tired brain missed the whole point of extracted_text

Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,17 @@ def fetch_content(self, after: Optional[datetime] = None, since_id: Optional[int
image_alt_texts = [x['alt'] for x in soup.find_all('img', alt=True)]
image_alt_texts = image_alt_texts if image_alt_texts else []

# Strip HTML tags from content and extracted_text
content = BeautifulSoup(entry.summary, "html.parser").get_text(strip=True)
extracted_text = soup.get_text(strip=True)

contents.append(
RedditContent(
link=entry.link,
id=entry.id,
title=entry.title,
content=entry.summary,
extracted_text=soup.get_text(),
content=content,
extracted_text=extracted_text,
image_alt_text=". ".join(image_alt_texts),
updated=datetime.fromtimestamp(mktime(entry.updated_parsed)),
author_name=entry.author_detail.name,
Expand Down