Search code examples
pythondjangorssdatefeedparser

Populating a Django DateTimeField with feedparser


I'm attempting to read my school's athletics/activities calendar, available in iCal or RSS format, into a Django Events model using feedparser.

Everything works, except the dates. Feedparser populates item.updated_parsed with a "9-tuple" but I can't figure out how to make this into something Django will accept in a DateTimeField. (I've used those before, but they've only ever been populated by datetime.datetime.now()).

Any ideas?


Solution

  • Covert the time.struct_time object into a datetime.datetime object:

    from time import mktime
    from datetime import datetime
    dt = datetime.fromtimestamp(mktime(item['updated_parsed']))