python类AsciiTable()的实例源码

cli.py 文件源码 项目:zops 作者: bjinwright 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def user_credentials(ctx,app_name,stage_name):
    result = Zops(app_name,stage_name,
                  profile_name=ctx.obj['profile_name']).user_stack_outputs()
    try:
        table_data = [
            [i['OutputKey'], i['OutputValue']]
            for i in result
            ]
    except TypeError:
        click.echo('User creds not ready yet.')
        return
    table_data.insert(0, ['Attribute','Value'])
    table = terminaltables.AsciiTable(table_data)
    click.echo(table.table)
player.py 文件源码 项目:football_tools 作者: johnshiver 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def show_top_players(cls, position="RB", n=15):
        """
        Displays top x players given position.
        """
        valid_positions = cls.POSITION_CHOICES
        # reduce tuples to single element
        valid_positions = map(lambda x: x[0], valid_positions)
        if position not in valid_positions:
            raise ValueError("{} must be one of {}".format(position,
                                                           valid_positions))

        table_data = [
            ['Player', 'Position', 'Points'],
        ]

        players = Player.objects.all()
        if position:
            players = players.filter(position=position)
        top_players = sorted(players, key=lambda x: x.draft_bot_score,
                             reverse=True)
        for player in top_players[:n]:
            table_data.append([player.full_name, player.position,
                               int(player.draft_bot_score)])

        table = AsciiTable(table_data)
        print(table.table)
ms3.py 文件源码 项目:viper-metascan 作者: securenetworx 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def show_analyzed_info(self):
        summary_table = [["Filename", "md5", "status"]]
        for path, name in self.files:
            av_found_threat = 0
            details = [["Engine", "Threat", "Def. time"]]
            res = self.metascan.scan_file_and_get_results(path, name)
            try:
                res.raise_for_status()
            except HTTPError as err:
                self.log('error', err)
                return
            jres = res.json()
            if jres.get("process_info", {}).get("result") == "Blocked":
                details = [["Blocked", "Reason: %s " % jres["process_info"]["blocked_reason"]]]
                status = "blocked"
            else:
                for engine, scan_details in jres["scan_results"]["scan_details"].iteritems():
                    if scan_details.get("scan_result_i"):
                        av_found_threat += 1
                    def_time = parser.parse(scan_details["def_time"]).strftime("%Y-%m-%d %H:%M:%S")
                    details.append([engine, scan_details["threat_found"], def_time])
                status = "%d/%d" % (av_found_threat, jres["scan_results"]["total_avs"])
            summary_table.append([name, jres["file_info"]["md5"], status])
            table = AsciiTable(details, name)
            print table.table
        return summary_table
ms3.py 文件源码 项目:viper-metascan 作者: securenetworx 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def show_summary(self, summary_table):
        sum_table = AsciiTable(summary_table, "Summary")
        print sum_table.table
ms3.py 文件源码 项目:viper-metascan 作者: securenetworx 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def show_engines(self):
        details = [["Engine name", "Engine version", "Def time", "Active"]]
        engines = self.metascan.get_engines()
        try:
            engines.raise_for_status()
        except HTTPError as err:
            self.log('error', err)
            return
        for eng in engines.json():
            def_time = parser.parse(eng["def_time"]).strftime("%Y-%m-%d %H:%M:%S")
            active = "Y" if eng["active"] else "N"
            details.append([eng["eng_name"], eng["eng_ver"], def_time, active])
        table = AsciiTable(details, "Engines")
        print table.table
ms4.py 文件源码 项目:viper-metascan 作者: securenetworx 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def show_summary(summary_table):
        sum_table = AsciiTable(summary_table, "Summary")
        print sum_table.table
ms4.py 文件源码 项目:viper-metascan 作者: securenetworx 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def show_workflows(self):
        details = []
        workflows = self.metascan.get_workflows()
        for wf in workflows.json():
            details.append([wf["name"]])
        table = AsciiTable(details, "Workflows")
        table.inner_heading_row_border = False
        print table.table
ms4.py 文件源码 项目:viper-metascan 作者: securenetworx 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def show_license(self):
        licenses = self.metascan.get_license()
        details = []
        for lic in licenses.json().iteritems():
            details.append([str(lic[0]), str(lic[1])])
        table = AsciiTable(details, "Licenses")
        table.inner_heading_row_border = False
        print table.table
utils.py 文件源码 项目:ovh-cli 作者: ovh 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def display_services(services):
    """Display the user services."""
    data = [['Services']]

    for service in sorted(services):
        data.append([service])

    table = AsciiTable(data)

    return table.table
utils.py 文件源码 项目:ovh-cli 作者: ovh 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def display_quota(quota):
    """Display the quota for a service."""
    used = '{} {}'.format(
        "%.2f" % quota['used']['value'],
        quota['used']['unit']
    )
    size = '{} {}'.format(
        "%.2f" % quota['size']['value'],
        quota['size']['unit']
    )

    table = AsciiTable([["Used", used], ["Size", size]])

    return table.table
utils.py 文件源码 项目:ovh-cli 作者: ovh 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def display_users(users):
    """Display the list of users by their username."""
    data = [['Users']]

    for user in sorted(users):
        data.append([user])

    table = AsciiTable(data)

    return table.table
framework.py 文件源码 项目:sff 作者: nevarezs 项目源码 文件源码 阅读 42 收藏 0 点赞 0 评论 0
def _print_table(self, data):
        """Print table to stdout."""
        max_width = 45
        wrapped_data = \
            [["\n".join(wrap(col, max_width))
                if ((type(col) is str or type(col) is unicode)
                    and len(col) > max_width)
                else col
                for col in row]
                for row in data]
        table = AsciiTable(wrapped_data)
        table.inner_row_border = True
        print table.table
