|
1 | 1 | from project_files import Cars
|
2 |
| -from project_files import Operations |
3 | 2 | from project_files import config
|
4 |
| -from project_files import connection, create_database, create_table |
5 |
| -from project_files.query import DB_NAME, TABLES |
| 3 | +from project_files import connection, create_database, create_table, data_send, sendSMS |
| 4 | +from project_files.query import DB_NAME, TABLES, add_new_row, add_specific_row |
| 5 | +import os |
6 | 6 |
|
| 7 | +car_type = input('Enter car type, for example: Auta małe \n') |
| 8 | +brand = input('Enter brand \n') |
| 9 | +min_price = input('Enter minimal price \n') |
| 10 | +max_price = input('Enter maximum price \n') |
| 11 | +min_year = input('Enter minimum year \n') |
| 12 | +max_year = input('Enter maximum year \n') |
| 13 | +min_mileage = input('Enter minimum mileage \n') |
| 14 | +max_mileage = input('Enter maximum mileage \n') |
| 15 | +max_page = input('how many pages should be searched? \n') |
| 16 | + |
| 17 | +create_database(DB_NAME=DB_NAME) |
7 | 18 | connect = connection(config=config)
|
8 | 19 | cursor = connect.cursor()
|
9 |
| -create_database(cursor=cursor, DB_NAME=DB_NAME) |
10 | 20 | create_table(cursor=cursor, TABLES=TABLES)
|
| 21 | + |
| 22 | +try: |
| 23 | + with Cars() as bot: |
| 24 | + correct_list = [] |
| 25 | + bot.land_first_page() |
| 26 | + bot.accept_button() |
| 27 | + bot.car_type(car=car_type) |
| 28 | + bot.car_brand(brand=brand) |
| 29 | + bot.price(min_price=min_price, max_price=max_price) |
| 30 | + bot.years(min_year=min_year, max_year=max_year) |
| 31 | + bot.mileage(min_mileage=min_mileage, max_mileage=max_mileage) |
| 32 | + bot.search_all() |
| 33 | + for page in range(1,max_page): |
| 34 | + data = bot.info() |
| 35 | + for row in data: |
| 36 | + correct_list.append( row) |
| 37 | + if int(page) > 1: |
| 38 | + bot.page_change(page=page) |
| 39 | +except: |
| 40 | + print('There is a problem with a main bot') |
| 41 | + |
| 42 | + |
| 43 | +for row in correct_list: |
| 44 | + data_send(connect=connect, cursor=cursor, sql=add_new_row, data=row) |
| 45 | + |
| 46 | +try: |
| 47 | + try: |
| 48 | + cursor.execute("SELECT title, city, price, year, mileage_km, engine_cm3, petrol from cars.car order by year asc limit 1") |
| 49 | + record = cursor.fetchall() |
| 50 | + first_ask = '' |
| 51 | + for row in record: |
| 52 | + first_ask = row |
| 53 | + except: |
| 54 | + print('Error with first table') |
| 55 | + try: |
| 56 | + cursor.execute("SELECT title, city, price, year, mileage_km, engine_cm3, petrol from cars.selected_car order by year asc limit 1") |
| 57 | + second_record = cursor.fetchall() |
| 58 | + second_ask = '' |
| 59 | + for row in second_record: |
| 60 | + if row != '' or row != None: |
| 61 | + second_ask = row |
| 62 | + except: |
| 63 | + print('error with second table') |
| 64 | + try: |
| 65 | + if first_ask != second_ask: |
| 66 | + data_send(connect=connect, cursor=cursor, sql=add_specific_row, data=first_ask) |
| 67 | + except: |
| 68 | + print('Error with adding row to: cars.selected_car') |
| 69 | + try: |
| 70 | + cursor.execute("SELECT ID, title, city, price, year, mileage_km, engine_cm3, petrol from cars.selected_car order by year asc limit 1") |
| 71 | + second_record = cursor.fetchall() |
| 72 | + for data in second_record: |
| 73 | + message = 'title: {} \ncity: {} \nprice: {} \nyear: {} \nmileage: {} km2 \nengine: {} cm3 \npetrol: {}'.format(data[1],data[2],data[3],data[4],data[5],data[6],data[7]) |
| 74 | + print(message) |
| 75 | + # sendSMS(apikey='****API_KEY****', numbers='', author='', message=message) |
| 76 | + except: |
| 77 | + 'Error with sms api' |
| 78 | +except: |
| 79 | + print('Error with second part') |
| 80 | + |
| 81 | +delete_database = input('Do you want delete database? Write Yes or Not \n') |
| 82 | +if delete_database == 'yes' or delete_database == 'Yes' or delete_database == 'YES': |
| 83 | + try: |
| 84 | + cursor.execute('DROP DATABASE cars') |
| 85 | + print('DATABASE WAS DELETED') |
| 86 | + except: |
| 87 | + print('Error with delete database') |
| 88 | + |
11 | 89 | cursor.close()
|
12 | 90 | connect.close()
|
13 |
| -# cursor.execute("SHOW TABLES") |
14 |
| - |
15 |
| -# for x in cursor: |
16 |
| -# print(x) |
17 |
| - |
18 |
| -# try: |
19 |
| -# with Cars() as bot: |
20 |
| -# bot.land_first_page() |
21 |
| -# bot.accept_button() |
22 |
| -# bot.car_type(car='Auta małe') |
23 |
| -# bot.car_brand(brand='Renault') |
24 |
| -# bot.price(min_price='0', max_price='15000') |
25 |
| -# bot.years(min_year='2000', max_year='2010') |
26 |
| -# bot.mileage(min_mileage='0', max_mileage='2000000') |
27 |
| -# bot.search_all() |
28 |
| -# for page in range(1,5): |
29 |
| -# data = bot.info() |
30 |
| - |
31 |
| -# for row in data: |
32 |
| -# print(row) |
33 |
| - |
34 |
| -# if int(page) > 1: |
35 |
| -# bot.page_change(page=page) |
36 |
| -# except: |
37 |
| -# 'There is a problem with a main bot' |
| 91 | + |
| 92 | + |
0 commit comments