-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_inventory.py
More file actions
77 lines (66 loc) · 1.72 KB
/
Copy pathparse_inventory.py
File metadata and controls
77 lines (66 loc) · 1.72 KB
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
77
# parse inventory
"""
This script just reads a single inventory for a toon, and
outputs a list of items. It looks in the current directory for the
Inventory file.
"""
import re
import sys
garbage = [
"Short Sword*",
"A Worn Candle",
"Skin of Milk",
"Bread Cakes*",
"Empty",
"Name",
"Song: Chant of Battle*",
"A tattered note",
"Tome of Order and Discord",
"Club*",
"Backpack",
"Large Sewing Kit",
"Hand Made Backpack",
"Large Box"
]
def main():
try:
toon = sys.argv[1]
except:
print("Give the name of the character to parse")
quit()
inventory = get_inventory(toon)
if inventory:
print(toon)
print(inventory)
for item in inventory:
print(item)
else:
print("Nothing to see here")
def get_inventory(mule_name):
file_name = mule_name + "-Inventory.txt"
item_list = []
try:
with open(file_name) as inventory:
for line in inventory:
split_line = re.split(r'\t+', line.rstrip('\t'))
if split_line[1] not in garbage:
item_list.append(split_line[1])
except:
print(mule_name + " not found.")
pass
return item_list
def get_counts(mule_name):
file_name = mule_name + "-Inventory.txt"
item_counts = []
try:
with open(file_name) as inventory:
for line in inventory:
split_line = re.split(r'\t+', line.rstrip('\t'))
if split_line[1] not in garbage:
item_counts.append([split_line[1], split_line[3]])
except:
print(mule_name + " not found.")
pass
return item_counts
if __name__ == '__main__':
main()