67 lines
2.6 KiB
Python

from django.core.management.base import BaseCommand
from inventory.services import get_make, get_model, decodevin
from bs4 import BeautifulSoup
import requests
class Command(BaseCommand):
help = "Seed the Customer model with 20 records"
def handle(self, *args, **kwargs):
vin, description = self.generate_vin()
result = decodevin(vin)
self.stdout.write(
self.style.SUCCESS(
"####################################################################################################"
)
)
self.stdout.write(
self.style.SUCCESS(
"####################################################################################################"
)
)
self.stdout.write(self.style.SUCCESS(f"Generated VIN: {vin}"))
self.stdout.write(self.style.SUCCESS(f"Description: {description}"))
# self.stdout.write(
# self.style.SUCCESS(
# "####################################################################################################"
# )
# )
# self.stdout.write(
# self.style.SUCCESS(
# "####################################################################################################"
# )
# )
# self.stdout.write(self.style.SUCCESS(f"Decoded VIN: {result}"))
# make, model, year_model = result.values()
# self.stdout.write(
# self.style.SUCCESS(
# f"VIN: {vin} - Make {make} - Model {model} - Model Year {year_model}"
# )
# )
# make = get_make(make)
# m = get_model(model,make)
# self.stdout.write(self.style.SUCCESS(f"Make: {m.id_car_make} - Model: {m}"))
# self.stdout.write(
# self.style.SUCCESS(
# "####################################################################################################"
# )
# )
# self.stdout.write(
# self.style.SUCCESS(
# "####################################################################################################"
# )
# )
def generate_vin(self):
# url = "https://www.vindecoder.org/vin-decoder"
url = "https://vingenerator.org/"
response = requests.get(url)
soup = BeautifulSoup(response.content, "html.parser")
vin = soup.find("input", {"name": "vin"})["value"]
description = soup.find("div", {"class": "description"}).text
return vin, description