def chan_jsonGET(url="", download=True): chan_json = urllib.request.urlopen(url, timeout=5) r_chan_json = chan_json.read() f_chan_json = open(cache_dir + "4chan-" + spam.get_time() + ".json", "wb") f_chan_json.write(r_chan_json) #f_chan_json_indent = open(cache_dir+"4chan-"+spam.get_time()+"-i.json", "wb") #d_chan_json_indent = json.dumps(r_chan_json, sort_keys=True, indent=2) #f_chan_json_indent.write(d_chan_json_indent) #json.loads(r_chan_json) # Trying to iter by force fchansrc = "images.4chan.org/{0}/src/".format(board) img_tim = [] # Lists of image tim img_ext = [] # and file type while True: i = 0 for tim in f_chan_json.iter("tim"): img_tim.append(img_tim) for ext in f_chan_json.iter("ext"): img_ext.append(img_ext) for i in range(len(img_tim)): img_a = str(img_tim[i]) + '.' + img_ext[i] img_fchansrc = fchansrc + img_a i += 1 if download == True and os.path.exists(cache_dir + img_a) == False: # if file is already downloaded, it will skip it urllib.request.urlretrieve(img_fchansrc, cache_dir + img_a) print(img_a)
def chan_jsonGET(url = "", download = True): chan_json = urllib.request.urlopen(url,timeout=5) r_chan_json = chan_json.read() f_chan_json = open(cache_dir+"4chan-"+spam.get_time()+".json", "wb") f_chan_json.write(r_chan_json) #f_chan_json_indent = open(cache_dir+"4chan-"+spam.get_time()+"-i.json", "wb") #d_chan_json_indent = json.dumps(r_chan_json, sort_keys=True, indent=2) #f_chan_json_indent.write(d_chan_json_indent) #json.loads(r_chan_json) # Trying to iter by force fchansrc = "images.4chan.org/{0}/src/".format(board) img_tim = [] # Lists of image tim img_ext = [] # and file type while True: i = 0 for tim in f_chan_json.iter("tim"): img_tim.append(img_tim) for ext in f_chan_json.iter("ext"): img_ext.append(img_ext) for i in range(len(img_tim)): img_a = str(img_tim[i])+'.'+img_ext[i] img_fchansrc = fchansrc + img_a i += 1 if download == True and os.path.exists(cache_dir+img_a) == False: # if file is already downloaded, it will skip it urllib.request.urlretrieve(img_fchansrc,cache_dir+img_a) print(img_a)
def LogFile(): getime = spam.get_time() log_file_download = open(pictures.cache_dir + "log-" + getime + ".txt", "wb") log_file_download.write()