Example #1
0
def list_wrestlers():
    """Print a list of all of the wrestlers and their records.
    """
    print "\nWide World of Wrestling Statistics"
    wrestlers = get_wrestlers()
    if wrestlers:
        # Figure out the max text length that our input will need.
        max_text_length = 0
        for wrestler in wrestlers:
            for k, v in wrestler.attrs_as_dict().items():
                max_text_length = max(max_text_length, len(str(k)), len(str(v)))
        
        # A little extra space.
        max_text_length += 1
        # Template for the table, assuming each wrestler has the same stats.
        row_template = StringIO()
        for i in range(5):
            row_template.write("{0[%s]:>%s}" % (i, max_text_length))
        row_template = row_template.getvalue() + "\n"
        output = StringIO()
        # Header first
        output.write(row_template.format(wrestlers[0].attrs_as_dict().keys()))
        # Wrestlers second
        for wrestler in wrestlers:
            output.write(row_template.format(wrestler.attrs_as_dict().values()))
        # Output to screen
        print "\n",output.getvalue(),"\n"
        output.close()
    else:
        print "No wrestlers found. Please recruit some wrestlers.\n"
Example #2
0
def list_wrestlers():
    """Print a list of all of the wrestlers and their records.
    """
    print "\nWide World of Wrestling Statistics"
    wrestlers = get_wrestlers()
    if wrestlers:
        # Figure out the max text length that our input will need.
        max_text_length = 0
        for wrestler in wrestlers:
            for k, v in wrestler.attrs_as_dict().items():
                max_text_length = max(max_text_length, len(str(k)), len(str(v)))
        
        # A little extra space.
        max_text_length += 1
        # Template for the table, assuming each wrestler has the same stats.
        row_template = StringIO()
        for i in range(5):
            row_template.write("{0[%s]:>%s}" % (i, max_text_length))
        row_template = row_template.getvalue() + "\n"
        output = StringIO()
        # Header first
        output.write(row_template.format(wrestlers[0].attrs_as_dict().keys()))
        # Wrestlers second
        for wrestler in wrestlers:
            output.write(row_template.format(wrestler.attrs_as_dict().values()))
        # Output to screen
        print "\n",output.getvalue(),"\n"
        output.close()
    else:
        print "No wrestlers found. Please recruit some wrestlers.\n"
Example #3
0
    def get_export_files(self, format=None, previous_export=None, filter=None, process=None, max_column_size=None,
                         apply_transforms=True, **kwargs):
        from couchexport.export import get_writer, format_tables, create_intermediate_tables

        if not format:
            format = self.default_format or Format.XLS_2007

        config, updated_schema, export_schema_checkpoint = self.get_export_components(previous_export, filter)

        # transform docs onto output and save
        writer = get_writer(format)
        
        # open the doc and the headers
        formatted_headers = list(self.get_table_headers())
        tmp = StringIO()
        writer.open(
            formatted_headers,
            tmp,
            max_column_size=max_column_size,
            table_titles=dict([
                (table.index, table.display)
                for table in self.tables if table.display
            ])
        )

        total_docs = len(config.potentially_relevant_ids)
        if process:
            DownloadBase.set_progress(process, 0, total_docs)
        for i, doc in config.enum_docs():
            if self.transform and apply_transforms:
                doc = self.transform(doc)
            formatted_tables = self.trim(
                format_tables(
                    create_intermediate_tables(doc, updated_schema),
                    separator="."
                ),
                doc,
                apply_transforms=apply_transforms
            )
            writer.write(formatted_tables)
            if process:
                DownloadBase.set_progress(process, i + 1, total_docs)

        writer.close()
        # hacky way of passing back the new format
        tmp.format = format
        return tmp, export_schema_checkpoint