-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathsto_superstream.py
More file actions
80 lines (74 loc) · 3.41 KB
/
sto_superstream.py
File metadata and controls
80 lines (74 loc) · 3.41 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
78
79
80
import datetime
import sys
import os
import tzlocal
min_date = tzlocal.get_localzone().localize(datetime.datetime(2002, 1, 1))
min_date -= min_date.utcoffset()
day = min_date
keys = ['Contraband', 'Dilithium', 'Dilithium Ore', 'Energy Credits']
dct = {key:0 for key in keys}
files = sorted(f for f in os.listdir() if f[:5]=="Chat_")
l = len(files)
try:
with open('lastlog.txt') as f:
lastlog = f.read()
except (FileNotFoundError, PermissionError):
lastlog = ''
print('Date', *keys, sep='\t')
for counter,fname in enumerate(files):
if fname >= lastlog:
print('Processing {} out of {}...'.format(counter, l), end='\r', file=sys.stderr)
with open(fname, encoding='utf-8-sig') as f:
for line in f:
if (line[26:70] == ",0,NumericReceived@,@,,,System]You received " and
('Dilithium' in line or 'Energy Credits' in line)):
quantity,item = line.strip()[70:].split(None, 1)
quantity = int(quantity.replace(',', ''))
if item == 'Refined Dilithium':
item = 'Dilithium'
elif line[26:66] == ",0,NumericReceived@,@,,,System]You sold ":
item = 'Energy Credits'
quantity = int(line.rsplit(None, 3)[1].replace(',', ''))
elif line[26:78] == ",0,NumericConversionSuccess@,@,,,System]You refined ":
item = 'Dilithium'
quantity = int(line[78:-11].replace(',', ''))
elif (line[26:56] == ",0,NumericLost@,@,,,System]You" and
(line[56:62] == " lost " or line[56:63] == " spent ") and
('Dilithium' in line or 'Energy Credits' in line)):
quantity,item = line[62:].strip().split(None, 1)
quantity = -int(quantity.replace(',', ''))
if item == 'Refined Dilithium':
item = 'Dilithium'
elif line[26:83] == ',0,ItemReceived@,@,,,System]Items acquired: Contraband x ':
quantity = int(line[70:].rsplit(None, 1)[1].replace(',', ''))
item = 'Contraband'
elif line[26:79] == ",0,ItemReceived@,@,,,System]Item acquired: Contraband":
quantity = 1
item = 'Contraband'
else:
continue
dt = tzlocal.get_localzone().localize(datetime.datetime(year=int(line[11:15]), month=int(line[15:17]),
day=int(line[17:19]), hour=int(line[20:22]), minute=int(line[22:24]), second=int(line[24:25])))
dt -= dt.utcoffset()
if dt.day != day.day and day != min_date:
print('{}-{}-{}'.format(day.year,
day.month,
day.day),
*(dct[k] for k in keys), sep='\t')
dct = {key:0 for key in keys}
day = dt
if item in dct:
dct[item] += quantity
print('{}-{}-{}'.format(dt.year,
dt.month,
dt.day),
*(dct[k] for k in keys), sep='\t')
print('\nDone.', file=sys.stderr)
last = files[-1][5:15]
current = files[-1]
for fname in files[::-1]:
current = fname
if fname[5:15] != last:
break
with open('lastlog.txt', 'w') as f:
f.write(current)