-
Notifications
You must be signed in to change notification settings - Fork 0
/
general_car_functions.py
140 lines (118 loc) · 3.55 KB
/
general_car_functions.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
from datetime import datetime
def get_car_age(car_year):
""" Get car age given its year and actual date """
this_year = datetime.now().year
car_age = this_year - int(car_year)
return car_age
def get_car_power(car_model):
""" Get car power from model description """
power_list = ['1.0', '1.3', '1.4', '1.5', '1.6', '1.7', '1.8',
'2.0', '2.2', '2.3', '2.4', '2.5', '2.7', '2.8',
'3.0', '3.2', '3.4', '4.0']
car_power = '1.0'
found = False
for power_element in power_list:
if power_element in car_model:
found = True
car_power = power_element
#if found == False:
# print 'Car Power Not Found', car_model
return car_power
def get_car_transmission(car_model):
""" Get car transmission from model description """
transm_list = ['Aut', 'AUT', 'Mec', 'MEC']
transm_final = 'MEC'
found = False
for transm_element in transm_list:
if transm_element in car_model:
found = True
transm_final = transm_element[:3].upper()
#if found == False:
# print 'Transmission Type Not Found', car_model
return transm_final
def get_car_model_code_fixed(car_model_code):
""" Fix car codes to olx standard """
car_fix_dict = {
'ka+': 'ka-mais',
'renegade1-8': 'renegade',
'ka-mais': 'ka+',
}
if car_model_code in car_fix_dict.keys():
car_model_code = car_fix_dict[car_model_code]
return car_model_code
def get_brand_from_model(car_model):
""" Model to Brand lookup """
model_to_brand = {
'cobalt': 'GM-CHEVROLET',
'cruze': 'GM-CHEVROLET',
'onix': 'GM-CHEVROLET',
'prisma': 'GM-CHEVROLET',
's10': 'GM-CHEVROLET',
'spin': 'GM-CHEVROLET',
'tracker': 'GM-CHEVROLET',
'argo': 'FIAT',
'cronos': 'FIAT',
'mobi': 'FIAT',
'siena': 'FIAT',
'strada': 'FIAT',
'toro': 'FIAT',
'uno': 'FIAT',
'ecosport': 'FORD',
'fiesta': 'FORD',
'focus': 'FORD',
'fusion': 'FORD',
'ka': 'FORD',
'ka+': 'FORD',
'ka-mais': 'FORD',
'ranger': 'FORD',
'city': 'HONDA',
'civic': 'HONDA',
'fit': 'HONDA',
'hr-v': 'HONDA',
'wr-v': 'HONDA',
'creta': 'HYUNDAI',
'hb20': 'HYUNDAI',
'hb20s': 'HYUNDAI',
'compass': 'JEEP',
'renegade': 'JEEP',
'renegade1-8': 'JEEP',
'kicks': 'NISSAN',
'sentra': 'NISSAN',
'versa': 'NISSAN',
'captur': 'RENAULT',
'duster': 'RENAULT',
'kwid': 'RENAULT',
'logan': 'RENAULT',
'sandero': 'RENAULT',
'corolla': 'TOYOTA',
'etios': 'TOYOTA',
'hilux': 'TOYOTA',
'yaris': 'TOYOTA',
'amarok': 'VW-VOLKSWAGEN',
'crossfox': 'VW-VOLKSWAGEN',
'fox': 'VW-VOLKSWAGEN',
'gol': 'VW-VOLKSWAGEN',
'golf': 'VW-VOLKSWAGEN',
'jetta': 'VW-VOLKSWAGEN',
'polo': 'VW-VOLKSWAGEN',
'saveiro': 'VW-VOLKSWAGEN',
'up': 'VW-VOLKSWAGEN',
'virtus': 'VW-VOLKSWAGEN',
'voyage': 'VW-VOLKSWAGEN'
}
return model_to_brand[car_model]
def get_brand_from_id(code):
""" ID to Brand lookup """
id_to_brand = {
'21': 'FIAT',
'22': 'FORD',
'23': 'GM-CHEVROLET',
'25': 'HONDA',
'26': 'HYUNDAI',
'29': 'JEEP',
'43': 'NISSAN',
'48': 'RENAULT',
'56': 'TOYOTA',
'59': 'VW-VOLKSWAGEN',
}
return id_to_brand[code]