Advertisement
Snuggledash

4chan Archive Age

Jun 26th, 2018
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. #!/usr/bin/python3
  2. import time, sys, email.utils
  3. # python3-requests
  4. import requests
  5.  
  6. board = (sys.argv[1] if len(sys.argv) > 1 else None) or 'qa'
  7. now = int(time.time())
  8.  
  9. archives = 'https://a.4cdn.org/' + board + '/archive.json'
  10. thread_placeholder = 'https://a.4cdn.org/' + board + '/thread/{}.json'
  11.  
  12. with requests.Session() as s:
  13.     threads = s.get(archives).json()
  14.     print("thread,time_since_archive")
  15.     for thread in threads:
  16.         #print("Testing /" + board + "/" + str(thread), file=sys.stderr)
  17.         thread_url = thread_placeholder.format(thread)
  18.         resp = s.head(thread_url)
  19.         if resp.ok:
  20.             # archival time is identical with last write time, avoiding pulling the whole thread
  21.             archive_time = int(time.mktime(email.utils.parsedate(resp.headers['Last-Modified'])))
  22.             time_since = now - archive_time
  23.             print(thread, time_since, sep=",")
  24.             time.sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement