def test_car_wheels(self): man = Car('MAN', 'Truck', 'trailer') koenigsegg = Car('Koenigsegg', 'Agera R') self.assertEqual( [8, 4], [man.num_of_wheels, koenigsegg.num_of_wheels], msg= 'The car shoud have four (4) wheels except its a type of trailer')
def CAR_DISCONNECT(car, parent, curTime): # print("\033[1;31;40m CAR_DISCONNECT : (%d, %s)-(%d, %s) \033[1;37;0m"%(car.Cid, car.state,parent.Cid, parent.state)) if type(car) != type(Car()) or type(parent) != type(Car()): print( " CAR_DISCONNECT ERROR : type ERROR type(car) : %s type(parent) : %s" % (type(car), type(parent))) exit() if car.state != "CM": print(" CAR_DISCONNECT ERROR : (%d,%s) state error %d" % (car.Cid, car.state, parent.Cid)) exit() reCCchildren = [] if len(car.childList) == 0: if car.parentCar != -1: car.changeParent(curTime, -1) car.changeState(curTime, "UN") car.changeLayer(curTime, -1) car.childList = [] print( "\033[1;31;40m CAR_DISCONNECT : (%d, %s) (%d, %s) --- OK\033[1;37;0m" % (car.Cid, car.state, parent.Cid, parent.state)) else: CAR_CLU_CREATE(car, curTime) if car in parent.childList: parent.childList.remove(car) fnam.write("m -t %f -s %d -n m1 -c black -h circle\n" % (curTime, car.Cid))
def __init__(self): threading.Thread.__init__(self) gpio.setmode(gpio.BCM) self.path = Path(16,12) self.path.Setup() self.car = Car() self.car.Setup() self.Stop = False
def test_car_speed2(self): man = Car('Mercedes', 'SLR500') parked_speed = man.speed moving_speed = man.drive(3).speed self.assertListEqual( [parked_speed, moving_speed], [0, 1000], msg= 'The Mercedes should have speed 0 km/h until you put `the pedal to the metal`' )
def test_car_speed(self): man = Car('MAN', 'Truck', 'trailer') parked_speed = man.speed moving_speed = man.drive(7).speed self.assertListEqual( [parked_speed, moving_speed], [0, 77], msg= 'The Trailer should have speed 0 km/h until you put `the pedal to the metal`' )
def test_car_doors(self): opel = Car('Opel', 'Omega 3') porshe = Car('Porshe', '911 Turbo') self.assertListEqual( [ opel.num_of_doors, porshe.num_of_doors, Car('Koenigsegg', 'Agera R').num_of_doors ], [4, 2, 2], msg= 'The car shoud have four (4) doors except its a Porshe or Koenigsegg' )
def test_drive_car(self): man = Car('MAN', 'Truck', 'trailer') moving_man = man.drive(7) moving_man_instance = isinstance(moving_man, Car) moving_man_type = type(moving_man) is Car self.assertListEqual( [True, True, man.speed], [moving_man_instance, moving_man_type, moving_man.speed], msg= 'The car drive function should return the instance of the Car class' )
def EVENT_M(block, GM): global gameMode global fnam gameMode = GM if not (fnam): fnam = open("%s.nam" % GM, "a") curTime = float(block[1]) Cid = int(block[2]) x = float(block[3]) y = float(block[4]) Vx = float(block[5]) Vy = float(block[6]) an = float(block[7]) # new Car come in if not (Cid in CarDict): fnam.write("n -t %f -s %d -x %f -y %f -c black\n" % (curTime, Cid, x, y)) newCar = Car(curTime, Cid, x, y, Vx, Vy, an) CarDict[Cid] = newCar print("STA : %f %d" % (curTime, Cid)) # previous Car come in else: # check time up EVENT_TIMEUP(CarDict[Cid], curTime) CarDict[Cid].changePVA(x, y, Vx, Vy, an)
def test_default_car_model(self): gm = Car() self.assertEqual( 'GM', gm.model, msg= "The car's model should be called `GM` if no model was passed as an argument" )
def test_default_car_name(self): gm = Car() self.assertEqual( 'General', gm.name, msg= 'The car should be called `General` if no name was passed as an argument' )
class Track (threading.Thread): def __init__(self): threading.Thread.__init__(self) gpio.setmode(gpio.BCM) self.path = Path(16,12) self.path.Setup() self.car = Car() self.car.Setup() self.Stop = False def run(self): while(self.Stop == False): self.move = self.path.TellPath() if(self.move=='f'): self.car.Forward(0.01) elif(self.move=='l'): self.car.Left(0.01) elif(self.move=='r'): self.car.Right(0.01) else: self.car.Stop()
def get_cars(url,car_list,id): """function that parses the url using BeautifulSoup4 With the information from the site we construct a list of car objects""" website=urllib.urlopen(url) soup=BeautifulSoup(website.read(),"html5lib") dict={"data-photo":re.compile(r"http")} for car in soup.find_all("article",class_="om-list-item"): name=car.find("a").string link="www.autovit.ro"+car.find("a")["href"] price=car.find("strong",class_="om-price-amount").string year=car.find("strong",text=re.compile(r"[0-9][0-9][0-9][0-9]")).string if(car.find("strong",title=re.compile(r"Putere"))!=None): fuel=car.find("strong",title=re.compile(r"Putere")).string else: fuel="" km=car.find("strong",text=re.compile(r"[0-9]* km")).string city=(car.find("a",attrs=dict)).find_next_sibling().string car_object=Car(id,name,link,price,year,fuel,km,city) if(car_object.good()): car_list.append(car_object) id=id+1 return id
#import Car class from CarClass import Car c1 = Car("Ford","Mondeo") c2 = Car("Fiat","Punto") c1.displayCar() c1.displayCount() c2.displayCar() c2.displayCount()
from CarClass import Car c = Car(2009,"Sedan",5) print("This is a", c.__str__()) c.accelerate() print("The car is going",c.get_speed(), "MPH") c.accelerate() print("The car is going",c.get_speed(), "MPH") c.accelerate() print("The car is going",c.get_speed(), "MPH") c.accelerate() print("The car is going",c.get_speed(), "MPH") c.accelerate() print("The car is going",c.get_speed(), "MPH") print() c.brake() print("The car is currently brarking and is going", c.get_speed(), "MPH") c.brake() print("The car is currently brarking and is going", c.get_speed(), "MPH") c.brake() print("The car is currently brarking and is going", c.get_speed(), "MPH") c.brake() print("The car is currently brarking and is going", c.get_speed(), "MPH") c.brake() print("The car is currently brarking and is going", c.get_speed(), "MPH")
#import Car class from CarClass import Car c1 = Car("Ford", "Mondeo") c2 = Car("Fiat", "Punto") c1.displayCar() c1.displayCount() c2.displayCar() c2.displayCount()
def fetch_cars_from_auction( link): # fetches the car data from a specific auction global qualifying_cars_list time.sleep(2) # Sets a pause p.moveTo(1428, 12) # Moves the mouse to a specific location of the screen p.hotkey("command", "l") # Command for the mac to search something time.sleep(1) p.typewrite(link) p.hotkey("enter") time.sleep(30) p.hotkey("shift", "command", "c") # Opens the inspector of the webpage time.sleep(10) p.hotkey("command", "f") time.sleep(2) p.typewrite("serverSideDataTable_wrapper") time.sleep(5) p.moveTo(979, 620) p.click(button='right') time.sleep(0.5) p.moveTo(1010, 612) time.sleep(1) p.click() print("Clicked") time.sleep(2) p.hotkey("command", "a") time.sleep(2) p.hotkey("command", "c") print("copied") another_new_html = pyperclip.paste( ) # Copy the data from the clipboard into the variable s copied_correctly = False counter = 0 while not copied_correctly: if str(another_new_html[0]) == "<" and str(another_new_html[1]) == "d" and str(another_new_html[2]) == "i" \ and len(another_new_html) > 10000: copied_correctly = True else: if counter > 5: p.moveTo(941, 560) p.click(button='right') time.sleep(0.1) p.moveTo(982, 608) p.click() time.sleep(5) p.hotkey("command", "a") time.sleep(2) p.hotkey("command", "c") another_new_html = pyperclip.paste() counter += 1 else: print( str(another_new_html[0]) + str(another_new_html[1]) + str(another_new_html[2])) time.sleep(5) p.hotkey("command", "a") time.sleep(2) p.hotkey("command", "c") another_new_html = pyperclip.paste() counter += 1 print(another_new_html) new_soup = Soup(another_new_html, "html.parser") new_soup.prettify() # Organizes the containers # Scrape the year car_year_soup = new_soup.findAll("span", {"data-uname": "lotsearchLotcenturyyear"}) indexes = [] # print(car_year_soup) year = "" for i in range(0, len(car_year_soup)): year = "" strng = str(car_year_soup[i]) for x in range(43, 47): year += strng[x] if int(year) >= 2016: indexes.append(i) print("There are " + str(len(indexes)) + " vehicles that are greater than 2016") car_list = [Car() for x in range(len(indexes))] # Creates a list of type Car # Scrape the year i = 0 while i < len(indexes): year = "" strng = str(car_year_soup[indexes[i]]) for x in range(43, 47): year += str(strng[x]) car_list[i].year = int(year) i += 1 previous_list = len(car_list) # Scrape the make car_make_soup = new_soup.findAll("span", {"data-uname": "lotsearchLotmake"}) c = 0 while c < len(indexes): make = "" strng = str(car_make_soup[indexes[c]]) x = 36 while strng[x] != "<": make += strng[x] x += 1 car_list[c].make = make c += 1 # Scrape the model car_model_soup = new_soup.findAll("span", {"data-uname": "lotsearchLotmodel"}) c = 0 while c < len(indexes): model = "" strng = str(car_model_soup[indexes[c]]) x = 37 while strng[x] != "<": model += strng[x] x += 1 car_list[c].model = model c += 1 # Scrape the url of each car url_lot_soup = new_soup.findAll("a", {"data-uname": "lotsearchLotnumber"}) c = 0 while c < len(indexes): url = "https://www.copart.com" strng = str(url_lot_soup[indexes[c]]) x = strng.find("href=") + 7 while strng[x] != '"': url += strng[x] x += 1 car_list[c].url = url c += 1 # Scrape the damage and bid # Finds all <td>'s with a class called 'odd table-row' and assigns them to a list called 'car_damage_soup' car_damage_soup = new_soup.findAll("tr", {"class": "odd table-row"}) # Done for every qualifying car for i in range(0, len(indexes)): strng = str(car_damage_soup[indexes[i]]) # car_list[i].show() damage_bid_soup = Soup(strng, "html.parser") td_soup = damage_bid_soup.findAll("td") damage_raw = str(td_soup[11]) damage_raw = damage_raw.splitlines() damage_raw = str(damage_raw[2]) counter = 6 damage = "" while damage_raw[counter] != "<": damage += damage_raw[counter] counter += 1 car_list[i].damage = damage bid_raw = str(td_soup[13]) bid_raw = bid_raw.splitlines() counter = 0 done = False while not done: if bid_raw[counter].find("Current Bid") != -1: done = True else: counter += 1 bid_raw = bid_raw[counter] counter = 38 bid = "" while bid_raw[counter] != " ": bid += bid_raw[counter] counter += 1 car_list[i].bid = bid for i in range(0, len(car_list)): car_list[i].qualify() car_list[i].qualification = nn.quali(car_list[i].input) check = 0 for i in range(0, len(car_list)): if float(car_list[i].qualification) > 0.6: qualifying_cars_list.append(car_list[i]) print("Added this car to the final list: ") car_list[i].show() download_image(car_list[i]) check += 1 print() else: print() print("This didn't do it") car_list[i].show() if check == 0: print("No cars qualified from this auction")
def test_object_type(self): honda = Car('Honda') self.assertTrue((type(honda) is Car), msg='The object should be a type of `Car`')
def test_car_instance(self): honda = Car('Honda') self.assertIsInstance( honda, Car, msg='The object should be an instance of the `Car` class')
def test_car_type(self): koenigsegg = Car('Koenigsegg', 'Agera R') self.assertTrue( koenigsegg.is_saloon(), msg='The car type should be saloon if it is not a trailer')
def get_cars(url): # parameter 'url' is the link to a specific auction global globavar, qualifying_cars_list newclient = uReq( url, context=context) # Opens the url into the variable newClient print("Successful request") new_html = newclient.read( ) # Assigns the HTML code from 'newclient' to variable 'new_html' print("HTML code read correctly") newclient.close( ) # Closes the connection to the website to save connectivity new_soup = soup( new_html, "html.parser") # Parses the HTML code from 'new_html' into 'new_soup' bFound = True s = url.find("branchCode=") + 11 branch = '' while bFound: strng = url[s] if strng == '&': bFound = False else: branch += url[s] s += 1 # Saves all the '<td' containers that hold a class named 'info year' into the list 'car_year_soup' car_year_soup = new_soup.findAll("td", {"class": "info year"}) # A list called 'indexes' that will hold the index of cars that have a year over 2016 in the list 'car_year_soup' indexes = [] for i in range(0, len(car_year_soup) ): # Will pass through each element of 'car_year_soup' year = "" strng = str( car_year_soup[i] ) # 'strng' is equal to the string value of element i in 'car_year_soup' for x in range( 24, 29 ): # Will pass through the characters 24 to 29 to collect the year year += str(strng[x]) # 'year' is going to be equal to the year if int( year ) >= 2016: # Checks if the year of that car is greater than 2016 indexes.append( i) # If true, then the value of i will be added to indexes. print("There are " + str(len(indexes)) + " qualifying vehicles in this auction") car_list = [Car() for x in range(len(indexes))] # Creates a list of type Car # Scrape the year i = 0 while i < len(indexes): year = "" strng = str(car_year_soup[indexes[i]]) for x in range(24, 29): year += str(strng[x]) car_list[i].year = int(year) i += 1 # Scrape the make car_make_soup = new_soup.findAll("td", {"class": "info make"}) c = 0 while c < len(indexes): make = "" strng = str(car_make_soup[indexes[c]]) x = 24 while strng[x] != "<": make += strng[x] x += 1 make = "".join(make.splitlines()) car_list[c].make = make c += 1 # Scrape the model car_model_soup = new_soup.findAll("td", {"class": "info model"}) c = 0 while c < len(indexes): model = "" strng = str(car_model_soup[indexes[c]]) x = 24 while strng[x] != "<": model += strng[x] x += 1 model = "".join(model.splitlines()) car_list[c].model = model c += 1 # Get the link of the vehicle to later scrape additional information # Saves all the '<td' containers that hold a class named 'info secondCol stockNbr' into the list 'car_link' car_link = new_soup.findAll("td", {"class": "info secondCol stockNbr"}) for i in range( 0, len(indexes) ): # Passes through every qualifying car of the list 'car_link' car_url = "https://www.iaai.com" # 'code' is equal to the string value of the element of the integer of indexes[i] in 'car_link' code = str(car_link[indexes[i]]) for x in range( 92, 133 ): # Passes through the characters 92 to 133 to collect the url car_url += code[ x] # 'car_url' is added the characters from 92 to 133 to have the full url of a car if car_url.find( "/Vehicle?" ) == -1: # Corrects a problem with the some cars having shorter url's car_url = "https://www.iaai.com" for y in range(179, 220): car_url += code[y] car_list[i].url = cleanup( car_url) # Adds the complete url to the car in car_list[i] # Scrape the Bid and Damage for i in range(0, len(indexes)): newer_client = uReq(car_list[i].url, context=context) newer_html = newer_client.read() newer_client.close() souping = soup(newer_html, "html.parser") # Scraping the bid bid_soup = souping.findAll("span", {"class": "high-price"}) bid_soup_str = str(bid_soup) bid = "" c = 27 while c < len(bid_soup_str) and bid_soup_str[c] != "<": bid += bid_soup_str[c] c += 1 if bid == "": car_list[i].bid = '0' elif bid[0] == 'd': car_list[i].bid = '0' else: car_list[i].bid = bid # Scraping the damage damage_soup = souping.findAll( "div", {"class": "col-7 col-value flex-self-end"}) damage_soup_str = str(damage_soup[1]) damage = "" c = 54 while c < len(damage_soup_str) and damage_soup_str[c] != "<": if damage_soup_str[c] == " " and damage_soup_str[c + 1] == "<": c = len(damage_soup_str) else: damage += damage_soup_str[c] c += 1 damage = damage.replace("&", "&") car_list[i].damage = damage stock_soup = souping.findAll("div", {"id": "promptYes"}) # Scraping the image item_id = '' ifound = True stock = str(stock_soup) s = stock.find('Yesclick(') + 10 while ifound: strng = stock[s] if strng == '\'': ifound = False else: item_id += stock[s] s += 1 car_list[i].specific(item_id, branch) for i in range(0, len(car_list)): car_list[i].qualify() car_list[i].qualification = nn.quali(car_list[i].input) check = 0 for i in range(0, len(car_list)): if float(car_list[i].qualification) >= 0.00000000001: qualifying_cars_list.append(car_list[i]) print("Added this car to the list final list:") car_list[i].show() download_image(car_list[i]) check += 1 print() else: print() print("This car didnt make it") car_list[i].show() if check == 0: print("No cars were qualified from this auction")
def test_car_properties(self): toyota = Car('Toyota', 'Corolla') self.assertListEqual( ['Toyota', 'Corolla'], [toyota.name, toyota.model], msg='The car name and model should be a property of the car')