How do I format an RSS, RFC-822 pubDate using Python?
Apr 22, 2019
asked by anonymous
Question / Issue:
How would I create a RFC-822 pubDate using Python?
Here's an example of what I want to produce:
Mon, 22 Apr 2019 04:00:00 PST
Responses:
Date: April 22, 2019
Author: Mind Chasers
Comment:
There are various ways, but here's an example of what seems to work best for us:
$ python3
...
>>> from datetime import datetime
>>> import time
>>> now = datetime.now()
>>> print(now.strftime('%a, %d %b %Y %X ')+time.tzname[0])
Mon, 22 Apr 2019 15:19:28 EDT
There's a %Z format fode for strftime, but it often returns an empty string.
And sometimes we just hardcode the timezone for specific content if we know for sure it needs to be set to something and don't want the underlying OS and environment on a cloud server changing underneath us.