我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用humanize.intword()。
def grand_tot(self): return humanize.intword(self.grand_total)
def setup_jinja2_filters(app): """Setup jinja2 filters.""" @app.template_filter('pretty_date') def _pretty_date_filter(s): return pretty_date(s) @app.template_filter('humanize_intword') def _humanize_intword(obj): return humanize.intword(obj) @app.template_filter('disqus_sso') def _disqus_sso(obj): # pragma: no cover return get_disqus_sso(obj)
def humanize_intword_filter(dt: int, fmt=None): """??humanize??????????????""" humanize.i18n.activate('zh_CN', path='etc/humanize') return humanize.intword(dt)
def updateCard(self, trainer): dailyDiff = await self.getDiff(trainer, 1) level=trainer.level embed=discord.Embed(timestamp=dailyDiff.new_date, colour=int(trainer.team().colour.replace("#", ""), 16)) try: embed.set_author(name=trainer.username, icon_url=trainer.account().discord().avatar_url) except: embed.set_author(name=trainer.username) embed.add_field(name='Level', value=level.level) if level.level != 40: embed.add_field(name='XP', value='{:,} / {:,}'.format(trainer.update.xp-level.total_xp,level.xp_required)) else: embed.add_field(name='Total XP', value='{}'.format(humanize.intword(trainer.update.xp))) if dailyDiff.change_xp and dailyDiff.change_time: gain = '{:,} since {}. '.format(dailyDiff.change_xp, humanize.naturalday(dailyDiff.old_date)) if dailyDiff.change_time.days>1: gain += "That's {:,} xp/day.".format(round(dailyDiff.change_xp/dailyDiff.change_time.days)) embed.add_field(name='Gain', value=gain) if trainer.goal_daily and dailyDiff.change_time.days>0: dailyGoal = trainer.goal_daily embed.add_field(name='Daily completion', value='{}% towards {:,}'.format(pycent.percentage(dailyDiff.change_xp/max(1,dailyDiff.change_time.days), dailyGoal), dailyGoal)) if trainer.goal_total and trainer.goal_total!=0: totalGoal = trainer.goal_total else: totalGoal = None if totalGoal: totalDiff = await self.getDiff(trainer, 7) embed.add_field(name='Goal remaining', value='{:,} out of {}'.format(totalGoal-totalDiff.new_xp, humanize.intword(totalGoal))) if totalDiff.change_time.seconds>=1: eta = lambda x, y, z: round(x/(y/z)) eta = eta(totalGoal-totalDiff.new_xp, totalDiff.change_xp, totalDiff.change_time.total_seconds()) eta = totalDiff.new_date+datetime.timedelta(seconds=eta) embed.add_field(name='Goal ETA', value=humanize.naturaltime(eta.replace(tzinfo=None))) if totalDiff.change_time.total_seconds()<583200: embed.description = "ETA may be inaccurate. Using {} of data.".format(humanize.naturaldelta(totalDiff.change_time)) embed.set_footer(text="Total XP: {:,}".format(dailyDiff.new_xp)) return embed
def profileCard(self, name: str, force=False): try: trainer = await self.get_trainer(username=name) except LookupError: raise if not trainer: raise LookupError("Trainer not found") account = trainer.owner() discordUser = account.discord()[0] level=trainer.level embed=discord.Embed(timestamp=trainer.update.update_time, colour=int(trainer.team().colour.replace("#", ""), 16)) try: embed.set_author(name=trainer.username, icon_url=discordUser.avatar_url) except: embed.set_author(name=trainer.username) if account and (account.first_name or account.last_name) and trainer.cheater is False: embed.add_field(name='Name', value=account.first_name+' '+account.last_name) embed.add_field(name='Team', value=trainer.team().name) embed.add_field(name='Level', value=level.level) if level.level != 40: embed.add_field(name='XP', value='{:,} / {:,}'.format(trainer.update.xp-level.total_xp,level.xp_required)) else: embed.add_field(name='Total XP', value='{}'.format(humanize.intword(trainer.update.xp))) if discordUser: embed.add_field(name='Discord', value='<@{}>'.format(discordUser.id)) if trainer.cheater is True: desc = "{} has been known to cheat." embed.description = desc.format(trainer.username) embed.set_footer(text="Total XP: {:,}".format(trainer.update.xp)) return embed
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