Snuggledash icon

4chan Archive Age

Snuggledash | PRO | 06/26/18 06:06:17 PM UTC | 0 ⭐ | 697 👁️ | Never ⏰ | []
Python |

930 B

|

None

|

0 👍

/

0 👎

#!/usr/bin/python3
import time, sys, email.utils
# python3-requests
import requests
 
board = (sys.argv[1] if len(sys.argv) > 1 else None) or 'qa'
now = int(time.time())
 
archives = 'https://a.4cdn.org/' + board + '/archive.json'
thread_placeholder = 'https://a.4cdn.org/' + board + '/thread/{}.json'
 
with requests.Session() as s:
    threads = s.get(archives).json()
    print("thread,time_since_archive")
    for thread in threads:
        #print("Testing /" + board + "/" + str(thread), file=sys.stderr)
        thread_url = thread_placeholder.format(thread)
        resp = s.head(thread_url)
        if resp.ok:
            # archival time is identical with last write time, avoiding pulling the whole thread
            archive_time = int(time.mktime(email.utils.parsedate(resp.headers['Last-Modified'])))
            time_since = now - archive_time
            print(thread, time_since, sep=",")
            time.sleep(0.5)

Comments