User:Phiarc/US missiles
Appearance
Usage
[edit]missiles = {}
for line in open("inp.txt", encoding="utf-8").readlines():
if not line.startswith('*'):
continue
linktext, _, missile = line.strip().lstrip('*').strip('[] ').partition('|')
missile = missile or linktext
mission = 'I' if missile.startswith('XLIM') else missile[1]
missiles.setdefault(mission, []).append((linktext, missile))
def number(missile):
return int(missile.partition('-')[2].strip('ABCDEFGHIJKLMNOPQRSTUVWXYZ/'))
def sortkey(linktext_missile):
typedes, _, number = linktext_missile[1].partition('-')
number = int(number.strip('ABCDEFGHIJKLMNOPQRSTUVWXYZ/'))
return number # sort by number
return typedes, number # group by type (e.g. AIM) then sort by number
for bunch in missiles.values():
bunch.sort(key=sortkey)
missionkey = dict(
D='Decoy',
E='Special electronic',
G='Ground attack',
I='Air intercept',
Q='Drone',
S='Anti-satellite',
T='Training',
U='Anti-submarine',
W='Weather observation',
)
for n, (mission, missiles) in enumerate(sorted(missiles.items())):
n += 1
print(f'|group{n} = {missionkey[mission]}')
print(f'|list{n} =')
lastnum = 0
lastlink = ''
for linktext, missile in missiles:
num = number(missile)
star = '* ' if num != lastnum else '**'
if linktext == missile:
print(f'{star}[[{missile}]]')
else:
print(f'{star}[[{linktext}|{missile}]]')
lastnum = num
print()