A preserved archive of the Logical Gamers community forums, 2009-2025. The original threads and posts, served read-only. Registration, posting and private messages are gone for good.

[PY3.1] Trash Picker log consilidation

1.1k views · started by Smithno13 ·
#1
[PY3.1] Trash Picker log consilidation
This script turns this
XXXXXX Just got a(n) : 1 Green Octopus (on my head)
XXXXXX Just got a(n) : 1 Green Octopus (on my head)
XXXXXX Just got a(n) : 1 Gaia Wing Beanie
XXXXXX Just got a(n) : 1 Blue Skull & Bones Arm Tattoo
XXXXXX Just got a(n) : 1 Blue Skull & Bones Arm Tattoo
XXXXXX Just got a(n) : 1 Blue Skull & Bones Arm Tattoo

into this
2 Green Octopus (on my head)
2 Gaia Wing Beanie
3 Blue Skull & Bones Arm Tattoo

If you run into any bugs, send me the log you are using it on and the line it stops on.
Requires Python 3.1 to run.
Opens up the trash picker log, log.txt and spits out b.txt with the revised inventory.
Save code as trashlogger.py or whatever you want, and run in your trash picker directory.

import re
origin= open('log.txt', 'r')
output = open('b.txt', 'w')
pattern = r"(:)\s(\d+)\s([^\n']+)"
items = dict()
itemlist = ['House Fly']
for line in origin:
print(line)
a = re.search(pattern, line)
if a:
print(a.group(3))
print(a.group(2))
if a.group(3) in items:
items[a.group(3)] = items[a.group(3)] + int(a.group(2))
else:
items[a.group(3)] = int(a.group(2))
itemlist.append(a.group(3))
print(items)
print(itemlist)
itemlist.sort(key=lambda x: x.lower())
for item in itemlist:
if items[item] > 1:
i="'s"
else:
i=""
output.write(str(items[item])+' '+item+i+'\n')
origin.close()
output.close()[/item][/item]
#2
Smithno13 wrote:
This script turns this
XXXXXX Just got a(n) : 1 Green Octopus (on my head)
XXXXXX Just got a(n) : 1 Green Octopus (on my head)
XXXXXX Just got a(n) : 1 Gaia Wing Beanie
XXXXXX Just got a(n) : 1 Blue Skull & Bones Arm Tattoo
XXXXXX Just got a(n) : 1 Blue Skull & Bones Arm Tattoo
XXXXXX Just got a(n) : 1 Blue Skull & Bones Arm Tattoo

into this
2 Green Octopus (on my head)
2 Gaia Wing Beanie
3 Blue Skull & Bones Arm Tattoo

If you run into any bugs, send me the log you are using it on and the line it stops on.
Requires Python 3.1 to run.
Opens up the trash picker log, log.txt and spits out b.txt with the revised inventory.
Save code as trashlogger.py or whatever you want, and run in your trash picker directory.

import re
origin= open('log.txt', 'r')
output = open('b.txt', 'w')
pattern = r"(:)\s(\d+)\s([^\n']+)"
items = dict()
itemlist = ['House Fly']
for line in origin:
print(line)
a = re.search(pattern, line)
if a:
print(a.group(3))
print(a.group(2))
if a.group(3) in items:
items[a.group(3)] = items[a.group(3)] + int(a.group(2))
else:
items[a.group(3)] = int(a.group(2))
itemlist.append(a.group(3))
print(items)
print(itemlist)
itemlist.sort(key=lambda x: x.lower())
for item in itemlist:
if items[item] > 1:
i="'s"
else:
i=""
output.write(str(items[item])+' '+item+i+'\n')
origin.close()
output.close()[/item][/item]


Orrrrrr, just use a regex replace all for the pattern and turn that entire thing into like 4 lines of code O.o
#3
That would remove the excess junk, but it would not accumulate the inventory.
#4
Smithno13 wrote:
That would remove the excess junk, but it would not accumulate the inventory.


Actually what you could do for that is use regex to replace the junk. Then create an array of all of the returned values (after the junk is stripped) and just loop through once adding the same items into a new array so i[0] = p[Item Name, Count][/0]
#5
I still don't understand. With a dict is is easier to check if the value, or the item, is already in the dictionary.