-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdw_utils.py
1367 lines (1225 loc) · 49.9 KB
/
rdw_utils.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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""rdw_utils.py"""
# pylint:disable=too-many-lines
from datetime import datetime
import re
import socket
import sys
import time
import traceback
from urllib import request
from urllib.error import HTTPError, URLError
# == log ========================================================================
def log(msg: str) -> None:
"""log a message prefixed with a date/time format yyyymmdd hh:mm:ss"""
print(datetime.now().strftime("%Y%m%d %H:%M:%S") + ": " + msg)
# ===============================================================================
# my_die
# parameter 1: die string
# ===============================================================================
def my_die(txt):
"""my_die"""
# Note that Python doesn't have a direct equivalent to Perl's croak
# function, so I've replaced it with sys.exit(1) which will terminate
# the program with an exit code of 1 (indicating an error).
log("\n" + "?" * 80 + "\n")
log(f"Error: {txt}\n\n")
traceback.print_stack()
sys.exit(1)
# == get_kentekens ====================================================================
def get_kentekens():
"""get_kentekens and handle errors"""
while True:
url = "https://opendata.rdw.nl/api/id/m9d7-ebf2.json?$select=*&$order=`:id`+ASC&$limit=8000&$offset=0&$where=(%60handelsbenaming%60%20%3D%20%27IONIQ5%27)&$$read_from_nbe=true&$$version=2.1" # noqa
errorstring = ""
try:
request.urlretrieve(url, "x.kentekens")
return
except HTTPError as error:
errorstring = str(error.status) + ": " + error.reason
except URLError as error:
errorstring = str(error.reason)
except TimeoutError:
errorstring = "Request timed out"
except socket.timeout:
errorstring = "Socket timed out"
except Exception as ex: # pylint: disable=broad-except
errorstring = "urlopen exception: " + str(ex)
traceback.print_exc()
log(f"RDW ERROR (retry after 1 minute): {errorstring} -> {url}")
time.sleep(60) # retry after 1 minute
# ===============================================================================
# arg_has
# parameter 1: string argument to match
# ===============================================================================
def arg_has(string: str) -> bool:
"""arguments has string"""
for i in range(1, len(sys.argv)):
if string in sys.argv[i].lower():
return True
return False
# ===============================================================================
# round5
# parameter 1: integer number
# ===============================================================================
def round5(number):
"""round5"""
remainder = number % 5
if remainder < 3:
return number - remainder
else:
return number - remainder + 5
def print_import_separate(
input_list: list,
header_not_import: str,
header_import: str,
replace_nog_niet_op_naam: bool = False,
):
"""print_import_separate"""
import_list = []
not_import_list = []
for string in input_list:
if replace_nog_niet_op_naam:
string = string.replace(" (nog niet op naam)", "")
if "geimporteerd" in string:
import_list.append(string)
else:
not_import_list.append(string)
if len(not_import_list) > 0:
print(header_not_import)
print("[code]")
for string in not_import_list:
print(string)
print("[/code]\n")
if len(import_list) > 0:
print(header_import)
print("[code]")
for string in import_list:
print(string)
print("[/code]\n")
# ===============================================================================
# fill_price
# parameter 1: hash reference
# parameter 2: variant
# parameter 3: prijscheck
# parameter 4: batterijgrootte
# parameter 5: AWD
# parameter 6: model2023
# parameter 7: prijslijst
# return variant
#
# 795 V2L (alleen op Style i.c.m. warmtepomp)
# 1200 WP (alleen beschikbaar op Style en Connect)
# 895 Panoramadak (alleen op Lounge)
# 1200 Zonnedak (alleen op Lounge)
# -750 geen FCA-JX en HDA2 (alleen op Connect, Connect+ en Lounge)
# 400 digitale binnenspiegel (2023 model)
# 1400 digitale buitenspiegels (2023 model)
# 0 19 inch wielen i.p.v. 20 inch (alleen Lounge)
#
def fill_price(
debug, prices, variant, prijscheck, batterijgrootte, arg_awd, model2023, prijslijst
):
"""fill_price"""
if debug:
print(
f"{variant}, {prijscheck}, {batterijgrootte}, {arg_awd:d}, {model2023:d}, {prijslijst}" # noqa
)
zonder_fca_hda2 = prijslijst != "mei 2021"
prijslijst = " (prijslijst " + prijslijst + ")"
duurder1500 = False
batterijgrootte = str(batterijgrootte) + " kWh "
if arg_awd:
batterijgrootte += "AWD "
prices[prijscheck] = batterijgrootte + variant + prijslijst
if duurder1500:
prices[prijscheck + 1500] = (
batterijgrootte + variant + prijslijst + " (1500 euro duurder)"
)
if variant == "Style":
prices[prijscheck + 1200] = batterijgrootte + variant + " met WP" + prijslijst
prices[prijscheck + 1200 + 795] = (
batterijgrootte + variant + " met WP en V2L" + prijslijst
)
if duurder1500:
prices[prijscheck + 1200 + 1500] = (
batterijgrootte
+ variant
+ " met WP"
+ prijslijst
+ " (1500 euro duurder)"
)
prices[prijscheck + 1200 + 795 + 1500] = (
batterijgrootte
+ variant
+ " met WP en V2L"
+ prijslijst
+ " (1500 euro duurder)"
)
elif variant == "Lounge":
prices[prijscheck + 895] = (
batterijgrootte + variant + " met Panoramadak" + prijslijst
)
prices[prijscheck + 1200] = (
batterijgrootte + variant + " met Zonnepanelendak" + prijslijst
)
if duurder1500:
prices[prijscheck + 895 + 1500] = (
batterijgrootte
+ variant
+ " met Panoramadak"
+ prijslijst
+ " (1500 euro duurder)"
)
prices[prijscheck + 1200 + 1500] = (
batterijgrootte
+ variant
+ " met Zonnepanelendak"
+ prijslijst
+ " (1500 euro duurder)"
)
if zonder_fca_hda2:
prices[prijscheck - 750] = (
batterijgrootte + variant + " zonder FCA-JX/HDA2" + prijslijst
)
prices[prijscheck + 895 - 750] = (
batterijgrootte
+ variant
+ " met Panoramadak zonder FCA-JX/HDA2"
+ prijslijst
)
prices[prijscheck + 1200 - 750] = (
batterijgrootte
+ variant
+ " met Zonnepanelendak zonder FCA-JX/HDA2"
+ prijslijst
)
if duurder1500:
prices[prijscheck - 750 + 1500] = (
batterijgrootte
+ variant
+ " zonder FCA-JX/HDA2"
+ prijslijst
+ " (1500 euro duurder)"
)
prices[prijscheck + 895 - 750 + 1500] = (
batterijgrootte
+ variant
+ " met Panoramadak zonder FCA-JX/HDA2"
+ prijslijst
+ " (1500 euro duurder)"
)
prices[prijscheck + 1200 - 750 + 1500] = (
batterijgrootte
+ variant
+ " met Zonnepanelendak zonder FCA-JX/HDA2"
+ prijslijst
+ " (1500 euro duurder)"
)
if model2023:
prices[prijscheck + 1400] = (
batterijgrootte + variant + " met digitale buitenspiegels" + prijslijst
)
prices[prijscheck + 895 + 1400] = (
batterijgrootte
+ variant
+ " met Panoramadak en digitale buitenspiegels"
+ prijslijst
)
prices[prijscheck + 1200 + 1400] = (
batterijgrootte
+ variant
+ " met Zonnepanelendak en digitale buitenspiegels"
+ prijslijst
)
if zonder_fca_hda2:
prices[prijscheck + 1400 - 750] = (
batterijgrootte
+ variant
+ " met digitale buitenspiegels zonder FCA-JX/HDA2"
+ prijslijst
)
prices[prijscheck + 895 + 1400 - 750] = (
batterijgrootte
+ variant
+ " met Panoramadak en digitale buitenspiegels zonder FCA-JX/HDA2"
+ prijslijst
)
prices[prijscheck + 1200 + 1400 - 750] = (
batterijgrootte
+ variant
+ " met Zonnepanelendak en digitale buitenspiegels zonder FCA-JX/HDA2" # noqa
+ prijslijst
)
elif variant == "Connect":
prices[prijscheck + 1200] = batterijgrootte + variant + " met WP" + prijslijst
if duurder1500:
prices[prijscheck + 1200 + 1500] = (
batterijgrootte
+ variant
+ " met WP"
+ prijslijst
+ " (1500 euro duurder)"
)
if zonder_fca_hda2:
prices[prijscheck - 750] = (
batterijgrootte + variant + " zonder FCA-JX/HDA2" + prijslijst
)
prices[prijscheck + 1200 - 750] = (
batterijgrootte + variant + " met WP zonder FCA-JX/HDA2" + prijslijst
)
if duurder1500:
prices[prijscheck - 750 + 1500] = (
batterijgrootte
+ variant
+ " zonder FCA-JX/HDA2"
+ prijslijst
+ " (1500 euro duurder)"
)
prices[prijscheck + 1200 - 750 + 1500] = (
batterijgrootte
+ variant
+ " met WP zonder FCA-JX/HDA2"
+ prijslijst
+ " (1500 euro duurder)"
)
elif variant == "Connect+":
if zonder_fca_hda2:
prices[prijscheck - 750] = (
batterijgrootte + variant + " zonder FCA-JX/HDA2" + prijslijst
)
if duurder1500:
prices[prijscheck - 750 + 1500] = (
batterijgrootte
+ variant
+ " zonder FCA-JX/HDA2"
+ prijslijst
+ " (1500 euro duurder)"
)
else:
my_die("PROGRAMERROR: variant niet bekend: " + variant)
def safe_get_key(hash_, key):
"""safe_get_key"""
if key in hash_:
return hash_[key]
return ""
def safe_get_pricelists_key(pricelists, key):
"""safe_get_pricelists_key"""
if key in pricelists:
return pricelists[key]
return {}
def get_prijs(pricelists, key, prijs):
"""get_prijs"""
result = ""
if key in pricelists:
item = pricelists[key]
if prijs in item:
result = item[prijs]
return result
# ===============================================================================
# find_variant_exact
# parameter 1: kenteken
# parameter 2: prijs
# parameter 3: variant
# parameter 4: model2023
# parameter 5: date
# return variant
def find_variant_exact(
pricelists, pricelists_dates, debug, kenteken, prijs, variant, model2023, date
):
"""findVariantExact"""
awd = variant == "F5E14" or variant == "F5E54"
smallbattery = variant == "F5E42"
result = ""
checked_one_pricelist = False
for pricelist_date in pricelists_dates:
if int(date) < int(pricelist_date) or (
checked_one_pricelist and pricelist_date[0:6] < date[0:6]
):
if debug:
print(f"{kenteken} Skipping pricelist [{pricelist_date}] for [{date}]")
continue # skip registration dates before prijslist date
checked_one_pricelist = True
if debug:
print(f"Checking {kenteken} pricelist [{pricelist_date}] for [{date}]")
if smallbattery:
if model2023:
result = get_prijs(pricelists, f"{pricelist_date}_58_2023", prijs)
else:
result = get_prijs(pricelists, f"{pricelist_date}_58", prijs)
elif awd:
if model2023:
result = get_prijs(pricelists, f"{pricelist_date}_77AWD", prijs)
else:
result = get_prijs(pricelists, f"{pricelist_date}_73AWD", prijs)
else:
if model2023:
result = get_prijs(pricelists, f"{pricelist_date}_77", prijs)
else:
result = get_prijs(pricelists, f"{pricelist_date}_73", prijs)
if result != "":
if debug:
print(f"{kenteken} find_variant_exact found result {result}")
break # found result....
if debug:
small_str = ""
if smallbattery:
small_str = "1"
awd_str = ""
if awd:
awd_str = "1"
print(
f"findVariantExact {kenteken} result {prijs}, {awd_str}, {small_str}: [{result}]" # noqa
)
return result
# ===============================================================================
# find_helper
# parameter 1: prices hash
# parameter 2: prijs
# return variant
def find_helper(debug, prices, prijs):
"""find_helper"""
found_delta = 9999999
found_price = 0
for price in prices:
delta = abs(prijs - price)
if delta < found_delta:
found_delta = delta
found_price = price
result = safe_get_key(prices, found_price)
if result != "" and found_delta != 0:
delta = prijs - found_price
abs_delta = abs(delta)
if abs_delta == delta:
result += f" $(E{abs_delta} duurder dan prijslijst)"
else:
result += f" $(E{abs_delta} goedkoper dan prijslijst)"
if debug:
print(f"findHelper result {prijs}: {result}")
return result
# ===============================================================================
# find_variant_nearest
# parameter 1: kenteken
# parameter 2: prijs
# parameter 3: variant
# parameter 4: model2023
# parameter 5: date
# return variant
def find_variant_nearest(
pricelists, pricelists_dates, debug, kenteken, prijs, variant, model2023, date
):
"""find_variant_nearest"""
awd = variant in ("F5E14", "F5E54")
smallbattery = variant == "F5E42"
result = ""
checked_one_pricelist = False
for pricelist_date in pricelists_dates:
if int(date) < int(pricelist_date) or (
checked_one_pricelist and pricelist_date[0:6] < date[0:6]
):
if debug:
print(
f"{kenteken} Skipping nearest pricelist {pricelist_date} for {date}"
)
continue # skip registration dates before pricelist date
checked_one_pricelist = True
if debug:
print(
f"Checking nearest pricelist {kenteken} pricelist {pricelist_date} for {date}" # noqa
)
if smallbattery:
if model2023:
result = find_helper(
debug,
safe_get_pricelists_key(pricelists, pricelist_date + "_58_2023"),
prijs,
)
else:
result = find_helper(
debug,
safe_get_pricelists_key(pricelists, pricelist_date + "_58"),
prijs,
)
elif awd:
if model2023:
result = find_helper(
debug,
safe_get_pricelists_key(pricelists, pricelist_date + "_77AWD"),
prijs,
)
else:
result = find_helper(
debug,
safe_get_pricelists_key(pricelists, pricelist_date + "_73AWD"),
prijs,
)
else:
if model2023:
result = find_helper(
debug,
safe_get_pricelists_key(pricelists, pricelist_date + "_77"),
prijs,
)
else:
result = find_helper(
debug,
safe_get_pricelists_key(pricelists, pricelist_date + "_73"),
prijs,
)
if result != "":
if debug:
print(f"{kenteken} find_variant_nearest found result {result}")
break
if debug:
small_str = ""
if smallbattery:
small_str = "1"
awd_str = ""
if awd:
awd_str = "1"
print(
f"findVariantNearest {kenteken} result {prijs}, {awd_str}, {small_str}: [{result}]" # noqa
)
return result
def clean_variant(value, debug):
"""clean_variant"""
stripped = value
if debug:
print(f"clean variant before: [{stripped}]")
stripped = re.sub(
r"\$\(E[0-9]+ [a-z]+ dan prijslijst\)", "", stripped
) # exclude dollar and goedkoper/duurder
stripped = stripped.replace("$", "") # exclude dollar in counting
stripped = re.sub(
r" \(model 202[^)]+\)", "", stripped, flags=re.IGNORECASE
) # exclude model in counting
stripped = re.sub(
r" \(Taxi\)", "", stripped, flags=re.IGNORECASE
) # exclude taxi in counting
stripped = re.sub(
r" \(geexporteerd\)", "", stripped, flags=re.IGNORECASE
) # exclude geexporteerd in counting
stripped = re.sub(
r" \(prijslijst [^)]+\)", "", stripped, flags=re.IGNORECASE
) # exclude prijslijst in counting
stripped = re.sub(
r" \(1500 euro duurder\)", "", stripped, flags=re.IGNORECASE
) # exclude prijsinfo in counting
stripped = re.sub(
r" \(1495 euro duurder\)", "", stripped, flags=re.IGNORECASE
) # exclude prijsinfo in counting
stripped = re.sub(
r" zonder FCA-JX/HDA2", "", stripped, flags=re.IGNORECASE
) # exclude prijsinfo in counting
stripped = re.sub(
r" \(19 inch banden\)", "", stripped, flags=re.IGNORECASE
) # exclude bandeninfo in counting
stripped = re.sub(
r" \(20 inch banden\)", "", stripped, flags=re.IGNORECASE
) # exclude bandeninfo in counting
stripped = re.sub(
r" \(Digital Teal, Mystic Olive met Panoramadak\)",
"",
stripped,
flags=re.IGNORECASE,
) # exclude colorinfo in counting
stripped = re.sub(r" \(Olive\)", "", stripped) # exclude colorinfo in counting
stripped = re.sub(
r" \(Shooting Star\)", "", stripped
) # exclude colorinfo in counting
stripped = re.sub(
r" \(Atlas White Matte\)", "", stripped
) # exclude colorinfo in counting
stripped = stripped.rstrip() # remove trailing spaces
if debug:
print(f"clean variant after: [{stripped}]")
return stripped
# ===============================================================================
# getVariant and count variants at the same time
# parameter 1: type
# parameter 2: opNaam
# parameter 3: kenteken
# parameter 4: date
# return type
#
# Legenda:
#
# Typegoedkeuring:
# e9*2018/858*11054*01 since 20210405 (model 2022)
# e9*2018/858*11054*03 since 20220210 (model 2022.5)
# e9*2018/858*11054*04 since 20220708 (model 2023)
#
# Variant:
# F5E14=72 kWh AWD (model 2022)
# F5E32=72 kWh RWD (model 2022)
# F5E42=58 kWh RWD (model 2022/2023)
# F5E54=77 kWh AWD (model 2023)
# F5E62=77 kWh RWD (model 2023)
#
# Uitvoering:
# E11A11=19 inch
# E11B11=20 inch
#
# Kleuren:
# GEEL Gravity Gold (Mat)
# ZWART Phantom Black (Mica Parelmoer)
# GROEN Digital Teal (Mica Parelmoer), Mystic Olive (Mica)
# BLAUW Lucid Blue (Mica Parelmoer)
# GRIJS Shooting Star (Mat), Cyber Grey (Metal.), Galactic Gray (Metal.)
# WIT Atlas White (Solid)
# BRUIN Mystic Olive (Mica)
#
# 795 V2L (alleen op Style i.c.m. warmtepomp)
# 1200 WP (alleen beschikbaar op Style en Connect)
# 895 Panoramadak (alleen op Lounge)
# 1200 Zonnedak (alleen op Lounge)
# -750 geen FCA-JX en HDA2 (alleen op Connect, Connect+ en Lounge)
# 400 digitale binnenspiegel (2023 model)
# 1400 digitale buitenspiegels (2023 model)
# 0 19 inch wielen i.p.v. 20 inch (alleen Lounge)
#
# Extra prijzen kleuren
# 695 Wit
# 895 Mica/Metallic
# 1095 Matte
#
# ===============================================================================
def get_variant(
pricelists,
pricelists_dates,
debug,
par,
fulltype,
op_naam,
kenteken,
date,
):
"""get_variant"""
value = "ERROR"
(
taxi,
export,
count20inch,
countlounge20inch,
count19inch,
countlounge19inch,
colormatte,
colormica,
colorsolid,
colormicapearl,
colormetallic,
variantscount,
variantscountnognietopnaam,
) = par
if debug:
print(f"#kenteken: {kenteken}")
print(f"#fulltype: {fulltype}")
print(f"#opNaam : {op_naam:d}")
print(f"#date : {date}")
if int(date) < 20210401 or int(date) > 20250101:
my_die(f"Unexpected date: {date} for {kenteken} {fulltype}\n")
kleur = "GRIJS"
inch20 = True
# F5E14;E11B11;e9*2018/858*11054*01; prijs: 59600 GRIJS
# $variant;$uitvoering;$typegoedkeuring; prijs: $prijs $kleur";
# 1 2 3 4 5 6 7 8
# 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
variant, uitvoering, typegoedkeuring, prijskleur = fulltype.split(";")
prijskleur = re.sub(" +", " ", prijskleur) # multiple spaces replaced by one
prijskleur = prijskleur.strip() # remove leading/trailing space
if not prijskleur.startswith("prijs: "):
my_die(f"Geen prijs in fulltype: {fulltype}")
if variant == "F5E14":
value = "73 kWh AWD"
elif variant == "F5E32":
value = "73 kWh"
elif variant == "F5E42":
value = "58 kWh"
elif variant == "F5E54":
value = "77 kWh"
elif variant == "F5E62":
value = "77 kWh"
elif variant == "F5E24": # error??
value = "58 kWh"
else:
my_die(f"ERROR: variant {variant} fout voor {kenteken}: {fulltype}")
if uitvoering != "E11A11" and uitvoering != "E11B11":
my_die(f"ERROR: uitvoering {uitvoering} fout voor {kenteken}: {fulltype}")
inch20 = uitvoering == "E11B11"
if inch20 and variant == "F5E42":
my_die("58 kWh and 20 inch not possible")
if (
typegoedkeuring != "e9*2018/858*11054*01"
and typegoedkeuring != "e9*2018/858*11054*03"
and typegoedkeuring != "e9*2018/858*11054*04"
):
my_die(
f"ERROR: typegoedkeuring {typegoedkeuring} fout voor {kenteken}: {fulltype}"
)
model2023 = typegoedkeuring == "e9*2018/858*11054*04"
prijskleur = prijskleur.replace("prijs: ", "")
prijsstr, tempkleur = prijskleur.split()
prijs = int(prijsstr)
kleur = tempkleur
if kleur not in ["WIT", "GRIJS", "GROEN", "ZWART", "BLAUW", "GEEL", "BRUIN"]:
my_die(f"ERROR: kleur {kleur} fout voor {kenteken}: {fulltype}")
if (prijs < 4200 or prijs > 75000) and prijs not in [
42000,
72300,
33589,
37831,
5242655,
78650,
76580,
]:
my_die(f"ERROR: prijs {prijs} fout voor {kenteken}: {fulltype}")
if debug:
print(f"#prijs : {prijs}")
# round prijs to multiple of 5 euro
prijs = round5(prijs)
if debug:
print(f"#prijs5 : {prijs}")
print(f"#kleur : {kleur}")
prijs2 = prijs
if variant == "F5E14":
if prijs == 58000:
value = "PROJECT45"
elif kenteken in ["L162KD", "L430TK", "L431TK", "L432TK", "N309TK", "P229NR"]:
value = "PROJECT45$"
if value != "PROJECT45" and value != "PROJECT45$":
if kleur == "WIT":
if model2023:
prijs -= 695
prijs2 -= 1095
else:
prijs -= 695
prijs2 = 0
elif kleur == "ZWART":
prijs -= 895
prijs2 = 0
elif kleur == "BLAUW":
if date > "20220801":
prijs2 -= 895
else:
prijs -= 895
prijs2 = 0
elif kleur == "GEEL":
prijs -= 1095
prijs2 = 0
elif kleur == "GRIJS":
prijs -= 895
prijs2 -= 1095
elif kleur == "GROEN":
prijs2 -= 895
elif kleur == "BRUIN":
prijs2 = 0
else:
my_die(f"PROGRAMERROR: kleur {kleur} fout voor {kenteken}: {fulltype}")
found_variant = find_variant_exact(
pricelists,
pricelists_dates,
debug,
kenteken,
prijs,
variant,
model2023,
date,
)
found_variant2 = ""
if prijs != prijs2 and prijs2 != 0:
found_variant2 = find_variant_exact(
pricelists,
pricelists_dates,
debug,
kenteken,
prijs2,
variant,
model2023,
date,
)
if found_variant == "" and found_variant2 == "":
found_variant = find_variant_nearest(
pricelists,
pricelists_dates,
debug,
kenteken,
prijs,
variant,
model2023,
date,
)
found_variant2 = ""
if prijs != prijs2 and prijs2 != 0:
found_variant2 = find_variant_nearest(
pricelists,
pricelists_dates,
debug,
kenteken,
prijs2,
variant,
model2023,
date,
)
delta1 = 9999999
delta2 = 9999999
if re.search(r"dan prijslijst\)", found_variant):
string = re.sub(r".*\$\(E", "", found_variant)
string = re.sub(r" [a-z]+ dan prijslijst\).*", "", string)
delta1 = int(string)
if re.search(r"dan prijslijst\)", found_variant2):
string = re.sub(r".*\$\(E", "", found_variant2)
string = re.sub(r" [a-z]+ dan prijslijst\).*", "", string)
delta2 = int(string)
if abs(delta2) < abs(delta1):
found_variant = ""
else:
found_variant2 = ""
if found_variant != "" and found_variant2 != "":
if kleur != "GROEN":
if debug:
print(
f"WARNING: 2 variants found for {kenteken} {kleur}: [{found_variant}] and [{found_variant2}]" # noqa
)
if kleur == "GRIJS":
if found_variant2 != "":
found_variant2 += " (Shooting Star)"
if found_variant != "":
if debug:
print(
f"Found DUBBEL GRIJS {kenteken}: {fulltype} -> [{found_variant}],[{found_variant2}]" # noqa
)
found_variant2 = ""
if debug:
print(f"{kenteken} Genomen: {fulltype} -> {found_variant}")
elif kleur == "WIT":
if found_variant2 != "":
found_variant2 += " (Atlas White Matte)"
if found_variant != "":
if debug:
print(
f"Found DUBBEL WHITE {kenteken}: {fulltype} -> [{found_variant}],[{found_variant2}]" # noqa
)
if model2023:
found_variant = ""
if debug:
print(f"{kenteken} Genomen: {fulltype} -> {found_variant2}")
else:
found_variant2 = ""
if debug:
print(f"{kenteken} Genomen: {fulltype} -> {found_variant}")
elif kleur == "GROEN":
if found_variant != "":
found_variant += " (Olive)"
if debug:
print(
f"Found OLIVE GROEN {kenteken}: {fulltype} -> {found_variant}" # noqa
)
if found_variant != "" and found_variant2 != "":
if re.search("Panoramadak", found_variant, re.IGNORECASE):
found_variant2 += " (Digital Teal, Mystic Olive met Panoramadak)"
if debug:
print(
f"Found DUBBEL GROEN {kenteken}: {fulltype} -> [{found_variant}],[{found_variant2}]" # noqa
)
found_variant = ""
else:
if debug:
print(
f"Found UNEXPECTED DUBBEL GROEN {kenteken}: {fulltype} -> [{found_variant}],[{found_variant2}]" # noqa
)
found_variant = "" # assume digital teal
if debug:
print(f"{kenteken} Genomen: {fulltype} -> {found_variant2}")
if found_variant == "":
found_variant = found_variant2
value = found_variant
if debug:
print(f"#value={value}")
if inch20:
if "Lounge" not in value and "PROJECT45" not in value:
value += " (20 inch banden)"
else:
if "Lounge" in value or "PROJECT45" in value:
value += " (19 inch banden)"
if inch20:
count20inch += 1
if "Lounge" in value:
countlounge20inch += 1
else:
count19inch += 1
if "Lounge" in value:
countlounge19inch += 1
if taxi == "Ja":
value += " (Taxi)"
if debug:
print(f"VALUE: {value}")
if export == "Ja":
value += " (geexporteerd)"
if debug:
print(f"VALUE: {value}")
if debug:
value += f" ({typegoedkeuring})"
if typegoedkeuring == "e9*2018/858*11054*01":
value += " (model 2022)"
elif typegoedkeuring == "e9*2018/858*11054*03":
value += " (model 2022.5)"
elif typegoedkeuring == "e9*2018/858*11054*04":
value += " (model 2023)"
if kleur == "WIT":
if re.search(r"\(Atlas White Matte\)", value, re.IGNORECASE):
colormatte += 1
else:
colorsolid += 1
elif kleur == "ZWART":
colormicapearl += 1
elif kleur == "BLAUW":
colormicapearl += 1
elif kleur == "GEEL":
colormatte += 1
elif kleur == "GRIJS":
if re.search(r"\(Shooting Star\)", value, re.IGNORECASE):
colormatte += 1
else:
colormetallic += 1
elif kleur == "GROEN":
if re.search(r"\(Olive\)", value, re.IGNORECASE):
colormica += 1
else:
colormicapearl += 1
elif kleur == "BRUIN":
colormica += 1
else:
my_die(f"PROGRAMERROR: kleur {kleur} fout voor {kenteken}: {fulltype}")
stripped = clean_variant(value, debug)
if stripped in variantscount:
variantscount[stripped] += 1
else:
variantscount[stripped] = 1
if not op_naam:
if stripped in variantscountnognietopnaam:
variantscountnognietopnaam[stripped] += 1
else:
variantscountnognietopnaam[stripped] = 1
if debug:
print(f"#RETURN: [{value}]")
return_value = (
value,
taxi,
export,
count20inch,
countlounge20inch,
count19inch,
countlounge19inch,
colormatte,
colormica,
colorsolid,
colormicapearl,
colormetallic,
variantscount,
variantscountnognietopnaam,
)
return return_value