-
Notifications
You must be signed in to change notification settings - Fork 0
/
fishtag inverter.py
76 lines (62 loc) · 2.87 KB
/
fishtag inverter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import re
def parse_fixed_width_yaml(yaml_string):
parsed_data = {}
yaml_lines = yaml_string.split('\n')
current_rarity = ''
current_tags = []
current_item_ids = []
for line in yaml_lines:
if line.startswith('Fish'):
current_rarity = line.split(':')[0]
parsed_data[current_rarity] = {}
elif line.startswith(' ItemId'):
current_tags = []
current_item_ids = []
elif line.startswith(' ') and line.strip():
columns = re.split(r'\s{2,}', line.strip())
item_id = columns[0]
tags = columns[-1].split(',')
if tags:
current_tags.extend(tags)
else:
# ItemID without any tags, associate with all tags
current_tags = []
current_item_ids.append(item_id)
# Store the current tags and associated ItemIDs
parsed_data[current_rarity][tuple(sorted(set(current_tags)))] = current_item_ids
return parsed_data
def generate_output(parsed_data):
output = ''
rarity_mapping = {
'Common': 'Common',
'Uncommon': 'Uncommon',
'Rare': 'Rare',
'Ultra': 'Ultra'
}
for rarity, tags_data in parsed_data.items():
output += rarity_mapping.get(rarity, rarity) + ':\n'
for tags, item_ids in tags_data.items():
if not tags:
tags_str = 'All'
else:
tags_str = ', '.join(sorted(tags))
output += f' {tags_str}:\n'
for item_id in item_ids:
output += f' - {item_id}\n'
return output
# Example usage
fixed_width_yaml = """
FishCommonSmallFresh:
Contents: |
ItemId Qty MatchOne Tags
________________________________________________________________________________________________________________
FishingSalmonSmallT1 1 TRUE
FishingPikeSmallT1 1 TRUE
FishingTroutSmallT1 1 TRUE Everfall,Brightwood,Weavers,GreatCleave,Queensport,Reekwater,FirstLight
FishingSunfishSmallT1 1 TRUE Windsward,Everfall,Weavers,Restless,Edengrove,Reekwater,Shattered
FishingBassSmallT1 1 TRUE Monarchs,Everfall,Brightwood,Weavers,GreatCleave,Edengrove,Shattered
FishingPerchSmallT1 1 TRUE Windsward,Everfall,Brightwood,CutlassKeys,Mourning,Edengrove,Shattered,Brimstone
"""
parsed_data = parse_fixed_width_yaml(fixed_width_yaml)
output = generate_output(parsed_data)
print(output)