Skip to content

Instantly share code, notes, and snippets.

@samchaaa
Created June 14, 2020 05:01
Show Gist options
  • Save samchaaa/71a6d4e64c1c827680906ccae5c35380 to your computer and use it in GitHub Desktop.
Save samchaaa/71a6d4e64c1c827680906ccae5c35380 to your computer and use it in GitHub Desktop.
200613 Secret Gist
def lookup(vin):
m = getManu(vin)
try:
y = int(getYear(vin))
except Exception as e:
y = e
# Exceptions here, or Sam may clean up in dict
# if m!= None:
# if 'General Motors' in m:
# print(m)
# m = 'Chevrolet'
try:
# Tries to get manufacturer name by matching the manufacturer name in the dict to the one from the WMI.
# WMI names can be longer (i.e. 'Mitsubishi Mexico') whereas the lookup dict make keys are short 'Mitsubishi' (for all Mitsubishi).
m = [re.match(x, m).group(0) for x in make_dict.keys() if re.match(x, m) != None][0] if len([re.match(x, m).group(0) for x in make_dict.keys() if re.match(x, m) != None]) else None
except Exception as e:
m = e
try:
# Finds the model VIN component (VIN[4:7]) by testing all model VIN components against the complete VIN (is it a substr).
# This eliminates needing to match up the exact indices of the VIN to a specific, hardcoded index of the VIN.
# May be slower, but more complete matches.
# Could potentially mismatch for single digit model codes? (Audi)
result = make_dict[m][y][[x for x in make_dict[[re.match(x, m).group(0) for x in make_dict.keys() if re.match(x, m) != None][0]][int(y)].keys() if x in vin][0]]
except Exception as e:
result = None
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment