Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #copy this text to a new .txt file, then change the extension to .py
- #you'll need python 3.0 to run this file (all you'd need to do is download and install it, then double click the .py file you just created)
- #64 bit Windows download link: https://www.python.org/ftp/python/3.6.1/python-3.6.1-amd64.exe
- #32 bit Windows download link: https://www.python.org/ftp/python/3.6.1/python-3.6.1.exe
- #! /usr/bin/python3
- # -*- coding: utf-8 -*-
- import urllib.request, urllib.error, urllib.parse, urllib.request, urllib.parse, urllib.error, http.cookiejar
- import http.client
- import json
- import pprint
- import os.path
- URL_WGCAT = "http://a.4cdn.org/wg/catalog.json"
- #http://a.4cdn.org/wg/thread/4667225.json
- URL_THREAD = "http://a.4cdn.org/wg/thread/"
- URL_IMG = "https://i.4cdn.org/wg/"
- def newOpener():
- cj = http.cookiejar.CookieJar()
- opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
- opener.addheaders.append(('User-agent', "wg image downloader"))
- return opener
- def postStuff(opener,site,postData, refer="",printResp =False):
- postData = urllib.parse.urlencode(postData)
- if refer != "":
- opener.addheaders.append( ('Referer', refer) )
- resp = opener.open(site, postData,timeOut)
- if printResp:
- return resp.read();
- def main():
- o = newOpener()
- resp = o.open(URL_WGCAT)
- pp = pprint.PrettyPrinter(indent=2)
- pages = json.load(resp)
- threads = []
- for p in pages:
- print((p['page']))
- for t in p['threads']:
- print((t['no']))
- threads.append(t['no'])
- for t in threads:
- tjson = o.open(URL_THREAD+str(t)+".json")
- tvar = json.load(tjson)
- print(( "thread: " +str(t)))
- for post in tvar['posts']:
- try:
- #print "width: "+str(post['w']) + ", height: " + str(post['h'])+",ratio: "+str(post['w']/float(post['h']))+", image id: "+ str(post['tim'])+str(post['ext'])
- if (post['w']==2560) and (post['h'] ==1440):
- if os.path.isfile(str(post['tim'])+str(post['ext'])):
- continue
- print(("width: "+str(post['w']) + ", height: " + str(post['h'])+",ratio: "+str(post['w']/float(post['h']))+", image id: "+ str(post['tim'])+str(post['ext'])))
- img = o.open(URL_IMG+str(post['tim'])+str(post['ext'])).read()
- f = open(str(post['tim'])+str(post['ext']),'wb')
- f.write(img)
- f.close()
- #ratio219.append(str(post['tim'])+str(post['ext']))
- except KeyError:
- #print "post has no image"
- pass
- except Exception as e:
- print((repr(e)))
- #pp.pprint(json.load(resp))
- if __name__ == "__main__":
- #Run as main program
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement