|
@@ -42,53 +42,72 @@ def abbreviate(string, max_lenght):
|
|
|
def format_state_region(side):
|
|
|
"""Format state and region name"""
|
|
|
state = '*[{}](https://m.rivalregions.com/#state/details/{})*'.format(
|
|
|
- abbreviate(side['state_name'], 4),
|
|
|
+ escape_markdown(abbreviate(side['state_name'], 4), 2),
|
|
|
side['state_id'],
|
|
|
)
|
|
|
region = '[{}](http://m.rivalregions.com/#map/details/{})'.format(
|
|
|
- side['region_name'],
|
|
|
+ escape_markdown(side['region_name'], 2),
|
|
|
side['region_id'],
|
|
|
)
|
|
|
return '{} {}'.format(state, region)
|
|
|
|
|
|
def roundk(integer):
|
|
|
"""Round down number"""
|
|
|
- thousand = 1
|
|
|
- while integer >= 999:
|
|
|
+ thousand = 0
|
|
|
+ decimal = 0
|
|
|
+ while integer >= 999 or integer <= -999:
|
|
|
thousand += 1
|
|
|
- decimal = str(integer)[-3:-2]
|
|
|
+ decimal = int(str(integer)[-3:-2])
|
|
|
integer = int(str(integer)[:-3])
|
|
|
- return '{}\\.{}{}'.format(integer, decimal, 'k' * thousand)
|
|
|
+ if decimal == 0:
|
|
|
+ return '{}{}'.format(integer, 'k' * thousand)
|
|
|
+ return '{}.{}{}'.format(integer, decimal, 'k' * thousand)
|
|
|
+
|
|
|
|
|
|
|
|
|
def telegram_format_war(war):
|
|
|
"""Format war object for article"""
|
|
|
+ row_list = []
|
|
|
if 'region_name' in war['attack']:
|
|
|
- title = '{} vs {}'.format(
|
|
|
+ row_list.append('{} vs {}'.format(
|
|
|
format_state_region(war['attack']),
|
|
|
format_state_region(war['defend'])
|
|
|
- )
|
|
|
+ ))
|
|
|
else:
|
|
|
- title = '{} vs {}'.format(
|
|
|
+ row_list.append('{} vs {}'.format(
|
|
|
'*{}*'.format(war['type']),
|
|
|
format_state_region(war['defend'])
|
|
|
- )
|
|
|
- damage = '{} *vs* {} \\= {}'.format(
|
|
|
- roundk(war['attack']['damage']),
|
|
|
- roundk(war['defend']['damage']),
|
|
|
- roundk(war['damage']),
|
|
|
+ ))
|
|
|
+
|
|
|
+ total_damage = war['attack']['damage'] + war['defend']['damage']
|
|
|
+ row_list.append('{} *vs* {} \\= {}'.format(
|
|
|
+ escape_markdown('{} ({:0.2f}%)'.format(
|
|
|
+ roundk(war['attack']['damage']),
|
|
|
+ 100 / total_damage * war['attack']['damage']
|
|
|
+ ), 2),
|
|
|
+ escape_markdown('{} ({:0.2f}%)'.format(
|
|
|
+ roundk(war['defend']['damage']),
|
|
|
+ 100 / total_damage * war['defend']['damage']
|
|
|
+ ), 2),
|
|
|
+ escape_markdown(roundk(war['damage']), 2),
|
|
|
+ ))
|
|
|
+
|
|
|
+ row_list.append(
|
|
|
+ 'finish: {} UTC'.format(escape_markdown(war['finish_date'].strftime('%Y-%m-%d %H:%M'), 2))
|
|
|
)
|
|
|
|
|
|
- link = '{} \\| {}'.format(
|
|
|
+ if war['time_left']:
|
|
|
+ row_list.append('time left: {}'.format(escape_markdown(str(war['time_left']))))
|
|
|
+ else:
|
|
|
+ row_list.append('max damage [{}](https://m.rivalregions.com/#slide/profile/{}): {}'.format(
|
|
|
+ war['max_hero_name'],
|
|
|
+ war['max_hero_id'],
|
|
|
+ escape_markdown(roundk(war['max_hero_damage']), 2),
|
|
|
+ ))
|
|
|
+
|
|
|
+ row_list.append('{} \\| {}'.format(
|
|
|
'[mobile](https://m.rivalregions.com/#war/details/{})'.format(war['war_id']),
|
|
|
'[desktop](http://rivalregions.com/#war/details/{})'.format(war['war_id']),
|
|
|
- )
|
|
|
+ ))
|
|
|
|
|
|
- formatted_war = '\n'.join([
|
|
|
- title,
|
|
|
- damage,
|
|
|
- 'finish: {} UTC'.format(escape_markdown(war['finish_date'].strftime('%Y-%m-%d %H:%M'), 2)),
|
|
|
- 'time left: {}'.format(escape_markdown(str(war['time_left']))),
|
|
|
- link,
|
|
|
- ])
|
|
|
- return formatted_war
|
|
|
+ return '\n'.join(row_list)
|