-1

I am scraping some Reddit data for my master thesis using this nice Python script - https://gist.github.com/BillyRobertson/06fd81c931834bdd297663d2add6ebf8 - and I am getting .json data like this:

{'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'}

How can I find out in which date (e.g. 03.04.2021) this post was written?

Thank you very much!

ehsan shirzadi
  • 4,709
  • 16
  • 69
  • 112
YogiX
  • 51
  • 5
  • 1
    Do you know what a Unix timestamp is? Probably need to interpret and parse the created_utc as such. – luk2302 Apr 16 '22 at 06:44
  • well...no... ^_^ thank you so much for hinting at it, now I know where to study things I don't know!!! – YogiX Apr 16 '22 at 06:47

1 Answers1

2

If your data is stored in variable d, you should be able to do this:

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

If you only care about the date and don't need to work with it as a datetime object, you can use this instead:

date = datetime.utcfromtimestamp(d['author_created_utc']).strftime('%Y-%m-%d')
Michael Hodel
  • 2,845
  • 1
  • 5
  • 10