Last active
August 1, 2019 13:24
-
-
Save yaph/4669516 to your computer and use it in GitHub Desktop.
A snippet that shows how to convert a feedparser time.struct_time object to a Django datetime with timezone support.
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
from django.utils import timezone | |
import time | |
# feed = object from DB | |
# doc = parsed feedparser object | |
feed.updated_at = doc.feed.get('updated_parsed', timezone.now()) | |
if isinstance(feed.updated_at, time.struct_time): | |
feed.updated_at = timezone.make_aware( | |
timezone.datetime(*feed.updated_at[:-3]), | |
timezone.get_default_timezone()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment