-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.py
43 lines (40 loc) · 1.37 KB
/
test.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
import re
filename = "TraderConfig.txt"
with open(filename, "r") as file:
lines = file.readlines()
traders = {}
current_trader = None
current_category = None
current_item = None
current_quantity = None
current_buyprice = None
current_sellprice = None
for line in lines:
line = line.strip()
line = line.split("//", 1)[0].strip() # Remove comments and extra whitespace
line = re.sub(r"\t", "", line)
if line is "":
continue
if line.startswith("<Trader>"):
trader_str = line.replace("<Trader>", "")
current_trader = trader_str
traders[current_trader] = {}
elif line.startswith("<Category>"):
category_str = line.replace("<Category>", "")
current_category = category_str
traders[current_trader][current_category] = []
elif current_trader is not None and current_category is not None:
if line != "<FileEnd>":
line_split = line.split(",")
class_str = line_split[0]
quant_str = line_split[1]
buyprice_str = line_split[2]
sellprice_str = line_split[3]
item_data = {
"class": class_str,
"quantity": quant_str,
"buy_price": int(buyprice_str),
"sell_price": int(sellprice_str),
}
traders[current_trader][current_category].append(item_data)
print(traders)