Python humanize 模块,intcomma() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用humanize.intcomma()

项目:graph-data-experiment    作者:occrp-attic    | 项目源码 | 文件源码
def mount_app_blueprints(app):
    app.template_filter()(humanize.intcomma)
    app.template_filter()(country)
    app.template_filter()(date)
    app.template_filter()(cleanurl)
    app.template_filter()(normalizeaddress)
    app.register_blueprint(base)
    app.register_blueprint(auth)
    app.register_blueprint(datasets)
    compile_assets(app)
项目:WebHashcat    作者:hegusung    | 项目源码 | 文件源码
def hashfile(request, hashfile_id, error_msg=''):
    context = {}
    context["Section"] = "Hashfile"

    hashfile = get_object_or_404(Hashfile, id=hashfile_id)

    context['hashfile'] = hashfile
    context['lines'] = humanize.intcomma(hashfile.line_count)
    context['recovered'] = "%s (%.2f%%)" % (humanize.intcomma(hashfile.cracked_count), hashfile.cracked_count/hashfile.line_count*100)
    context['hash_type'] = Hashcat.get_hash_types()[hashfile.hash_type]["name"]

    template = loader.get_template('Hashcat/hashfile.html')
    return HttpResponse(template.render(context, request))
项目:WebHashcat    作者:hegusung    | 项目源码 | 文件源码
def get_wordlists(self, detailed=True):

        res = []
        if not detailed:
            path = os.path.join(os.path.dirname(__file__), "..", "Files", "Wordlistfiles")

            res = [{"name": f} for f in listdir(path) if isfile(join(path, f)) and f.endswith(".wordlist")]
        else:
            path = os.path.join(os.path.dirname(__file__), "..", "Files", "Wordlistfiles", "*")
            # use md5sum instead of python code for performance issues on a big file
            result = subprocess.run('md5sum %s' % path, shell=True, stdout=subprocess.PIPE).stdout.decode()

            for line in result.split("\n"):
                items = line.split()
                if len(items) == 2:
                    info = {
                        "name": items[1].split("/")[-1],
                        "md5": items[0],
                        "path": items[1],
                    }

                    try:
                        info["lines"] = humanize.intcomma(sum(1 for _ in open(items[1], errors="backslashreplace")))
                    except UnicodeDecodeError:
                        print("Unicode decode error in file %s" % items[1])
                        info["lines"] = "error"
                    res.append(info)


        return sorted(res, key=itemgetter('name'))
项目:source-code-to-name    作者:zironycho    | 项目源码 | 文件源码
def cli_total_repos():
    print(humanize.intcomma(Crawler().num_repos()))
项目:source-code-to-name    作者:zironycho    | 项目源码 | 文件源码
def cli_total_features():
    print(humanize.intcomma(Crawler().num_features()))
项目:twitch-zoo    作者:dbernard    | 项目源码 | 文件源码
def build_streamer_json(stream, user_info):
    """Compile useful streamer information from a stream object.

    :param user: The username of the streamer
    :param stream: The complete stream JSON object
    :param participant_id: The user's Extra Life participant ID
    :return: A subset object of relevant streamer info
    """
    participant_id = user_info.get('EXTRALIFE')
    user = user_info.get('TWITCH')
    donate_url = 'https://www.extra-life.org/index.cfm?fuseaction=donorDrive.' \
                 'participant&participantID={}'.format(participant_id)
    s = {
        'dispname': user_info['NAME'],
        'username': user_info['TWITCH'],
        'playing': 'Offline',
        'viewers': 0,
        'url': 'https://www.twitch.tv/{}'.format(user),
        'preview': 'http://placehold.it/640x360',
        'participant_id': participant_id,
        'donate': donate_url if participant_id else None,
        'fps': 0,
        'views': 0,
    }

    if not stream['stream']:
        return s

    mapping = [
        ('pubg', 'PUBG', "PLAYERUNKNOWN'S BATTLEGROUNDS", ),
        ('overwatch', 'BLIZZARD', 'Overwatch', ),
        ('rocketleague', 'STEAM', 'Rocket League', ),
        ('destiny2', 'DESTINY2', 'Destiny 2', )
    ]

    for key, lookup, twitch_name in mapping:
        module = importlib.import_module('games.{}'.format(key))
        if user_info.get(lookup):
            if stream['stream'].get('game') != twitch_name:
                continue
            try:
                s[key] = module.stats(user_info[lookup])
            except KeyError as exc:
                s[key] = {}

    s['username'] = stream['stream']['channel']['display_name']
    s['playing'] = stream['stream']['game']
    s['viewers'] = humanize.intcomma(int(stream['stream']['viewers']))
    s['preview'] = stream['stream']['preview']['large']
    s['fps'] = stream['stream']['average_fps']
    s['views'] = humanize.intword(int(stream['stream']['channel']['views']))

    return s