def generate_notification(sales_to_notify): rows = [] for game, country_price, country, sale in sales_to_notify: title = game.title country = COUNTRIES[country] end_date = sale.end_date.strftime('%b %d') sale_price = format_float(sale.sale_price, country[DIGITS]) full_price = format_float(country_price.full_price, country[DIGITS]) if game.websites.get(country[ID]): title = f'[{title}]({game.websites.get(country[ID])})' rows.append( f'{title}|' f'*{end_date}*|' f'{country[FLAG]} **{country[CURRENCY_CODE]} {sale_price}** ~~{full_price}~~|' f'`{sale.discount}%`' ) rows.sort() content = [ 'Title | Expiration | Price | %', '--- | --- | --- | :---: ' ] content.extend(rows) content.append('') return '\n'.join(content)
def make_row(game, country, price, sale, disable_url=False): now = datetime.utcnow() title = game.titles.get(country[REGION], game.title) if game.published_by_nintendo: title = f'{NINTENDO} {title}' if game.hidden_gem: title = f'{title} {GEM}' if len(title) > 30: title = f'{title[:29]}…'.replace(' …', '…') if not disable_url: if game.websites.get(country[ID]): title = '[{}]({})'.format(title, game.websites.get(country[ID])) new = (now - sale.start_date).days < 1 bold = '**' if new else '' emoji = NEW if new else '' time_left = sale.end_date - now formatted_time = sale.end_date.strftime('%b %d') if time_left.days > 0: days = time_left.days if days < 2: emoji = EXP_TOMORROW else: hours = round(time_left.seconds / 60 / 60) if hours <= 24: emoji = EXP_TODAY if hours > 0: formatted_time = f'{formatted_time} ({hours}h)' else: minutes = round(time_left.seconds / 60) formatted_time = f'{formatted_time} ({minutes}m)' country_price = price.prices[country[ID]] sale_price = format_float(sale.sale_price, country[DIGITS]) full_price = format_float(country_price.full_price, country[DIGITS]) return f'{bold}{title}{bold}|{emoji}|{formatted_time}|' \ f'{country[CURRENCY]}{sale_price} ~~{full_price}~~|`{sale.discount}`|' \ f'{game.players}|{game.scores.metascore}|{game.scores.userscore}|' \ f'{game.wishlisted if game.wishlisted else "-"}'
def make_row(game, country, price, sale, disable_url=False, **kwargs): now = datetime.utcnow() title = game.titles.get(country[REGION], game.title) if game.published_by_nintendo: title = f'{NINTENDO} {title}' if game.hidden_gem: title = f'{GEM} {title}' if len(title) > 25: title = f'{title[:26]}…'.replace(' …', '…') if not disable_url: if game.websites.get(country[ID]): title = '[{}]({})'.format(title, game.websites.get(country[ID])) new = (now - sale.start_date).days < 1 if not kwargs.get('disable_title_formatting', False): bold = '**' if new else '' else: bold = '' emoji = NEW if new else '' time_left = sale.end_date - now formatted_time = sale.end_date.strftime('%b %d') if time_left.days > 0: days = time_left.days if days < 2: emoji = EXP_TOMORROW else: hours = round(time_left.seconds / 60 / 60) if hours <= 24: emoji = EXP_TODAY if hours > 0: formatted_time = f'{formatted_time} ({hours}h)' else: minutes = round(time_left.seconds / 60) formatted_time = f'{formatted_time} ({minutes}m)' country_price = price.prices[country[ID]] if not kwargs.get('disable_extra_zeros', False): digits = country[DIGITS] else: digits = 0 sale_price = format_float(sale.sale_price, digits) full_price = format_float(country_price.full_price, digits) if not kwargs.get('disable_full_prices', False): full_price = f' ~~{full_price}~~' else: full_price = '' wishlisted = game.wishlisted if game.wishlisted else '' metascore = game.scores.metascore if game.scores.metascore != '-' else '' userscore = game.scores.userscore if game.scores.userscore != '-' else '' row = f'{bold}{title}{bold}|{emoji}|{formatted_time}|' \ f'{sale_price}{full_price}' if not kwargs.get('disable_discount_formatting', False): row += f'|`{sale.discount}`' else: row += f'|{sale.discount}' if not kwargs.get('disable_players', False): row += f'|{game.players}' if not kwargs.get('disable_scores', False): row += f'|{metascore}|{userscore}' if not kwargs.get('disable_wishlisted', False): row += f'|{wishlisted}' return row