• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python termcolor.colored函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中termcolor.colored函数的典型用法代码示例。如果您正苦于以下问题:Python colored函数的具体用法?Python colored怎么用?Python colored使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了colored函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: getData

	def getData(self, url):
		
		data = Data()

		try:
			req = urllib2.Request(url, headers={'User-Agent' : "Magic Browser"})
			request = urllib2.urlopen(req)
			mime = request.info().getheader('Content-Type')		
			code = request.code

			print(colored('[' + mime + '] ' + url, 'yellow'))

			if code is 200:
				if 'text/html' in mime:

					html = request.read()
					data = self.parse(html, url)
					
				else:
					#ANALYSIS TYPE
					data.url = url
					data.type = mime

			elif code is 400:
				data.broke = True

		except UnicodeEncodeError as e :

			print(colored(e, 'red'))
			data.broke = True

		return data 
开发者ID:carloshpds,项目名称:BCC-2s13-PI4-web-crawler,代码行数:32,代码来源:data_extractor.py


示例2: hash_cracker

def hash_cracker(dict_file_name, hash_file_name):
    found = 0
    file_dict = open(dict_file_name, "r")
    passwords = file_dict.read().split('\n')
    file_hash = open(hash_file_name, "r")
    enc_hashes = file_hash.read().split('\n')
    print enc_hashes
    for pwd in passwords:
        try:
            for rec in enc_hashes:
                # print pwd.split(':')[1]
                test = sha1(pwd.split(':')[1] + rec.split(':')[1]).hexdigest()
                if pwd.split(':')[1] == 'admin':
                    print rec.split(':')[0]
                    print test
                if test == rec.split(':')[0]:
                    print colored("[-] Password Found for password_sha " + rec.split(':')[0] + " : " + pwd)
                    found = 1
                    break
                else:
                    pass
                    if found == 1:
                        break
        except:
            pass
开发者ID:VitoYane,项目名称:Nosql-Exploitation-Framework,代码行数:25,代码来源:couchattacks.py


示例3: server

def server():
	global connection
	global board
	global newTiles
	global WAIT
	# Create a TCP/IP socket
	server_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	# Bind the socket to the port
	if int(sys.argv[1]) == 1:
		server_address = ('localhost', PORT_NUMBER_2)
	else:
		server_address = ('localhost', PORT_NUMBER_1)
	print >>sys.stderr, 'starting up on %s port %s' % server_address
	server_sock.bind(server_address)
	# Listen for incoming connections
	server_sock.listen(1)

	while True:
	    # Wait for a connection
	    print >>sys.stderr, 'waiting for a connection'
	    connection, client_address = server_sock.accept()
	    try:
	        print >>sys.stderr, 'connection from', client_address
	        state = "NORMAL"
	        # Receive the data in small chunks and retransmit it
	        while True:
	            data = connection.recv(1000)
	            # print >>sys.stderr, 'received "%s"' % data
	            if data:
	            	if data == "BOARD" or data == "INITIAL" or data == "NEW_TILES":
	            		state = data
	            		print "STATE: %s"%state
	            	else:
		            	if state == "BOARD":
		            		board = pickle.loads(data)
		            		print colored("The other player has made a move",'red')
		            		printBoard()
		            		print "received board"
		            		WAIT = False
		            	elif state == "INITIAL":
		            		board = pickle.loads(data)
		            		print "received initial"
		            		printBoard()
		            	elif state == "NEW_TILES":
		            		newTiles = pickle.loads(data)
		            		print newTiles
		            		print "received new tiles"
		            	state = "NORMAL"
		            	print "STATE: NORMAL"
	            else:
	                break
	    except KeyboardInterrupt:
	    	print "Closed connection on server"
	    	connection.close()
	    	break     
	    finally:
	        # Clean up the connection
	    	print "Closed connection on server"
	        connection.close()
	        break
开发者ID:justinklchan,项目名称:collaborative2048,代码行数:60,代码来源:singlePlayer2048.py


