约会 Reddit 被抓取 post

Dating a Reddit scraped post

我正在使用这个不错的 Python 脚本为我的硕士论文抓取一些 Reddit 数据 - https://gist.github.com/BillyRobertson/06fd81c931834bdd297663d2add6ebf8 - 我得到了这样的 .json 数据:

{'author': 'xxxxxxxx',
  'author_created_utc': 1373079085,
  'author_flair_css_class': '',
  'author_flair_text': 'Pro Choice',
  'author_fullname': 't2_ca12v',
  'body': "\n>Legally? No. But you certainly have the *right* to do so.\n\nNo you don't have the right. And if you did it wouldn't be illegal.",
  'controversiality': 0,
  'created_utc': 1454111259,
  'distinguished': None,
  'gilded': 0,
  'id': 'czh0sct',
  'link_id': 't3_435gui',
  'nest_level': 5,
  'parent_id': 't1_czgyyl5',
  'reply_delay': 3057,
  'retrieved_on': 1454817532,
  'score': 0,
  'stickied': False,
  'subreddit': 'prolife',
  'subreddit_id': 't5_2qscv'}

我怎样才能知道这个 post 是在哪一天(例如 2021 年 4 月 3 日)写的?

非常感谢!

如果您的数据存储在变量 d 中,您应该可以这样做:

from datetime import datetime
date = datetime.utcfromtimestamp(d['author_created_utc'])

如果您只关心日期而不需要将其作为 datetime 对象使用,您可以改用它:

date = datetime.utcfromtimestamp(d['author_created_utc']).strftime('%Y-%m-%d')