def __init__(self, excel_name, parent_folder=None): """ :param excel_name: excel文件名 :param parent_folder: 文件夹 """ self.excel_name = '{}_{}.xlsx'.format(excel_name, t) self.parent_folder = parent_folder self.work_book = Workbook() make_dir(self.parent_folder)
def save_image(imagetuple, itemtuple): folder = helper.make_dir(itemtuple[-2:]) # make_dir should return a dir, not create one filename = imagetuple[0] image = imagetuple[1] path = os.path.join(config.path, 'image', folder, filename) print "saving image", filename f = open(path, 'wb') f.write(image) f.close()
def download_new_item(latest_item): screen_geometry = helper.get_screen_geometry() url = latest_item[0] folder = helper.make_dir(latest_item[-2:]) conn = urllib.urlopen(url) page = conn.read() conn.close() images = re.findall(pattern_image, page) images = list(set(images)) for image in images: m = re.match('.*/(.*)', image) filename = m.groups()[0] m = re.match('.*?(\d+)x(\d+).*', filename) (width, height) = list(map(int, m.groups()[:2])) if not (width, height) == screen_geometry: continue if os.path.exists(os.path.join(config.path, 'image', folder, filename)): continue logging.debug('downloading image: %s\n' % image) conn = urllib.urlopen(image) image_data = conn.read() conn.close() yield (filename, image_data)