示例4: process

    def process(self, msg, kwargs):
        if self.extra is None:
            return u'{}'.format(msg), kwargs

        if 'module' in self.extra.keys():
            if len(self.extra['module']) > 8:
                self.extra['module'] = self.extra['module'][:8] + '...'

        #If the logger is being called when hooking the 'options' module function
        if len(self.extra) == 1 and ('module' in self.extra.keys()):
            return u'{:<64} {}'.format(colored(self.extra['module'], 'cyan', attrs=['bold']), msg), kwargs

        #If the logger is being called from CMEServer
        if len(self.extra) == 2 and ('module' in self.extra.keys()) and ('host' in self.extra.keys()):
            return u'{:<24} {:<39} {}'.format(colored(self.extra['module'], 'cyan', attrs=['bold']), self.extra['host'], msg), kwargs

        #If the logger is being called from a protocol
        if 'module' in self.extra.keys():
            module_name = colored(self.extra['module'], 'cyan', attrs=['bold'])
        else:
            module_name = colored(self.extra['protocol'], 'blue', attrs=['bold'])

        return u'{:<24} {:<15} {:<6} {:<16} {}'.format(module_name,
                                                    self.extra['host'],
                                                    self.extra['port'],
                                                    self.extra['hostname'].decode('utf-8') if self.extra['hostname'] else 'NONE',
                                                    msg), kwargs
开发者ID:0xe7,项目名称:CrackMapExec,代码行数:27,代码来源:logger.py


示例5: one

def one(expected, champs, display, shuffle = False):
    global count, total
    vm = VM()
    vm.add(champs)

    if shuffle:
        vm.shuffle()

    if display:
        util.tprint('Battle', '%s / %s' % (colored('%d' % (count), 'yellow'), colored('%d' % (total), 'yellow')))
        util.tprint('Champions', ', '.join([colored(champ.champion.name, 'blue', attrs = ['bold']) for champ in vm.champions]))
    count += 1
    winner = vm.launch(stdout = PIPE)
    report = None
    if winner:
        if display:
            if winner.champion.filename == expected.filename:
                color = 'green'
            else:
                color = 'red'
            util.tprint('Winner', colored(winner.champion.name, color, attrs = ['bold']))
        report = Report(champs, winner.champion)

    if display:
        print ''
    return report
开发者ID:KokaKiwi,项目名称:epitech.corewar-py,代码行数:26,代码来源:blindtest.py


示例6: main

def main(username):
    google_api = vault.get_key('google_api')
    if google_api != None:
        API_SERVICE_NAME = "youtube"
        API_VERSION = "v3"
        max_results = 50
        video_ids = []
        service = build(API_SERVICE_NAME, API_VERSION,
                        developerKey=google_api)
        channel_id = find_channel_by_username(service,
                                              part='snippet',
                                              maxResults=max_results,
                                              q=username)
        if channel_id is not None:
            channel_details = get_channel_details(username,
                                                  service,
                                                  part='snippet,contentDetails,statistics',
                                                  id=channel_id['Channel ID'])

            channel_analysis = analyze_activity(service,
                                                part='snippet,contentDetails',
                                                channelId=channel_id['Channel ID'],
                                                maxResults=max_results)
            return [ channel_id, channel_details, channel_analysis ]
        else:
            return [ colored(style.BOLD +'[!] Error: Channel not found for ' +
                             username + '\n' + style.END, 'red') ]
    else:
        return [ colored(style.BOLD + '[!] Error: No Google API key found. Skipping' +
                         style.END, 'red') ]
开发者ID:dvopsway,项目名称:datasploit,代码行数:30,代码来源:username_youtubedetails.py


示例7: list_letter

def list_letter(aset, vb=False, output=False):
    '''list words by letter, from a-z (ingore case).'''

    conn = sqlite3.connect(os.path.join(DEFAULT_PATH, 'word.db'))
    curs = conn.cursor()
    try:
        if not vb:
            curs.execute('SELECT name, pr FROM Word WHERE aset = "%s"' % aset)
        else:
            curs.execute('SELECT expl, pr FROM Word WHERE aset = "%s"' % aset)
    except Exception as e:
        print(colored('something\'s wrong, catlog is from A to Z', 'red'))
        print(e)
    else:
        if not output:
            print(colored(format(aset, '-^40s'), 'green'))
        else:
            print(format(aset, '-^40s'))

        for line in curs.fetchall():
            expl = line[0]
            pr = line[1]
            print('\n' + '=' * 40 + '\n')
            if not output:
                print(colored('★ ' * pr, 'red', ), colored('☆ ' * (5 - pr), 'yellow'), sep='')
                colorful_print(expl)
            else:
                print('★ ' * pr + '☆ ' * (5 - pr))
                normal_print(expl)
    finally:
        curs.close()
        conn.close()
开发者ID:louisun,项目名称:iSearch,代码行数:32,代码来源:isearch.py


示例8: bye

def bye():
    global flag
    global op_stop
    flag = False
    op_stop = True
    print termcolor.colored("Bye", "cyan")
    print termcolor.colored("有任何建议欢迎与我联系: [email protected]", "cyan")
开发者ID:ChaoSBYNN,项目名称:zhihu-terminal,代码行数:7,代码来源:zhihu.py


示例9: display_time

    def display_time(self):
        length = len(self.TITLE)
        while True:
            if self.q == 1:  # 退出
                break
            if self.song_time >= 0 and self.douban.playingsong:
                minute = int(self.song_time) / 60
                sec = int(self.song_time) % 60
                show_time = str(minute).zfill(2) + ':' + str(sec).zfill(2)

                self.volume = self.get_volume()  # 获取音量
                self.TITLE = self.TITLE[:length - 1] + '  ' + self.douban.playingsong['kbps'] + 'kbps  ' + colored(show_time, 'cyan') + '  rate: ' + colored(self.rate[int(round(self.douban.playingsong['rating_avg'])) - 1], 'red') + '  vol: '
                if self.is_muted:
                    self.TITLE += '✖'
                else:
                    self.TITLE += self.volume.strip() + '%'
                if self.loop:
                    self.TITLE += '  ' + colored('↺', 'red')
                else:
                    self.TITLE += '  ' + colored('→', 'red')
                self.TITLE += '\r'
                self.display()
                if not self.pause:
                    self.song_time -= 1
            else:
                self.TITLE = self.TITLE[:length]
            time.sleep(1)
开发者ID:fusky,项目名称:douban.fm,代码行数:27,代码来源:douban.py


示例10: __init__

 def __init__(self):
   # Load the trained models
   print(colored('Loading CLF models','magenta'))
   self.topicHasher = texthasher.safe_load(TEXT_VECTORIZER_PATH,stop_words=[])
   self.tagHasher   = taghasher.safe_load(TAG_HASHER_PATH,n_feature=256)
   self.clf         = cluster.safe_load(CLF_PATH,method=None,n_features=256)
   print(colored('[DONE] ','green'),'CLF models loaded')
开发者ID:starcolon,项目名称:pantip-libr,代码行数:7,代码来源:classify.py


示例11: loadsession

def loadsession():
    global session
    try:
        session.cookies.load(ignore_discard="true")
    except:
        termcolor.colored("加载异常", "red")
        pass
开发者ID:ChaoSBYNN,项目名称:zhihu-terminal,代码行数:7,代码来源:zhihu.py


示例12: pty_based_auth

def pty_based_auth(auth_backend, pty):
    """
    Show a username/password login prompt.
    Return username when authentication succeeded.
    """
    tries = 0
    while True:
        # Password authentication required for this session?
        sys.stdout.write('\033[2J\033[0;0H') # Clear screen
        sys.stdout.write(colored('Please authenticate\r\n\r\n', 'cyan'))

        if tries:
            sys.stdout.write(colored('  Authentication failed, try again\r\n', 'red'))

        try:
            console = Console(pty)
            username = console.input('Username', False)
            password = console.input('Password', True)
        except NoInput:
            raise NotAuthenticated

        if auth_backend.authenticate(username, password):
            sys.stdout.write(colored(' ' * 40 + 'Authentication successful\r\n\r\n', 'green'))
            return username
        else:
            tries += 1
            if tries == 3:
                raise NotAuthenticated
开发者ID:Duologic,项目名称:python-deployer,代码行数:28,代码来源:telnet_server.py


示例13: show_telemetry

def show_telemetry(tel):
    output = [] 

    for k, v in tel.iteritems():
        if k == 'register':
            color = 'blue'

        elif k == 'density':
            color = 'red'

        elif k == 'harmonicity':
            color = 'green'

        elif k == 'roughness':
            color = 'cyan'

        elif k == 'pace':
            color = 'yellow'

        else:
            color = 'white'

        if k == 'name':
            output += [ colored(' '.join(v), color) ]
        else:
            output += [ colored('%s: %.2f' % (k[:3], v), color) ]

    output = ' | '.join(output)
    dsp.log(output)
开发者ID:hecanjog,项目名称:nomadpalace-wmse,代码行数:29,代码来源:blue.py


示例14: search_replace_with_prompt

def search_replace_with_prompt(fpath, txt1, txt2, force=False):
	""" Search and replace all txt1 by txt2 in the file with confirmation"""

	from termcolor import colored
	with open(fpath, 'r') as f:
		content = f.readlines()

	tmp = []
	for c in content:
		if c.find(txt1) != -1:
			print fpath
			print  colored(txt1, 'red').join(c[:-1].split(txt1))
			a = ''
			if force:
				c = c.replace(txt1, txt2)
			else:
				while a.lower() not in ['y', 'n', 'skip']:
					a = raw_input('Do you want to Change [y/n/skip]?')
				if a.lower() == 'y':
					c = c.replace(txt1, txt2)
				elif a.lower() == 'skip':
					return 'skip'
		tmp.append(c)

	with open(fpath, 'w') as f:
		f.write(''.join(tmp))
	print colored('Updated', 'green')
开发者ID:gowrav-vishwakarma,项目名称:wnframework,代码行数:27,代码来源:wnf.py


示例15: play

    def play(self):
        self.lrc_dict = {}  # 歌词清空
        if not self.loop:
            self.douban.get_song()
        if self.is_muted:  # 静音状态
            subprocess.Popen('echo "mute {mute}" > {fifo}'.format(fifo=self.mplayer_controller, mute=1), shell=True, stdin=subprocess.PIPE)
        song = self.douban.playingsong
        self.song_time = song['length']
        # 是否是红心歌曲
        if song['like'] == 1:
            love = self.love
        else:
            love = ''
        title = colored(song['title'], 'green')
        albumtitle = colored(song['albumtitle'], 'yellow')
        artist = colored(song['artist'], 'white')
        self.SUFFIX_SELECTED = (love + ' ' + title + ' • ' + albumtitle + ' • ' + artist + ' ' + song['public_time']).replace('\\', '')

        cmd = 'mplayer -slave -input file={fifo} {song_url} >/dev/null 2>&1'
        self.p = subprocess.Popen(cmd.format(fifo=self.mplayer_controller, song_url=song['url']), shell=True, stdin=subprocess.PIPE)  # subprocess.PIPE防止继承父进程
        self.pause = False
        self.display()
        self.notifySend()
        if self.lrc_display:  # 获取歌词
            self.lrc_dict = self.douban.get_lrc()
            if not self.lrc_dict:  # 歌词获取失败,关闭歌词界面
                self.lrc_display = 0
        self.start = 1
开发者ID:fusky,项目名称:douban.fm,代码行数:28,代码来源:douban.py


示例16: informer

 def informer(self,_type,msg,debug=True,log=False,color='green',type_color="cyan",attrs=["bold"]):
     if debug :print '[ '+colored(_type,type_color,attrs=attrs)+' ]'" :"+colored(msg,color,attrs=attrs)
     if log:
         try:
             self.log_file.write(msg)
         except Exception,e:
             print colored(e,'red','on_white',attrs=['bold'])
开发者ID:Srbpunyani,项目名称:yoolotto,代码行数:7,代码来源:winning_common_importer.py


示例17: xap_doc_sim_for_pmids

def xap_doc_sim_for_pmids(pmids,n_terms=100):
	enq=xapian.Enquire(database)
	rset=xapian.RSet()
	for a in pmids:
		try: 
			database.get_document(a)
		except xapian.DocNotFoundError:
			continue
		rset.add_document(a)
	if rset.empty():
		print colored("No documents for set %s"%(str(pmids)),'red')
		return {},[]
	eset=enq.get_eset(n_terms,rset) # Number of terms in the eset
	# q=xapian.Query(xapian.Query.OP_OR,eset.begin(),eset.end())
	terms=[x[0] for x in eset.items]
	print ";".join(terms[:10])
	q=xapian.Query(xapian.Query.OP_OR,terms)
	enq.set_query(q)
	res=enq.get_mset(0,database.get_doccount())
	weighted_docs=[(r.docid,r.weight) for r in res]
	#normalize the weights to [0,1]
	max_w=max([x[1] for x in weighted_docs])

	weighted_docs=[(x[0],x[1]*1.0/max_w) for x in weighted_docs]

	sorted_results=dict(weighted_docs)
	return sorted_results,terms
开发者ID:massyah,项目名称:LINK,代码行数:27,代码来源:compare_ir_scheme_xapian.py


示例18: search_database

def search_database(word):
    '''offline search.'''

    conn = sqlite3.connect(os.path.join(DEFAULT_PATH, 'word.db'))
    curs = conn.cursor()
    curs.execute(r'SELECT expl, pr FROM Word WHERE name LIKE "%s%%"' % word)
    res = curs.fetchall()
    if res:
        print(colored(word + ' 在数据库中存在', 'white', 'on_green'))
        print()
        print(colored('★ ' * res[0][1], 'red'), colored('☆ ' * (5 - res[0][1]), 'yellow'), sep='')
        colorful_print(res[0][0])
    else:
        print(colored(word + ' 不在本地,从有道词典查询', 'white', 'on_red'))
        search_online(word)
        input_msg = '若存入本地,请输入优先级(1~5) ,否则 Enter 跳过\n>>> '
        if sys.version_info[0] == 2:
            add_in_db_pr = raw_input(input_msg)
        else:
            add_in_db_pr = input(input_msg)

        if add_in_db_pr and add_in_db_pr.isdigit():
            if(int(add_in_db_pr) >= 1 and int(add_in_db_pr) <= 5):
                add_word(word, int(add_in_db_pr))
                print(colored('单词 {word} 已加入数据库中'.format(word=word), 'white', 'on_red'))
    curs.close()
    conn.close()
开发者ID:louisun,项目名称:iSearch,代码行数:27,代码来源:isearch.py


示例19: remap_keys

def remap_keys(old_filename, new_filename, output_folder):
    """
    Create a script to remap bibtex keys from one .bib file to another.

    This function uses the edit distance on filenames generated from a bitex entry
    to compare entries together, and greedily matches old entries to new entries.
    """
    old_db = utils.read_bib_file(old_filename, homogenize=False)
    new_db = utils.read_bib_file(new_filename, homogenize=False)
    old_list = {}
    new_list = {}
    subst = {}
    for entry in new_db.entries:
        name = nomenclature.gen_filename(entry)
        new_list[name] = entry['ID']
    for entry in old_db.entries:
        name = nomenclature.gen_filename(entry)
        if name in new_list.keys():
            subst[entry['ID']] = new_list[name]
            del new_list[name]
        else:
            old_list[name] = entry['ID']
    for name, bibkey in new_list.items():
        match, score = utils.most_similar_filename(name, old_list.keys())
        if score < 0.90:
            print(termcolor.colored("Warning: potentially incorrect substitution:", 'yellow', attrs=["bold"]))
            print(termcolor.colored('-', 'red') + match)
            print(termcolor.colored('+', 'green') + name)
        subst[old_list[match]] = bibkey
    utils.write_remap_script(subst, output_folder)
开发者ID:jdumas,项目名称:autobib,代码行数:30,代码来源:autobib.py


示例20: list_latest

def list_latest(limit, vb=False, output=False):
    '''list words by latest time you add to database.'''

    conn = sqlite3.connect(os.path.join(DEFAULT_PATH, 'word.db'))
    curs = conn.cursor()
    try:
        if not vb:
            curs.execute('SELECT name, pr, addtime FROM Word ORDER by datetime(addtime) DESC LIMIT  %d' % limit)
        else:
            curs.execute('SELECT expl, pr, addtime FROM Word ORDER by datetime(addtime) DESC LIMIT  %d' % limit)
    except Exception as e:
        print(e)
        print(colored('something\'s wrong, please set the limit', 'red'))
    else:
        for line in curs.fetchall():
            expl = line[0]
            pr = line[1]
            print('\n' + '=' * 40 + '\n')
            if not output:
                print(colored('★ ' * pr, 'red'), colored('☆ ' * (5 - pr), 'yellow'), sep='')
                colorful_print(expl)
            else:
                print('★ ' * pr + '☆ ' * (5 - pr))
                normal_print(expl)
    finally:
        curs.close()
        conn.close()
开发者ID:louisun,项目名称:iSearch,代码行数:27,代码来源:isearch.py



注:本文中的termcolor.colored函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python termcolor.colorfunc函数代码示例发布时间:2022-05-27
下一篇:
Python ui.parse_cli_args函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap