-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdwfinder.bat
198 lines (187 loc) · 7.4 KB
/
rdwfinder.bat
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
@rem = '--*-Perl-*--
@echo off
if "%OS%" == "Windows_NT" goto WinNT
perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
goto endofperl
:WinNT
perl -x -S %0 %*
if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
if %errorlevel% == 9009 echo You do not have Perl in your PATH.
if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
goto endofperl
@rem ';
#!C:\Perl\Bin\perl.exe -w
#line 15
#
#
#
# Zuinige Rijder
#
#
#
#2345678901234567890123456789012345678901234567890123456789012345678901234567890
#===============================================================================
#@description
#
# rdw: Rick's get IONIQ 5 rdw kenteken data
#
#===============================================================================
#use diagnostics;
use strict;
use Carp;
use POSIX qw/strftime/;
use JSON qw( decode_json ); # From CPAN
use Data::Dumper;
$| = 1; # no output buffering
# declaration of subroutine prototypes
sub myDie($);
sub executeCommand($);
my $true=1;
my $false=0;
my $DEBUG=$false;
my $TOGGLE=$true;
my $COUNT=0;
#===============================================================================
# die
# parameter 1: die string
#===============================================================================
sub myDie($) {
my ($txt) = @_;
print "\n", "?" x 80, "\n";
print "Error: $txt\n\n";
croak("$txt\n\n");
exit 1;
}
#===============================================================================
# execute command
# parameter 1: command
# parameter 2: redirect
# return errorlevel
#===============================================================================
sub executeCommand($) {
my ($command) = @_;
my $try = 5;
my $rc;
do {
if ($try < 5) {
print "Retry: $try\n";
}
$try--;
$COUNT++;
#$command = correctSlashes($command);
# Perl with Nutcracker should have double DOS slashes
# ActivePerl does not care
print "Before: $command 2>&1\n" if $DEBUG;
#$command =~ s?/?\\\\?g; # change single / into double \\
#$command =~ s?\\?\\\\?g; # change single \ into double \\
#$command =~ s?\\\\\\\\?\\\\?g; # change multiple \\ into single \\
#print "After: $command 2>&1\n" if $DEBUG;
$rc = 0xffff & system("$command 2>&1");
if ($rc == 0) {
# everything Ok
return 0;
} elsif ($rc == 0xff00) {
print "ERROR: Command [$command] failed: $!\n";
} elsif ($rc > 0x80) {
$rc >>= 8;
print "ERROR: Command [$command] exited with non-zero exit status: $rc\n";
} else {
print "ERROR: Command [$command] exited with ";
if ($rc & 0x80) {
$rc &= ~0x80;
print "coredump from ";
}
print "signal $rc\n";
}
} while ($rc != 0 and $try > 0);
return $rc;
}
if (@ARGV != 5) {
myDie("Usage: rdwfinder BEGINLETTER ENDLETTERS FROM TO INCREMENT, e.g. rdwfinder R LF 510 560 1");
}
my $BEGINLETTER = $ARGV[0];
my $LETTERS = $ARGV[1];
my $from = $ARGV[2];
my $to = $ARGV[3];
if ($to < $from) {
my $tmp = $to;
$to = $from;
$from = $tmp;
}
my $increment = $ARGV[4];
uc $BEGINLETTER;
uc $LETTERS;
my @results;
my $current = $from;
my $count = 0;
my $start_time = time();
my $BEGIN_TIME = time();
print strftime('%Y-%m-%d %H:%M:%S',localtime);
print "\n";
while ($current <= $to and $current <= 1000 and $current >= 0) {
my $currentNumber = sprintf("%03s", $current);
my $kenteken = "$BEGINLETTER$currentNumber" . "$LETTERS";
$current += $increment;
print "Getting details of kenteken: $kenteken\n" if $DEBUG;
my $filename="x.rdwf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gL%2F%2F%2F%2F%2FD2QFF2N0bDAwJE1haW5Db250ZW50JGN0bDEwDxQrAA5kZGRkZGRkFCsAA2RkZAIDZGRkZgL%2F%2F%2F%2F%2FD2QFF2N0bDAwJE1haW5Db250ZW50JGN0bDMyDxQrAA5kZGRkZGRkFCsAA2RkZAIDZGRkZgL%2F%2F%2F%2F%2FD2QFF2N0bDAwJE1haW5Db250ZW50JGN0bDEyDxQrAA5kZGRkZGRkPCsABQACBWRkZGYC%2F%2F%2F%2F%2Fw9kBRdjdGwwMCRNYWluQ29udGVudCRjdGwwOA8UKwAOZGRkZGRkZDwrAAcAAgdkZGRmAv%2F%2F%2F%2F8PZAUXY3RsMDAkTWFpbkNvbnRlbnQkY3RsMTgPFCsADmRkZGRkZGQ8KwAEAAIEZGRkZgL%2F%2F%2F%2F%2FD2QFF2N0bDAwJE1haW5Db250ZW50JGN0bDA0DxQrAA5kZGRkZGRkPCsADAACDGRkZGYC%2F%2F%2F%2F%2Fw9kBRdjdGwwMCRNYWluQ29udGVudCRjdGwyOA8UKwAOZGRkZGRkZDwrAAcAAgdkZGRmAv%2F%2F%2F%2F8PZNmHhgdEC2dk11hzIudYxHwUwGfK4eXG%2Fo9Cu8qdtlVL&__VIEWSTATEGENERATOR=CA0B0334&__EVENTVALIDATION=%2FwEdAALw6Ljfck63rzOJzJwmCORy851Fq81QBiZgFEttEk2eePY91dYtbp8ZA%2BHq0kU34KFnAvRU3Nv8x3coJguc2YKX&ctl00%24TopContent%24txtKenteken=' . "$kenteken" . '" https://ovi.rdw.nl/default.aspx > x.rdwfind.html';
#my $cmd = 'curl -X GET https://www.autoweek.nl/kentekencheck/' . "$kenteken" . '/ > ' . $filename;
print "$count: Checking $kenteken\n";
executeCommand($cmd);
open(KENTEKENFILE, "$filename") or myDie("Cannot open for read: $filename: $!\n");
my $match = $false;
my $matchHyundai = $false;
while (<KENTEKENFILE>) {
my $line = "$_";
chomp $line;
if ($line =~ 'IONIQ5') {
print "MATCH IONIQ5: $kenteken\n";
push @results, $kenteken;
$match = $true;
$matchHyundai = $true;
$count++;
last;
} elsif ($line =~ 'HYUNDAI') {
#print "MATCH HYUNDAI: $kenteken\n" if not $matchHyundai;
$matchHyundai = $true;
} elsif ($line =~ 'Het maximaal aantal opvragingen per dag' or $line =~ 'dienst ontzegd') {
print "$line\n";
sleep(30);
$current -= $increment;
} elsif ($line =~ 'Er zijn geen gegevens gevonden voor het ingevulde kenteken') {
print "GEEN GEGEVENS: $kenteken\n";
}
}
close(KENTEKENFILE);
#if ($match) {
# rename "$filename", "$filename.match.html" or myDie "Cannot rename file: $!";
#}
my $stop_time = time();
my $diff_time = $stop_time - $start_time;
$TOGGLE = not $TOGGLE;
my $wait_time;
if ($TOGGLE) {
$wait_time = 3 - $diff_time; # at least wait some seconds
} else {
$wait_time = 2 - $diff_time; # at least wait some seconds
}
print "Diff: [$diff_time], Wait: [$wait_time]\n" if $DEBUG;
if ($wait_time > 0) {
sleep($wait_time);
}
$start_time = time();
}
print "\n\nAlle detail resultaten:\n\n";
foreach (sort @results) {
print "$_\n";
}
print "Totaal aantal IONIQ5: $count\n";
print strftime('%Y-%m-%d %H:%M:%S',localtime);
my $END_TIME = time();
my $ELAPSED_TIME = $END_TIME - $BEGIN_TIME;
print " Elapsed: [$ELAPSED_TIME]\n";
__END__
:endofperl