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

Conversation

strueman
Copy link

HTML tags were present in content:

The changes made are to reader.py:

  1. Added a new line to strip HTML tags from the content field:
content = BeautifulSoup(entry.summary, "html.parser").get_text(strip=True)
  1. Modified the extracted_text assignment to use strip=True:
extracted_text = soup.get_text(strip=True)
  1. Updated the RedditContent creation to use these new stripped values.
    These changes will remove HTML tags and extra whitespace from both the content and extracted_text fields. The get_text(strip=True) method removes all HTML tags and strips leading and trailing whitespace.
    With these modifications, the output should no longer contain HTML tags in the content and extracted_text fields.

Update example.py

  • Replaced 'datetime.utcnow()' as its depreciated

replaced datetime.utcnow() with datetime.now(timezone.utc) as datetime.utcnow() is depreciated and being removed from datetime.
Changes:

#Old:

from datetime import datetime, timedelta
since_time = datetime.utcnow().astimezone(pytz.utc) + timedelta(days=-5)

#New:

from datetime import datetime, timedelta, timezone
since_time = datetime.now(timezone.utc).astimezone(pytz.utc) + timedelta(days=-5)

The changes made are:

1. Added a new line to strip HTML tags from the `content` field:

   content = BeautifulSoup(entry.summary, "html.parser").get_text(strip=True)

2. Modified the `extracted_text` assignment to use `strip=True`:

   extracted_text = soup.get_text(strip=True)

3. Updated the `RedditContent` creation to use these new stripped values.
These changes will remove HTML tags and extra whitespace from both the `content` and `extracted_text` fields. The `get_text(strip=True)` method removes all HTML tags and strips leading and trailing whitespace.
With these modifications, the output should no longer contain HTML tags in the `content` and `extracted_text` fields.
replaced datetime.utcnow() with datetime.now(timezone.utc) as datetime.utcnow() is depreciated and being removed from datetime.
Changes:
added import timzone
OLD: since_time = datetime.utcnow().astimezone(pytz.utc) + timedelta(days=-5)

NEW: since_time = datetime.now(timezone.utc).astimezone(pytz.utc) + timedelta(days=-5)
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant