Last active
February 8, 2017 05:27
-
-
Save auxiliary-character/cd33be787f2378ff8bc6827817774bdb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import urllib.request | |
import json | |
import sys | |
import time | |
def get_url(url): | |
opener = urllib.request.build_opener() | |
opener.addheaders = [('User-agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36')] | |
return opener.open(url) | |
def get_json(url): | |
with get_url(url) as f: | |
return json.loads(f.read().decode("utf-8")) | |
def save_file(f,nonce): | |
if ("tim" in f) and ("filename" in f) and ("ext" in f): | |
print(f["tim"],f["filename"],f["ext"]) | |
with get_url("https://media.8ch.net/file_store/{0}{1}".format(f["tim"],f["ext"])) as u: | |
with open("{0:07}-{1}{2}".format(nonce,f["filename"],f["ext"]),"wb") as f: | |
f.write(u.read()) | |
def main(): | |
"""example: $ ./betterthancamo.py civ 39912""" | |
board = sys.argv[1] | |
number = sys.argv[2] | |
thread = get_json("https://8ch.net/{0}/res/{1}.json".format(board,number)) | |
nonce = 0 | |
for post in thread["posts"]: | |
time.sleep(1) | |
nonce+=1 | |
save_file(post,nonce) | |
if "extra_files" in post: | |
for extra in post["extra_files"]: | |
time.sleep(1) | |
nonce+=1 | |
save_file(extra,nonce) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment