Python colorama.Back.RESET Examples
The following are 22
code examples of colorama.Back.RESET().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
colorama.Back
, or try the search function
.
Example #1
Source File: colors.py From chepy with GNU General Public License v3.0 | 6 votes |
def red(s: str) -> str: # pragma: no cover """Red color string if tty Args: s (str): String to color Returns: str: Colored string Examples: >>> from chepy.modules.internal.colors import red >>> print(RED("some string")) """ if sys.stdout.isatty(): return Fore.RED + s + Fore.RESET else: return s
Example #2
Source File: colors.py From chepy with GNU General Public License v3.0 | 6 votes |
def blue(s: str) -> str: # pragma: no cover """Blue color string if tty Args: s (str): String to color Returns: str: Colored string Examples: >>> from chepy.modules.internal.colors import blue >>> print(BLUE("some string")) """ if sys.stdout.isatty(): return Fore.BLUE + s + Fore.RESET else: return s
Example #3
Source File: colors.py From chepy with GNU General Public License v3.0 | 6 votes |
def cyan(s: str) -> str: # pragma: no cover """Cyan color string if tty Args: s (str): String to color Returns: str: Colored string Examples: >>> from chepy.modules.internal.colors import cyan >>> print(CYAN("some string")) """ if sys.stdout.isatty(): return Fore.CYAN + s + Fore.RESET else: return s
Example #4
Source File: colors.py From chepy with GNU General Public License v3.0 | 6 votes |
def green(s: str) -> str: # pragma: no cover """Green color string if tty Args: s (str): String to color Returns: str: Colored string Examples: >>> from chepy.modules.internal.colors import green >>> print(GREEN("some string")) """ if sys.stdout.isatty(): return Fore.GREEN + s + Fore.RESET else: return s
Example #5
Source File: colors.py From chepy with GNU General Public License v3.0 | 6 votes |
def magenta(s: str) -> str: # pragma: no cover """Magenta color string if tty Args: s (str): String to color Returns: str: Colored string Examples: >>> from chepy.modules.internal.colors import magenta >>> print(MAGENTA("some string")) """ if sys.stdout.isatty(): return Fore.MAGENTA + s + Fore.RESET else: return s
Example #6
Source File: __init__.py From podfox with GNU General Public License v3.0 | 5 votes |
def pretty_print_episodes(feed): format_str = Fore.GREEN + '{0:40} |' format_str += Fore.BLUE + ' {1:20}' + Fore.RESET + Back.RESET for e in feed['episodes'][:20]: status = 'Downloaded' if e['downloaded'] else 'Not Downloaded' print(format_str.format(e['title'][:40], status))
Example #7
Source File: print_nodes.py From pyta with GNU General Public License v3.0 | 5 votes |
def _wrap_color(code_string): """Wrap key parts in styling and resets. Stying for each key part from, (col_offset, fromlineno) to (end_col_offset, end_lineno). Note: use this to set color back to default (on mac, and others?): Style.RESET_ALL + Style.DIM """ ret = Style.BRIGHT + Fore.WHITE + Back.BLACK ret += code_string ret += Style.RESET_ALL + Style.DIM + Fore.RESET + Back.RESET return ret
Example #8
Source File: __init__.py From podfox with GNU General Public License v3.0 | 5 votes |
def pretty_print_feeds(feeds): format_str = Fore.GREEN + '{0:45.45} |' format_str += Fore.BLUE + ' {1:40}' + Fore.RESET + Back.RESET print(format_str.format('title', 'shortname')) print('='*80) for feed in feeds: format_str = Fore.GREEN + '{0:40.40} {1:3d}{2:1.1} |' format_str += Fore.BLUE + ' {3:40}' + Fore.RESET + Back.RESET feed = sort_feed(feed) amount = len([ep for ep in feed['episodes'] if ep['downloaded']]) dl = '' if feed['episodes'][0]['downloaded'] else '*' print(format_str.format(feed['title'], amount, dl, feed['shortname']))
Example #9
Source File: __init__.py From podfox with GNU General Public License v3.0 | 5 votes |
def print_green(s): print(Fore.GREEN + s + Fore.RESET)
Example #10
Source File: __init__.py From podfox with GNU General Public License v3.0 | 5 votes |
def print_err(err): print(Fore.RED + Style.BRIGHT + err + Fore.RESET + Back.RESET + Style.RESET_ALL, file=sys.stderr)
Example #11
Source File: color.py From domained with GNU General Public License v3.0 | 5 votes |
def colored(msg, fore=Fore.RESET, back=Back.RESET): print("{}{}{}".format(fore, back, msg))
Example #12
Source File: errorAnalysis.py From stanford-ctc with Apache License 2.0 | 5 votes |
def disp_err_corr(hyp_corr, ref_corr): hyp_str = '' ref_str = '' assert len(hyp_corr) == len(ref_corr) for k in xrange(len(hyp_corr)): if hyp_corr[k] == '[space]': hc = ' ' elif hyp_corr[k] == '<ins>': hc = Back.GREEN + ' ' + Back.RESET else: hc = hyp_corr[k] if ref_corr[k] == '[space]': rc = ' ' elif ref_corr[k] == '<del>': rc = Back.RED + ' ' + Back.RESET else: rc = ref_corr[k] if hc != rc and len(hc) == 1 and len(rc) == 1: hc = Back.BLUE + Fore.BLACK + hc + Fore.RESET + Back.RESET rc = Back.BLUE + Fore.BLACK + rc + Fore.RESET + Back.RESET hyp_str += hc ref_str += rc print hyp_str print ref_str
Example #13
Source File: passhole.py From passhole with GNU General Public License v3.0 | 5 votes |
def show(args): """Print out the contents of an entry to console""" kp = open_database(**vars(args)) entry = get_entry(kp, args.path) # show specified field if args.field: # handle lowercase field input gracefully field = get_field(entry, args.field) print(entry._get_string_field(field), end='') # otherwise, show all fields else: print(green("Title: ") + (entry.title or '')) print(green("UserName: ") + (entry.username or '')) print( green("Password: ") + Fore.RED + Back.RED + (entry.password or '') + Fore.RESET + Back.RESET ) print(green("URL: ") + (entry.url or '')) for field_name, field_value in entry.custom_properties.items(): print(green("{}: ".format(field_name)) + str(field_value or '')) print(green("Created: ") + entry.ctime.isoformat()) print(green("Modified: ") + entry.mtime.isoformat())
Example #14
Source File: view.py From oh-my-stars with MIT License | 5 votes |
def _highlight_keywords(self, text, keywords, fore_color=Fore.GREEN): if keywords and self.enable_color: for keyword in keywords: regex = re.compile(keyword, re.I | re.U | re.M) color = fore_color + Back.RED + Style.BRIGHT text = regex.sub( color + keyword + Back.RESET + Style.NORMAL, text) return text
Example #15
Source File: view.py From oh-my-stars with MIT License | 5 votes |
def _print(self, text='', fore_color=Fore.WHITE, end=' '): if self.enable_color: print(fore_color + text, end='') print(Fore.RESET + Back.RESET + Style.RESET_ALL, end=end) else: print(text, end=end)
Example #16
Source File: colors.py From chepy with GNU General Public License v3.0 | 5 votes |
def yellow_background(s: str) -> str: # pragma: no cover """Yellow color string if tty Args: s (str): String to color Returns: str: Colored string """ if sys.stdout.isatty(): return Back.YELLOW + Fore.BLACK + s + Fore.RESET + Back.RESET else: return s
Example #17
Source File: config.py From scrapple with MIT License | 5 votes |
def traverse_next(page, nextx, results, tabular_data_headers=[], verbosity=0): """ Recursive generator to traverse through the next attribute and \ crawl through the links to be followed. :param page: The current page being parsed :param next: The next attribute of the current scraping dict :param results: The current extracted content, stored in a dict :return: The extracted content, through a generator """ for link in page.extract_links(selector=nextx['follow_link']): if verbosity > 0: print('\n') print(Back.YELLOW + Fore.BLUE + "Loading page ", link.url + Back.RESET + Fore.RESET, end='') r = results.copy() for attribute in nextx['scraping'].get('data'): if attribute['field'] != "": if verbosity > 1: print("\nExtracting", attribute['field'], "attribute", sep=' ', end='') r[attribute['field']] = link.extract_content(**attribute) if not nextx['scraping'].get('table'): result_list = [r] else: tables = nextx['scraping'].get('table', []) for table in tables: table.update({ 'result': r, 'verbosity': verbosity }) table_headers, result_list = link.extract_tabular(**table) tabular_data_headers.extend(table_headers) if not nextx['scraping'].get('next'): for r in result_list: yield (tabular_data_headers, r) else: for nextx2 in nextx['scraping'].get('next'): for tdh, result in traverse_next(link, nextx2, r, tabular_data_headers=tabular_data_headers, verbosity=verbosity): yield (tdh, result)
Example #18
Source File: genconfig.py From scrapple with MIT License | 5 votes |
def execute_command(self): """ The genconfig command depends on predefined `Jinja2 <http://jinja.pocoo.org/>`_ \ templates for the skeleton configuration files. Taking the --type argument from the \ CLI input, the corresponding template file is used. Settings for the configuration file, like project name, selector type and URL \ are taken from the CLI input and using these as parameters, the template is \ rendered. This rendered JSON document is saved as <project_name>.json. """ print(Back.GREEN + Fore.BLACK + "Scrapple Genconfig") print(Back.RESET + Fore.RESET) directory = os.path.join(scrapple.__path__[0], 'templates', 'configs') with open(os.path.join(directory, self.args['--type'] + '.txt'), 'r') as f: template_content = f.read() print("\n\nUsing the", self.args['--type'], "template\n\n") template = Template(template_content) settings = { 'projectname': self.args['<projectname>'], 'selector_type': self.args['--selector'], 'url': self.args['<url>'], 'levels': int(self.args['--levels']) } rendered = template.render(settings=settings) with open(self.args['<projectname>'] + '.json', 'w') as f: rendered_data = json.loads(rendered) json.dump(rendered_data, f, indent=3) print(Back.WHITE + Fore.RED + self.args['<projectname>'], ".json has been created" \ + Back.RESET + Fore.RESET, sep="")
Example #19
Source File: generate.py From scrapple with MIT License | 5 votes |
def execute_command(self): """ The generate command uses `Jinja2 <http://jinja.pocoo.org/>`_ templates \ to create Python scripts, according to the specification in the configuration \ file. The predefined templates use the extract_content() method of the \ :ref:`selector classes <implementation-selectors>` to implement linear extractors \ and use recursive for loops to implement multiple levels of link crawlers. This \ implementation is effectively a representation of the traverse_next() \ :ref:`utility function <implementation-utils>`, using the loop depth to \ differentiate between levels of the crawler execution. According to the --output_type argument in the CLI input, the results are \ written into a JSON document or a CSV document. The Python script is written into <output_filename>.py - running this file \ is the equivalent of using the Scrapple :ref:`run command <command-run>`. """ print(Back.GREEN + Fore.BLACK + "Scrapple Generate") print(Back.RESET + Fore.RESET) directory = os.path.join(scrapple.__path__[0], 'templates', 'scripts') with open(os.path.join(directory, 'generate.txt'), 'r') as f: template_content = f.read() template = Template(template_content) try: with open(self.args['<projectname>'] + '.json', 'r') as f: config = json.load(f) if self.args['--output_type'] == 'csv': from scrapple.utils.config import extract_fieldnames config['fields'] = str(extract_fieldnames(config)) config['output_file'] = self.args['<output_filename>'] config['output_type'] = self.args['--output_type'] rendered = template.render(config=config) with open(self.args['<output_filename>'] + '.py', 'w') as f: f.write(rendered) print(Back.WHITE + Fore.RED + self.args['<output_filename>'], \ ".py has been created" + Back.RESET + Fore.RESET, sep="") except IOError: print(Back.WHITE + Fore.RED + self.args['<projectname>'], ".json does not ", \ "exist. Use ``scrapple genconfig``." + Back.RESET + Fore.RESET, sep="")
Example #20
Source File: web.py From scrapple with MIT License | 5 votes |
def execute_command(self): """ The web command runs the Scrapple web interface through a simple \ `Flask <http://flask.pocoo.org>`_ app. When the execute_command() method is called from the \ :ref:`runCLI() <implementation-cli>` function, it starts of two simultaneous \ processes : - Calls the run_flask() method to start the Flask app on port 5000 of localhost - Opens the web interface on a web browser The '/' view of the Flask app, opens up the Scrapple web interface. This \ provides a basic form, to fill in the required configuration file. On submitting \ the form, it makes a POST request, passing in the form in the request header. \ This form is passed to the form_to_json() \ :ref:`utility function <implementation-utils>`, where the form is converted into \ the resultant JSON configuration file. Currently, closing the web command execution requires making a keyboard interrupt \ on the command line after the web interface has been closed. """ print(Back.GREEN + Fore.BLACK + "Scrapple Web Interface") print(Back.RESET + Fore.RESET) p1 = Process(target = self.run_flask) p2 = Process(target = lambda : webbrowser.open('http://127.0.0.1:5000')) p1.start() p2.start()
Example #21
Source File: __init__.py From podfox with GNU General Public License v3.0 | 4 votes |
def import_feed(url, shortname=''): ''' creates a folder for the new feed, and then inserts a new feed.json that will contain all the necessary information about this feed, and all the episodes contained. ''' # configuration for this feed, will be written to file. feed = {} #get the feed. d = feedparser.parse(url) if shortname: folder = get_folder(shortname) if os.path.exists(folder): print_err( '{} already exists'.format(folder)) exit(-1) else: os.makedirs(folder) #if the user did not specify a folder name, #we have to create one from the title if not shortname: # the rss advertises a title, lets use that. if hasattr(d['feed'], 'title'): title = d['feed']['title'] # still no succes, lets use the last part of the url else: title = url.rsplit('/', 1)[-1] # we wanna avoid any filename crazyness, # so foldernames will be restricted to lowercase ascii letters, # numbers, and dashes: title = ''.join(ch for ch in title if ch.isalnum() or ch == ' ') shortname = title.replace(' ', '-').lower() if not shortname: print_err('could not auto-deduce shortname.') print_err('please provide one explicitly.') exit(-1) folder = get_folder(shortname) if os.path.exists(folder): print_err( '{} already exists'.format(folder)) exit(-1) else: os.makedirs(folder) #we have succesfully generated a folder that we can store the files #in #trawl all the entries, and find links to audio files. feed['episodes'] = episodes_from_feed(d) feed['shortname'] = shortname feed['title'] = d['feed']['title'] feed['url'] = url # write the configuration to a feed.json within the folder feed_file = get_feed_file(shortname) feed = sort_feed(feed) with open(feed_file, 'x') as f: json.dump(feed, f, indent=4) print('imported ' + Fore.GREEN + feed['title'] + Fore.RESET + ' with shortname ' + Fore.BLUE + feed['shortname'] + Fore.RESET)
Example #22
Source File: run.py From scrapple with MIT License | 4 votes |
def execute_command(self): """ The run command implements the web content extractor corresponding to the given \ configuration file. The execute_command() validates the input project name and opens the JSON \ configuration file. The run() method handles the execution of the extractor run. The extractor implementation follows these primary steps : 1. Selects the appropriate :ref:`selector class <implementation-selectors>` through \ a dynamic dispatch, with the selector_type argument from the CLI input. #. Iterate through the data section in level-0 of the configuration file. \ On each data item, call the extract_content() method from the selector class to \ extract the content according to the specified extractor rule. #. If there are multiple levels of the extractor, i.e, if there is a 'next' \ attribute in the configuration file, call the traverse_next() \ :ref:`utility function <implementation-utils>` and parse through successive levels \ of the configuration file. #. According to the --output_type argument, the result data is saved in a JSON \ document or a CSV document. """ try: self.args['--verbosity'] = int(self.args['--verbosity']) if self.args['--verbosity'] not in [0, 1, 2]: raise ValueError if self.args['--verbosity'] > 0: print(Back.GREEN + Fore.BLACK + "Scrapple Run") print(Back.RESET + Fore.RESET) import json with open(self.args['<projectname>'] + '.json', 'r') as f: self.config = json.load(f) validate_config(self.config) self.run() except ValueError: print(Back.WHITE + Fore.RED + "Use 0, 1 or 2 for verbosity." \ + Back.RESET + Fore.RESET, sep="") except IOError: print(Back.WHITE + Fore.RED + self.args['<projectname>'], ".json does not ", \ "exist. Use ``scrapple genconfig``." + Back.RESET + Fore.RESET, sep="") except InvalidConfigException as e: print(Back.WHITE + Fore.RED + e + Back.RESET + Fore.RESET, sep="")