137 lines
4.2 KiB
Python
137 lines
4.2 KiB
Python
import os
|
|
import django
|
|
|
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "car_inventory.settings")
|
|
django.setup()
|
|
|
|
from inventory.models import *
|
|
from rich import print
|
|
import random
|
|
import datetime
|
|
|
|
from inventory.services import decodevin
|
|
|
|
|
|
def run():
|
|
# car = Car.objects.filter(vin='2C3HD46R4WH170267')
|
|
vin_list = [
|
|
"1B3ES56C13D120225",
|
|
"1GB4KYC86FF131536",
|
|
"1HSHXAHR15J136217",
|
|
"1G1ZT52845F231124",
|
|
"1J4GK48K43W721617",
|
|
"JTDBE32K430163717",
|
|
"1J4FA69S05P331572",
|
|
"2FMGK5D86EBD28496",
|
|
"KNADE243696530337",
|
|
"1N4AL21EX8N499928",
|
|
"1N4AL21E49N400571",
|
|
"1G2NW12E54C145398",
|
|
"LGJE1EE09SM333542",
|
|
"LGJE1EE0XSM333551",
|
|
"LGJE1EE02SM333561",
|
|
"LGJE1EE0XSM333565",
|
|
"LGJE1EE01SM333549",
|
|
"LGJE1EE06SM333563",
|
|
"LGJE1EE04SM333562",
|
|
"LGJE1EE08SM333564",
|
|
"LFB1E6078P1Y01338",
|
|
"LGJE5EE02PM046815",
|
|
"LFB1E6074P1Y01742",
|
|
"LGJE5EE07PM132850",
|
|
"LGJE1EE08SM311094",
|
|
"LFPH4ACP4P2A00123",
|
|
"LFB1E6075R1Y00117",
|
|
"ZAMPP56F0J1282425",
|
|
"LGJE1EE06RM292314",
|
|
"LGJE1EE00NM013594",
|
|
"LFB1E6075M1Y00272",
|
|
"LFB1E6670P1Y00224",
|
|
"LFB1E6079N1Y00275",
|
|
"LGJE3FE00MM804819",
|
|
"LGJE3FE0XMM804844",
|
|
"LGJE1EE01RM200767",
|
|
"LGJE1EE08RM200703",
|
|
"ZAMXS57F7L1341373",
|
|
"LGJE5EE06SM330781",
|
|
"LFB1E6077P1Y02643",
|
|
"LFB1E6074M1Y00151",
|
|
"LGJE1EE07RM292323",
|
|
"LGJE1EE01RM200171",
|
|
"LGJE1EE04SM311545",
|
|
"LGJE1EE04RM292859",
|
|
"LGJE1EE02RM292861",
|
|
"LFB1E607XP1Y01454",
|
|
"LFB1E6073P1Y00081",
|
|
"LGJE1EE03PM129391",
|
|
"LGJE1EE03RM200639",
|
|
"LGJE1EE02PM128393",
|
|
"LGJE1EE03NM964436",
|
|
"LGJE1EE06RM211599",
|
|
"LGJE1EE06NM014104",
|
|
"LGJE1EE05NM014272",
|
|
"LGJE5EE06SM331641",
|
|
"LGJE1EE09NM013528",
|
|
"LGJE5EE0XPM048196",
|
|
"LGJE1EE01RM212935",
|
|
"LGJE1EE05RM200433",
|
|
"LGJE1EE05SM311909",
|
|
"LGJE5EE02SM346914",
|
|
"LGJE1EE08SM306753",
|
|
"LGJE1EE02SM312001",
|
|
"LFPH4ACP6R2A02586",
|
|
"LGJE1EE00PM048445",
|
|
"LGJE1EE02SM311902",
|
|
"LGJE1EE03SM312573",
|
|
"LGJE1EE00SM306813",
|
|
"LFB1E6674N1Y00577",
|
|
"LGJE1EE00SM306875",
|
|
"LGJE1EE04SM306863",
|
|
"LFB1E6079P1Y00389",
|
|
"LGJE1EE04SM311562",
|
|
"LGJE1EE01SM312006",
|
|
"LGJE1EE08SM312486",
|
|
"LFB1E6676P1Y00941",
|
|
"LFPH4ACP1M1B00116",
|
|
"LGJE1EE02SM312564",
|
|
"LFPH4BCPXS2L00051",
|
|
"LGJE1EE06SM306864",
|
|
]
|
|
for vin in vin_list:
|
|
try:
|
|
for _ in range(15):
|
|
dealer = Dealer.objects.get(user__email="marwan@tenhal.sa")
|
|
vin = f"{vin[:-4]}{random.randint(0, 9)}{random.randint(0, 9)}{random.randint(0, 9)}{random.randint(0, 9)}"
|
|
result = decodevin(vin)
|
|
make = CarMake.objects.get(name=result["maker"])
|
|
model = make.carmodel_set.filter(name__contains=result["model"]).first()
|
|
if not model or model == "":
|
|
model = random.choice(make.carmodel_set.all())
|
|
year = result["modelYear"]
|
|
serie = random.choice(model.carserie_set.all())
|
|
trim = random.choice(serie.cartrim_set.all())
|
|
|
|
car = Car.objects.create(
|
|
vin=vin,
|
|
id_car_make=make,
|
|
id_car_model=model,
|
|
id_car_serie=serie,
|
|
id_car_trim=trim,
|
|
year=(int(year) or 2025),
|
|
receiving_date=datetime.datetime.now(),
|
|
dealer=dealer,
|
|
)
|
|
car_finance = CarFinance.objects.create(
|
|
car=car, cost_price=10000, selling_price=20000
|
|
)
|
|
car_color = CarColors.objects.create(
|
|
car=car,
|
|
interior=random.choice(InteriorColors.objects.all()),
|
|
exterior=random.choice(ExteriorColors.objects.all()),
|
|
)
|
|
print(make, model, serie, trim)
|
|
except Exception as e:
|
|
print(e)
|
|
|
|
if __name__ == "__main__":
|
|
run() |