Vendor Log Dump Reader by Brozan (Syal)

Description: A log parser written in Powershell to read vendor output

1$dir = "C:\Program Files (x86)\Ultima Online Outlands\ClassicUO\Data\Client\JournalLogs"
2$latest = Get-ChildItem -Path $dir | Sort-Object LastAccessTime -Descending | Select-Object -First 1
3
4$file = $latest.name
5
6#Remember this is hardcoded for testing!
7#$file = "2021_10_27_11_12_55_journal.txt"
8
9$outfile = "C:\users\oreos\desktop\test.txt"
10
11Set-Content $outfile ''
12
13$new_vendor = 0
14$line_count = 0
15$write_check = 1
16$item_count = 1
17$last_item_count = 1
18$master_list_count = 0
19$total_count = 0
20$item_string = ''
21$last_item_string = 'a'
22$master_list_string_output = 'Master List of Items ['
23$last_line = ''
24foreach($line in Get-Content $dir\$file) {
25	$line_count = $line_count + 1
26	if ($line -like "*START CATALOGUE*"  )
27	{
28		#Start Block
29		$write_check = 0		
30	}
31	if ($line -like "*DONE CATALOGUE*"  )
32	{
33		#Start Block
34		$write_check = 1		
35	}
36	if ($write_check -eq 0 -and $line -like "*New Vendor*" -and $line -notlike "*New target*" )
37	{
38		#Found new vendor - grab next line
39		$new_vendor = 1
40		$line_count = 0
41	}
42	if ($write_check -eq 0 -and $line -like "*Razor: Target*" -and $line -notlike "*New target*" )
43	{		
44		$line = $line -replace '\[.*\].*Razor: Target: ', '**Vendor Name: '
45		$line = $line + "**"
46		Add-Content $outfile " "
47		Add-Content $outfile $line
48	}
49	
50	if ($write_check -eq 0 -and $new_vendor -eq 1 -and $line_count -eq 1  -and $line -notlike "*When used, it will*"  -and $line -notlike "*That is not accessible*"  -and $line -notlike "*used to increase*"  -and $line -notlike "*WorldMap*" -and $line -notlike "*completed the achievement*" -and $line -like "*System*" -and $line -notlike "*.xml*" -and $line -notlike "*New target*" )
51	{
52		#This is our vendor name		
53		
54		#Output last build item
55		if($item_string -ne $last_item_string)
56		{
57			#new item - output
58			if($last_item_count -gt 1)
59			{
60				#Previous item had multiples
61				$dup_out_string = "        >> [" +  $last_item_count + "] AVAILABLE!"				
62				Add-Content $outfile $dup_out_string
63			}
64			$dump_item_string = $item_string -replace '(?<=\d)(?=(0{3})+\b)', 'k'
65			$dump_item_string = $dump_item_string -replace 'k000', 'k'
66			Add-Content $outfile $dump_item_string
67			
68			#Add item to master list if it's not on the list	
69			if($item_string -notlike '*carpet dye*' -and $item_string -notlike '*queued actions*'  -and $item_string -notlike '*martial manual*'  -and $item_string -notlike '*gorget*'  -and $item_string -notlike '*Queuing action*' -and $item_string -notlike '*exceptional*' -and $item_string -notlike '*viking sword*' -and $item_string -notlike '*two-handed axe*' -and $item_string -notlike '*select an item*' -and $item_string -notlike '*crossbow*' -and $item_string -notlike '*CATALOGUE*'  -and $item_string -notlike '*black staff*'   -and $item_string -notlike '*battleaxe*'  -and $item_string -notlike '*prestige has*'  -and $item_string -notlike '*melodious*'  -and $item_string -notlike '*spellbook*' -and $item_string -notlike '*container identification wand*'  -and $item_string -notlike '*dullhide*'  -and $item_string -notlike '*copperhide*'  -and $item_string  -notlike '*goldenwood*'  -and $item_string -notlike '*dullwood*'  -and $item_string -notlike '*verewood*'  -and $item_string -notlike '*valewood*' )
70			{
71				$master_list_string = $master_list_string + $item_string + ";"
72				#echo $item_string
73			}
74			$master_list_count = $master_list_count + 1 
75			$last_item_count = 1
76		}
77		else
78		{
79			#Previous item had multiples
80			$dup_out_string = "        >> [" +  $last_item_count + "] AVAILABLE!"					
81			Add-Content $outfile $dup_out_string	
82			$last_item_count = 1	
83		}
84
85		
86		
87		#build vendor name
88		$new_vendor = 0
89		$item_string = ''
90	}
91	if ($write_check -eq 0 -and $new_vendor -ne 1 -and $line_count -gt 1  -and $line -notlike "*When used, it will*" -and $line -notlike "*That is not accessible*"  -and $line -notlike "*used to increase*"  -and $line -notlike "*Ignore List cleared*"  -and $line -notlike "*completed the achievement*" -and $line -notlike "*Welcome Syal*"  -and $line -notlike "*WorldMap*"   -and $line -notlike "*.xml*" -and $line -notlike "*Not for sale*" -and $line -like "*System*" -and $line -notlike "*New target*" )
92	{
93		#First  line of new item; generally the price, grab and append next lines
94		$total_count = $total_count + 1
95		
96		#Output last build item
97		if($item_string -ne $last_item_string)
98		{
99			#new item - output
100			if($last_item_count -gt 1)
101			{
102				#Previous item had multiples
103				$dup_out_string = "        >> [" +  $last_item_count + "] AVAILABLE!"						
104				Add-Content $outfile $dup_out_string
105			}
106			$dump_item_string = $item_string -replace '(?<=\d)(?=(0{3})+\b)', 'k'
107			$dump_item_string = $dump_item_string -replace 'k000', 'k'
108			Add-Content $outfile $dump_item_string
109			$last_item_count = 1
110			
111			#Add item to master list if it's not on the list	queued actions 		
112			if($item_string -notlike '*carpet dye*' -and $item_string -notlike '*queued actions*'  -and $item_string -notlike '*martial manual*'  -and $item_string -notlike '*gorget*'  -and $item_string -notlike '*Queuing action*' -and $item_string -notlike '*exceptional*' -and $item_string -notlike '*viking sword*' -and $item_string -notlike '*two-handed axe*' -and $item_string -notlike '*select an item*' -and $item_string -notlike '*crossbow*' -and $item_string -notlike '*CATALOGUE*'  -and $item_string -notlike '*black staff*'   -and $item_string -notlike '*battleaxe*'  -and $item_string -notlike '*prestige has*'  -and $item_string -notlike '*melodious*'  -and $item_string -notlike '*spellbook*' -and $item_string -notlike '*container identification wand*'  -and $item_string -notlike '*dullhide*'  -and $item_string -notlike '*copperhide*'  -and $item_string  -notlike '*goldenwood*'  -and $item_string -notlike '*dullwood*'  -and $item_string -notlike '*verewood*'  -and $item_string -notlike '*valewood*' )
113			{
114				$master_list_string = $master_list_string + $item_string + ";"
115				#echo $item_string
116			}
117			$master_list_count = $master_list_count + 1 
118		}
119		else
120		{
121			#repeat item
122			$last_item_count = $last_item_count + 1	
123		}
124		
125		
126		#build new string
127		$line = $line -replace '\[.*\].*System: ', '   - '
128		$last_item_string = $item_string
129		$item_string = $line 
130	}
131	if ($write_check -eq 0 -and $new_vendor -ne 1 -and $line_count -gt 1 -and $line -notlike "*Description*"  -and $line -notlike "*When used, it will*"  -and $line -ne "bag"  -and $line -ne "backpack"  -and $line -ne "wooden box"  -and $line -ne "pouch"  -and $line -notlike "*That is not accessible*"  -and $line -notlike "*used to increase*"   -and $line -notlike "*Price*"  -and $line -notlike "*completed the achievement*"  -and $line -notlike "*New target*" -and $line -notlike  '*`[*`]*')
132	{
133		#Lines to be appended to item
134		$line =  " " + $line 
135		$item_string = $item_string + $line
136		
137	}
138	if ($write_check -eq 0 -and $new_vendor -ne 1 -and $line_count -gt 1 -and $line -like "*Description*"  -and $line -notlike "*When used, it will*"  -and $line -notlike "*That is not accessible*"  -and $line -ne "backpack"  -and $line -ne "wooden box"  -and $line -ne "pouch"  -and $line -notlike "*used to increase*"  -and $line -notlike "*New target*" -and $line -notlike "*completed the achievement*"  -and $line -notlike  '*`[*`]*')
139	{
140		#Lines to be appended to item - Description line
141		$line =  " " + $line + " -- "  
142		$item_string = $item_string + $line
143	} 
144	$last_line = $line
145}
146
147
148#Output last build item
149if($item_string -ne $last_item_string)
150{
151	#new item - output
152	if($last_item_count -gt 1)
153	{
154		#Previous item had multiples
155		$dup_out_string = "        >> [" +  $last_item_count + "] AVAILABLE!"				
156		Add-Content $outfile $dup_out_string
157	}
158	$dump_item_string = $item_string -replace '(?<=\d)(?=(0{3})+\b)', 'k'
159	$dump_item_string = $dump_item_string -replace 'k000', 'k'
160	Add-Content $outfile $dump_item_string
161	$last_item_count = 1
162}
163else
164{
165	#repeat item
166	$last_item_count = $last_item_count + 1			
167	Add-Content $outfile $item_string
168 
169	#Previous item had multiples
170	$dup_out_string = "        >> [" +  $last_item_count + "] AVAILABLE!"					
171	Add-Content $outfile $dup_out_string	
172}
173
174#format master list
175$master_list_string = $master_list_string -replace 'Price: \d+ ', ''
176$master_list_string = $master_list_string -replace '; ;', ';'
177$master_list_string = $master_list_string -replace ' ; ', '; '
178$master_list_string = $master_list_string -replace ' - ', ' '
179$master_list_string = $master_list_string -replace 'When used, it will unlock this spell hue for a randomized spell you do not currently have in this hue.;', ''
180$master_list_string = $master_list_string -replace 'skill mastery scroll', 'SS'
181$master_list_string = $master_list_string -replace 'When used, it will unlock this spell hue for a randomized spell you do not currently have in this hue.;', ''
182$master_list_string = $master_list_string -replace ' ;', ';'
183$master_list_string = $master_list_string -replace 'Aspect', ' '
184$master_list_string = $master_list_string -replace 'Tierra', ''
185$master_list_string = $master_list_string -replace '\s+', ' '
186$master_list_string = $master_list_string -replace '\s+;\s+', ';'
187$master_list_string = $master_list_string -replace ';\s+', ';'
188$master_list_string = $master_list_string -replace ' ;', ';'
189$master_list_string = $master_list_string -replace '\s+;\s+', ';'
190$master_list_string = $master_list_string -replace 'Tierra', ''
191$master_list_string = $master_list_string -replace '\(.*?\)', ''
192$master_list_string = $master_list_string -replace ':.*?;', ';'
193$master_list_string = $master_list_string -replace '\s+', ' '
194$master_list_string = $master_list_string -replace '\s+;\s+', ';'
195$master_list_string = $master_list_string -replace ';\s+', ';'
196$master_list_string = $master_list_string -replace ' ;', ';'
197#echo $master_list_string
198
199#push some stuff we had to cut
200$master_list_string = $master_list_string + "carpet dyes galore;magic spellbooks;container identification wands;"
201
202
203
204$master_list_string = $master_list_string -replace '\s+', ' '
205
206#dedupe and sort list
207$master_list_string = ($master_list_string -split ';' | Sort-Object | Select -Unique) -join ';'
208
209
210$master_list_string_output = $master_list_string_output + $master_list_count + " Unique Items!] and [" + $total_count + " Total Items!] Available `r`n" 
211				
212Add-Content $outfile " "
213Add-Content $outfile " "
214Add-Content $outfile $master_list_string_output	
215
216
217
218
219
220
221
222
223
224
225
226
227