util.py 文件源码 项目:gce-manager 作者: binary-com 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def get_ascii_table(self, table):
        return AsciiTable(table).table
cm_connection.py 文件源码 项目:CManager 作者: fachrioktavian 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def show_profile(self):
        indent = ' '
        header = indent + 'List of profiles saved by system:\n'
        table = [['Profile name', 'Connection type', 'SSID', 'Passphrase']]
        list_profile = os.listdir(self.profile_path)
        for fileconf in list_profile:
            of_file = open(self.profile_path + fileconf, 'r')
            of = of_file.read().split('\n')
            if of[0][1::] == 'Open':
                table.append([fileconf[:-5:], 'Open', of[2][7:-1:], '-'])
            elif of[0][1::] == 'WPA':
                table.append([fileconf[:-5:], 'WPA', of[2][7:-1:], of[3][7:-1:]])
            of_file.close()
        print (Fore.YELLOW + Style.DIM + header + AsciiTable(table).table)
cm_interfaces.py 文件源码 项目:CManager 作者: fachrioktavian 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def print_ifaces_ethernet_table(self):
        indent = ' ' * 1
        header = indent + 'Ethernet interfaces information:\n'
        self.ethernet_table = [['Interface', 'Status', 'IP Address', 'Mask']]
        for data in self.ifaces_ethernet:
            self.ethernet_table.append([
                data,
                self.dict_status[data],
                self.dict_ipaddr[data],
                self.dict_mask[data]
            ])
        table = AsciiTable(self.ethernet_table)
        print (Fore.YELLOW + Style.DIM + header + table.table)
cm_interfaces.py 文件源码 项目:CManager 作者: fachrioktavian 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def print_ifaces_localhost_table(self):
        indent = ' ' * 1
        header = indent + 'Localhost interfaces information:\n'
        self.localhost_table = [['Interface', 'Status', 'IP Address', 'Mask']]
        for data in self.ifaces_localhost:
            self.localhost_table.append([
                data,
                self.dict_status[data],
                self.dict_ipaddr[data],
                self.dict_mask[data]
            ])
        table = AsciiTable(self.localhost_table)
        print (Fore.YELLOW + Style.DIM + header + table.table)
helpers.py 文件源码 项目:cointrader 作者: toirl 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def colorize_value(value):
    if value < 0:
        return colored(value, "red")
    else:
        return colored(value, "green")


# def render_signal_details(signals):
#     out = [["Indicator", "Signal", "Details"]]
#     for s in signals:
#         out.append([s, signals[s].value, signals[s].details])
#     table = AsciiTable(out).table
#     return "\n".join(["\nSignal:", table])
helpers.py 文件源码 项目:cointrader 作者: toirl 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def render_bot_statistic(stat):
    out = [["", stat["start"], stat["end"], "CHANGE %"]]
    out.append(["COINTRADER", stat["trader_start_value"], stat["trader_end_value"], "{}".format(colorize_value(round(stat["profit_cointrader"], 4)))])
    out.append(["MARKET", stat["market_start_value"], stat["market_end_value"], "{}".format(colorize_value(round(stat["profit_chart"], 4)))])
    table = AsciiTable(out).table
    return "\n".join(["\nStatistic:", table])
helpers.py 文件源码 项目:cointrader 作者: toirl 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def render_bot_tradelog(trades):
    out = [["DATE", "TYPE", "RATE", "COINS", "COINS'", "BTC", "BTC'"]]
    for trade in trades:
        values = []
        values.append(trade.date)
        values.append(trade.order_type)
        values.append(trade.rate)
        if trade.order_type == "BUY":
            values.append("--")
            values.append(trade.amount_taxed)
            values.append(trade.btc)
            values.append("--")
        elif trade.order_type == "SELL":
            values.append(trade.amount)
            values.append("--")
            values.append("--")
            values.append(trade.btc_taxed)
        else:
            values.append(trade.amount)
            values.append("--")
            values.append(trade.btc)
            values.append("--")
        out.append(values)
    table = AsciiTable(out).table

    return "\n".join(["\nTradelog:", table])
music.py 文件源码 项目:spider163 作者: Chengyumeng 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def get_playlist(self, playlist_id):
        self.view_capture(int(playlist_id))
        url = uapi.playlist_api.format(playlist_id)
        s = requests.session()
        s = BeautifulSoup(s.get(url, headers=self.__headers).content, "html.parser")
        playlist = json.loads(s.text)['result']

        print("?" + playlist['name'].encode('utf-8') + "?")
        author = playlist['creator']['nickname'].encode('utf-8')
        pc = str(playlist['playCount'])
        sc = str(playlist['subscribedCount'])
        rc = str(playlist['shareCount'])
        cc = str(playlist['commentCount'])
        print("????{}  ???{} ???{} ???{} ???{}".format(author, pc, sc, rc, cc))
        print("???{}".format(playlist['description'].encode('utf-8')))
        print("???{}".format(",".join(playlist['tags']).encode("utf-8")))

        tb = [["ID", "????", "???", "??"]]
        for music in playlist['tracks']:
            artists = []
            for s in music['ar']:
                artists.append(s['name'])
            ms = music['name'].encode("utf-8")
            ar = ",".join(artists).encode("utf-8")
            ab = music['album']['name'].encode("utf-8")
            id = music['id']
            tb.append([id, ms, ar, ab])
        print(AsciiTable(tb).table)


问题


面经


文章

微信
公众号

扫码关注公众号