def get_user_opt(self): args = Base.get_user_input('hcf:r:s:t:') if r'-h' in args: Base.print_help(self.help_menu) if r'-c' in args: self._combine_files = True if r'-f' in args: fmt = args['-f'].lower() if fmt == TYPE_TXT or fmt == TYPE_CSV: self._fmt = fmt else: Base.print_exit("Error, unsupport format!") if r'-r' in args: if args['-r'] == r'True': self._sort_reverse = True else: self._sort_reverse = False if r'-s' in args: # set _src to list if self._src == None: self._src = list() # get src files fs = self.get_src_files(os.path.abspath(args['-s'])) if fs: # add fs to _src for f in fs: self._src.append(f) if r'-t' in args: ftype = File.get_filetype(os.path.abspath(args['-t'])) if ftype in [TYPE_TXT, TYPE_CSV]: self._tgt = os.path.abspath(args['-t']) self._combine_files = True self._fmt = ftype else: self._tgt = os.path.abspath(args['-t'])
def main(): fid, sid = get_face_image() if fid == None or sid == None: Base.print_exit('Error, no found id image.') x_appid = 'wsr00030d4d@ch407c0f6177e2477400' api_key = '' url = 'http://api.xfyun.cn/v1/service/v1/image_identify/face_verification' x_time = str(int(time.time())) param = {'auto_rotate': True} param = json.dumps(param) x_param = base64.b64encode(param.encode('utf-8')) m2 = hashlib.md5() m2.update(str(api_key + x_time + str(x_param))) x_checksum = m2.hexdigest() x_header = { 'X-Appid': x_appid, 'X-CurTime': x_time, 'X-CheckSum': x_checksum, 'X-Param': x_param, } with open(fid, 'rb') as f: f1 = f.read() with open(sid, 'rb') as f: f2 = f.read() f1_base64 = str(base64.b64encode(f1)) f2_base64 = str(base64.b64encode(f2)) data = { 'first_image': f1_base64, 'second_image': f2_base64, } req = requests.post(url, data=data, headers=x_header) result = str(req.content) print(result) return
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 main(self): self.get_user_input() if not self._src: Base.print_exit('no -s, -h for help!') if not self._tgt: self._tgt = '%s/%s.txt' % (self._src, os.path.basename(self._src)) # collect urls. self.collect_web_url()
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 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 main(self): # get user options. self.get_user_opt() # check args. self.check_opt_args() # start to process data. if self._src == None or len(self._src) == 0: Base.print_exit('No found .ics, do nothing.') elif self._combine_files == True: self.combine_fs_handler() else: self.fs_handler()
def print_help(): help_menu = ( '==================================', ' help menu', '==================================', 'option: -x xxx', ' -x xxx: xxxx', ) # print for txt in help_menu: print(txt) Base.print_exit()
def format_output(self): if len(self._events) == 0: return # sort all of events. self._events.sort(key = lambda event: event._date_s, reverse=self._sort_reverse) # output if self._fmt == TYPE_TXT: self.save_to_txt() elif self._fmt == TYPE_CSV: self.save_to_csv() elif self._fmt == None: self.print_ics_contents() else: print('Error, use -f txt/csv to set format output\n') Base.print_help(self.help_menu) # clear all of events. self._events = list()
def get_user_input(self, args=None): if not args: args = Base.get_user_input('hu:n:p:x:m:i:R:t:vdD') if '-h' in args: Base.print_help(self.help_menu) if '-u' in args: self._url = re.sub('/$', '', args['-u']) if '-n' in args: self._num = int(args['-n']) if '-p' in args: self._path = os.path.abspath(args['-p']) if '-R' in args: self._ex_re_image_url = os.path.abspath(args['-R']) if '-t' in args: try: n = int(args['-t']) except ValueError as e: Base.print_exit('%s, -h for help!' % str(e)) if n: self._thread_max = n if '-v' in args: self._view = True self._pr.set_pr_level(self._pr.get_pr_level() | Print.PR_LVL_WARN) if '-x' in args: self._xval = args['-x'] if '-m' in args: dl_image_funcs = { 'wget': self.wget_url_image, 'rtrv' : self.retrieve_url_image, 'rget' : self.requests_get_url_image, 'uget' : self.urlopen_get_url_image, } if args['-m'] in dl_image_funcs.keys(): self._dl_image = dl_image_funcs[args['-m']] if '-d' in args: self.__dbg = 1 self._pr.set_pr_level(self._pr.get_pr_level() | Print.PR_LVL_ALL ) if '-D' in args: self.__dbg = 2 self._pr.set_pr_level(self._pr.get_pr_level() | Print.PR_LVL_DBG) WebContent.pr.set_pr_level(self._pr.get_pr_level() | Print.PR_LVL_DBG) # check url if self._url: base, num = WebContent.get_url_base_and_num(self._url) if base: self._url_base = base if num: self._url = num self._pr.pr_dbg('get base: %s, url: %s' % (base, self._url)) else: Base.print_exit('[WebImage] Error, no set url, -h for help!') if self._url_base: www_com = re.match('http[s]?://.+\.(com|cn|net)', self._url_base) if www_com: self._com = www_com.group() return args
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
def main(self): args = Base.get_user_input('harLPpgSBbu') if '-h' in args: Base.print_help(self.help_menu) if '-a' in args: self.ibus_add_to_wubi_love98_db() if '-r' in args: self.ibus_restart() if '-L' in args: self.ibus_list_engine() if '-P' in args: self.ibus_set('sunpinyin') if '-p' in args: self.ibus_set('pinyin') if '-g' in args: self.ibus_set('googlepinyin') if '-S' in args: self.ibus_set('wubi98') if '-B' in args: self.ibus_set('wubi-haifeng86') if '-b' in args: self.ibus_set('wubi-jingdian86') if '-u' in args: self.ibus_update_wubi_love98_db()
' rget: using requests to download file', ' uget: using urlopen to download file', ' html: download html of url' ' -v:', ' 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,
for rt, dr, fs in os.walk(path): if fs: for f in fs: f = os.path.join(rt, f) 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:
' -r path,(w,d): remove small size of images', ' path: path of dir or file', ' -R path: reclaim image format', ' path: path of dir or file', ' -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:
def main(self): args = Base.get_user_input('h') if '-h' in args: self.print_help()
def main(): args = Base.get_user_input('h') if '-h' in args: print_help()