# Conflicts: # car_inventory/settings.py # inventory/models.py # inventory/services.py # inventory/urls.py # inventory/views.py
71 lines
1.7 KiB
Python
71 lines
1.7 KiB
Python
"""
|
|
Services module
|
|
"""
|
|
import requests
|
|
import json
|
|
from .utils import get_jwt_token
|
|
from pyvin import VIN
|
|
from django.conf import settings
|
|
from openai import OpenAI
|
|
from .models import Car
|
|
|
|
|
|
def normalize_name(name):
|
|
return name.replace(' ', '').replace('-', '').lower()
|
|
|
|
|
|
def decode_vin_pyvin(vin):
|
|
vehicle = VIN(vin)
|
|
|
|
data = {
|
|
'Make': vehicle.Make,
|
|
'Model': vehicle.Model,
|
|
'ModelYear': vehicle.ModelYear,
|
|
}
|
|
print(data)
|
|
return data
|
|
|
|
|
|
# vehicle-info
|
|
# c2729afb
|
|
# 6d397471920412d672af1b8a02ca52ea
|
|
|
|
# option-info
|
|
# 367974ed
|
|
# 046b0412c1b4d3f8c39ec6375d6f3030
|
|
def elm(vin):
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
'app-id': 'c2729afb',
|
|
'app-key': '6d397471920412d672af1b8a02ca52ea',
|
|
'client-id': '94142c27-2536-47e9-8e28-9ca7728b9442',
|
|
}
|
|
url = 'https://vehicle-maintenance.api.elm.sa/api/v1/vehicles/vehicle-info?vin='+vin
|
|
|
|
payload = {}
|
|
response = requests.request("GET", url, headers=headers, data=payload)
|
|
car_info = json.loads(response.text)
|
|
print(car_info)
|
|
return car_info
|
|
|
|
|
|
def translate(content, *args, **kwargs):
|
|
client = OpenAI(api_key=settings.OPENAI_API_KEY)
|
|
completion = client.chat.completions.create(
|
|
model="gpt-4",
|
|
messages=[
|
|
{"role": "system", "content": "You are a translation assistant that translates English to Arabic."},
|
|
{"role": "user", "content": content}
|
|
],
|
|
temperature=0.3,
|
|
)
|
|
translation = completion.choices[0].message.content.strip()
|
|
return translation
|
|
|
|
|
|
def calculate_stock_value():
|
|
cars = Car.objects.all()
|
|
total_value = sum(car.selling_price for car in cars)
|
|
return total_value
|
|
|