def main(self): self.get_user_input() # get all of .wiz self.get_all_of_wiz() # unzip all of wiz files. self.unzip_wiz() # remove blank dir. Path.remove_blank_dir(self._dst)
def get_face_image(): fid = None sid = None args = Base.get_user_input('hf:s:') if '-h' in args: Base.print_help(help_menu) if '-f' in args: fid = Path.get_abs_path(args['-f']) if '-s' in args: sid = Path.get_abs_path(args['-s']) return fid, sid
def get_input(self, args=None): if not args: args = Base.get_user_input('hu:n:p:x:m:R:t:UvDd') if '-h' in args: Base.print_help(self.HELP_MENU) if '-U' in args: self._run_ui = True if '-u' in args: if os.path.isfile(args['-u']): self._url_file = Path.get_abs_path(args['-u']) else: self._url = re.sub('/$', '', args['-u']) if '-x' in args: self._xval = args['-x'] if '-d' in args: self._pr.set_pr_level(self._pr.get_pr_level() | Print.PR_LVL_DBG) # get url_base from xval if self._xval: if self._xval in URL_BASE: self._url_base = list(URL_BASE[self._xval])[0] self._class = URL_BASE[self._xval][self._url_base] else: Base.print_exit('[WebImageCrawler] Error, invalid -x val!') # get class from url if self._url: base, num = self.get_url_base_and_num(self._url) if base: self._url_base = base # get class from url_base if all((not self._class, self._url_base)): for dict_url_base in URL_BASE.values(): if self._url_base == list(dict_url_base)[0]: self._class = dict_url_base[self._url_base] break return args
def get_url_content(cls, url, retry_times=3, view=True, path=None): if cls.url_is_https(url): content = cls.get_html(url=url, context=cls.CONTEXT_UNVERIFIED, retry_times=retry_times, view=view) else: content = cls.get_html(url=url, retry_times=retry_times, view=view) # save content to path. if all((content, path)): Path.make_path(path) f = '%s/%s' % (path, cls.convert_url_to_title(url)) if File.get_exname(f) != '.html': f = f + '.html' with open(f, 'w') as fd: fd.write(content) return content
def get_user_input(self): args = Base.get_user_input('hs:t:') if '-h' in args: Base.print_help(self.HELP_MENU) if '-s' in args: self._src = re.sub('/$', '', args['-s']) if '-t' in args: self._tgt = Path.get_abs_path(args['-t']) return args
def unzip_wiz(self): for f in self._fs: path = os.path.join( os.path.dirname(f).replace(self._src, self._dst), File.get_fname(f)) path = os.path.splitext(path)[0] Path.make_path(path) self.unzip_file(f, path) # remove small image. Image.remove_small_image(path) # move image. if os.path.exists('%s/index_files' % path): for ff in os.listdir('%s/index_files' % path): if Image.image_file('%s/index_files/%s' % (path, ff)): shutil.copyfile('%s/index_files/%s' % (path, ff), '%s/%s' % (path, ff)) # remove invalid files and dirs. shutil.rmtree('%s/index_files' % path) if os.path.exists('%s/index.html' % path): os.remove('%s/index.html' % path)
def get_user_input(self): args = Base.get_user_input('hs:t:v') # help if '-h' in args: Base.print_help(self.help_menu) # src path if '-s' in args: self._src = Path.get_abs_path(args['-s']) # dst path if '-t' in args: self._dst = Path.get_abs_path(args['-t']) # show if '-v' in args: self._show = True # start to check args. # start id is must be set, otherwise return.. if self._src == None: return False # next to start if _end is not set. if self._dst == None: self._dst = Path.get_current_path() print('warnning: no found -t, output to: %s' % self._dst) return True
' view info of webcontent.', ) path = None url = None df = None view = False wc = WebContent() pr = Print(wc.__class__.__name__) args = Base.get_user_input('hp:u:d:v') if '-h' in args: Base.print_help(HELP_MENU) if '-p' in args: path = Path.get_abs_path(args['-p']) if '-u' in args: url = args['-u'] if '-v' in args: view = True wc.pr.set_pr_level(0x07) if '-d' in args: df_funcs = { 'wget': wc.wget_url_file, 'rtrv': wc.retrieve_url_file, 'rget': wc.requests_get_url_file, 'uget': wc.urlopen_get_url_file, 'html': wc.get_url_content, } if all((args['-d'] in df_funcs.keys(), url)): df = df_funcs[args['-d']]
if File.get_exname(f) == '.pyc': os.remove(f) if show: print('remove: %s' % f) if dr: for d in dr: if d == '__pycache__': os.remove(d) if __name__ == '__main__': args = Base.get_user_input('hp:vc') # help if '-h' in args: Base.print_help(help_menu) # check path. if '-p' in args: if re.match('\.', args['-p']): path = re.sub('.', Path.get_current_path(), args['-p']) else: path = args['-p'] else: path = Path.get_current_path() # check show. if '-v' in args: show = True else: show = False # clean .pyc now. clean_pyc(path, show)
' -o path,rename,nz: rename image to order', ' path: path of images', ' rename: the format of image to be rename', ' nz: True is set %0d, False is set %d', ' -i img: show detail info of image file', ' img: the path of image file', ) Img = Image() pr = Print(Img.__class__.__name__) xval = None args = Base.get_user_input('hc:r:R:x:o:i:') if '-h' in args: Base.print_help(HELP_MENU) if '-c' in args: result = Img.image_file(Path.get_abs_path(args['-c'])) pr.pr_info(result) if '-r' in args: data = args['-r'].split(',') path = data[0] if len(data) >=2: w = data[1] h = data[2] Img.remove_small_image(path, int(w), int(h)) else: Img.remove_small_image(path) if '-R' in args: path = args['-R'] if Img.image_file(path): Img.reclaim_image(path) else:
def download_image(self, url, path): if self._dl_image: Path.make_path(path) self._dl_image(url, path, self.__dbg)