Created
April 25, 2014 21:40
-
-
Save tonussi/11304305 to your computer and use it in GitHub Desktop.
populador de carros
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding:utf-8 | |
import random | |
import os | |
def main(): | |
population = PopulateDatabase(1899, 2014) | |
population.generate_population() | |
class PopulateDatabase(object): | |
def __init__(self, first, second): | |
self.first = first | |
self.second = second | |
def generate_population(self): | |
brand = ["'Chevrolet'" | |
,"'Ford'" | |
,"'Fiat'" | |
,"'Volkswagen'" | |
] | |
ponto = '.' | |
virgula = ',' | |
aspas = str(u"\u0027") | |
genid = -1 | |
doors = [2, 4] | |
components = ["TRUE", "FALSE"] | |
chev = ["'Avalanche'" | |
,"'Aveo'" | |
,"'Cobalt'" | |
,"'Colorado'" | |
,"'Corvette'" | |
,"'Cruze'" | |
,"'Equinox'" | |
,"'Express 1500'" | |
,"'Express 2500'" | |
,"'Express 3500'" | |
,"'HHR'" | |
,"'Impala'" | |
,"'Malibu'" | |
,"'Silverado 1500'" | |
,"'Silverado 2500 HD'" | |
,"'Silverado 3500 HD'" | |
,"'Suburban 1500'" | |
,"'Suburban 2500'" | |
,"'Tahoe'" | |
,"'TrailBlazer'" | |
,"'Traverse'" | |
,"'Uplander'" | |
,"'Volt'" | |
] | |
ford = ["'E150'" | |
,"'E250'" | |
,"'E350 Super Duty'" | |
,"'Edge'" | |
,"'Escape'" | |
,"'Expedition'" | |
,"'Expedition XL'" | |
,"'Explorer'" | |
,"'F150'" | |
,"'F250 Super Duty'" | |
,"'F250 Super Duty'" | |
,"'F450 Super Duty'" | |
,"'Flex'" | |
,"'Focus'" | |
,"'Fusion'" | |
,"'Mustang'" | |
,"'Ranger Regular Cab'" | |
,"'Ranger Super Cab'" | |
,"'Taurus'" | |
,"'Transit Connect'" | |
] | |
volks = ["'CC'" | |
,"'Eos'" | |
,"'Golf'" | |
,"'GTI'" | |
,"'Jetta'" | |
,"'New Beetle'" | |
,"'Passat'" | |
,"'Routan'" | |
,"'Tiguan'" | |
,"'Touareg'" | |
] | |
fiat = ["'Tempra'" | |
,"'Cinquecento'" | |
,"'Punto'" | |
,"'Fiorino (third generation)'" | |
,"'Barchetta'" | |
,"'Brava'" | |
,"'Bravo'" | |
,"'Cinquecento Sporting'" | |
,"'Coupé 16v Turbo'" | |
,"'Coupé 1.8 16v'" | |
,"'Ulysse'" | |
,"'Palio'" | |
,"'Coupé 2.0 20v'" | |
,"'Marea 1.4 12v'" | |
,"'Marea 155 20v'" | |
,"'Marea Weekend 155 20v'" | |
,"'Multipla'" | |
,"'Seicento'" | |
,"'Punto (second generation)'" | |
] | |
# INSERT INTO vehicle (id,airbag,arcondicionado,brand,direcaohidraulica,doors,freiosabs,model,pricestring,travaseletricas,vidroseletricos,year) VALUES (0,TRUE,TRUE,'Ford',TRUE,2,FALSE,'Silverado 2500 HD','151,53',FALSE,FALSE,1942); | |
xmodel = "" | |
xprice = "" | |
xbrand = "" | |
prefix = "INSERT INTO vehicle (id,airbag,arcondicionado,brand,direcaohidraulica,doors,freiosabs,model,pricestring,travaseletricas,vidroseletricos,year) VALUES (" | |
xid = 0 | |
ls = os.linesep | |
fobj = open("populate.sql", 'w') | |
quant = 99 | |
for i in range(quant): | |
for j in range(quant): | |
xid = xid + 1 | |
xbrand = random.choice(brand) | |
if xbrand == brand[0]: | |
xmodel = random.choice(chev) | |
elif xbrand == brand[1]: | |
xmodel = random.choice(ford) | |
elif xbrand == brand[2]: | |
xmodel = random.choice(fiat) | |
else: | |
xmodel = random.choice(volks) | |
if random.choice(components): | |
xprice = str(random.randint(0, 999)) + ponto + str(random.randint(100, 999)) + virgula + str(random.randint(10, 99)) | |
else: | |
xprice = str(random.randint(0, 999)) + virgula + str(random.randint(10, 99)) | |
line = prefix + str(xid) + virgula + random.choice(components) + virgula + random.choice(components) + virgula + xbrand + virgula + random.choice(components) + virgula + str(random.choice(doors)) + virgula + random.choice(components) + virgula + xmodel + virgula + aspas + xprice + aspas + virgula + random.choice(components) + virgula + random.choice(components) + virgula + str(random.randint(self.first, self.second)) + ");" | |
fobj.writelines(['%s%s' % (line, ls)]) | |
fobj.close() | |
print 'Pronto.' | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment