Advertisement
Guest User

main.py

a guest
Dec 21st, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 23.26 KB | None | 0 0
  1. from selenium import webdriver
  2. from time import sleep
  3. from selenium.webdriver.chrome.options import Options
  4. import os
  5. import csv
  6. from time import gmtime, strftime
  7. from bs4 import BeautifulSoup
  8. import mysql.connector
  9. from pyvirtualdisplay import Display
  10.  
  11.  
  12. def wait_until_csv_file_exists():
  13.     waits = 0
  14.     while True:
  15.         for root, dirs, files in os.walk(os.getcwd()):
  16.             for file in files:
  17.                 if file.endswith('.csv'):
  18.                     return file
  19.         print("sleeping...." + str(waits))
  20.         sleep(.5)  # make sure file completes downloading
  21.         waits += .5
  22.  
  23.  
  24. def delete_if_csv_exists():
  25.     for root, dirs, files in os.walk(os.getcwd()):
  26.         for file in files:
  27.             if file.endswith('.csv'):
  28.                 os.remove(file)
  29.  
  30.  
  31. def enable_downloading_in_google_headless(driver):
  32.     """
  33.    there is currently a "feature" in chrome where
  34.    headless does not allow file download: https://bugs.chromium.org/p/chromium/issues/detail?id=696481
  35.    This method is a hacky work-around until the official chromedriver support for this.
  36.    Requires chrome version 62.0.3196.0 or above.
  37.    """
  38.     download_dir = os.getcwd()
  39.     # add missing support for chrome "send_command"  to selenium webdriver
  40.     driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')
  41.  
  42.     params = {'cmd': 'Page.setDownloadBehavior', 'params': {'behavior': 'allow', 'downloadPath': download_dir}}
  43.     command_result = driver.execute("send_command", params)
  44.     print("response from browser:")
  45.  
  46.     for key in command_result:
  47.         print("result:" + key + ":" + str(command_result[key]))
  48.  
  49.  
  50. def make_a_query(lot_number, actual_date, description, sales_date, year, high_bid, odometer, fuel_type, color,
  51.                  transmission, engine, drive, vin, lot_cond, has_keys, damage_description, secondary_damage,
  52.                  location_city, make, model_detail, imgs, body):
  53.     # imgs : str - img do obrazkow oddzielone przecinkami
  54.     # current date yyyy-mm-dd hh:mm:ss
  55.     # dla wpcm_expration yyyy-mm-dd
  56.  
  57.     return str("INSERT INTO  `admin_strona`.`auta_posts` (\n" +
  58.                "`ID` ,\n" +
  59.                "`post_author` ,\n" +
  60.                "`post_date` ,\n" +
  61.                "`post_date_gmt` ,\n" +
  62.                "`post_content` ,\n" +
  63.                "`post_title` ,\n" +
  64.                "`post_excerpt` ,\n" +
  65.                "`post_status` ,\n" +
  66.                "`comment_status` ,\n" +
  67.                "`ping_status` ,\n" +
  68.                "`post_password` ,\n" +
  69.                "`post_name` ,\n" +
  70.                "`to_ping` ,\n" +
  71.                "`pinged` ,\n" +
  72.                "`post_modified` ,\n" +
  73.                "`post_modified_gmt` ,\n" +
  74.                "`post_content_filtered` ,\n" +
  75.                "`post_parent` ,\n" +
  76.                "`guid` ,\n" +
  77.                "`menu_order` ,\n" +
  78.                "`post_type` ,\n" +
  79.                "`post_mime_type` ,\n" +
  80.                "`comment_count`\n" +
  81.                ")\n" +
  82.                "VALUES (\n" +
  83.                "\'{}\',  '1',  \'{}\',  \'{}\',  '{}',  \'{} {}\',  '',  'publish',  'closed',  'closed',  '',  \'{}\',  '', '',  \'{}\',  \'{}\',  '',  '0',  '',  '0',  'wpcm_vehicle',  '',  '0'\n".format(
  84.                    lot_number, actual_date, actual_date, description, make, model_detail, lot_number, actual_date,
  85.                    actual_date) +
  86.                ");\n" +
  87.                "\n" +
  88.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','wpcm_expiration',\'{}\');\n".format(
  89.                    lot_number, sales_date) +
  90.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','wpcm_sold',0);\n".format(
  91.                    lot_number) +
  92.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','wpcm_featured',0);\n".format(
  93.                    lot_number) +
  94.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','wpcm_condition','new');\n".format(
  95.                    lot_number) +
  96.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','wpcm_make',0);\n".format(
  97.                    lot_number) +
  98.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','wpcm_model',0);\n".format(
  99.                    lot_number) +
  100.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','wpcm_frdate',\'{}\');\n".format(
  101.                    lot_number, year) +
  102.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','wpcm_price',\'{}\');\n".format(
  103.                    lot_number, high_bid) +
  104.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','wpcm_mileage',\'{}\');\n".format(
  105.                    lot_number, odometer) +
  106.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','wpcm_fuel_type',\'{}\');\n".format(
  107.                    lot_number, fuel_type) +
  108.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','wpcm_color',\'{}\');\n".format(
  109.                    lot_number, color) +
  110.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','wpcm_transmission',\'{}\');\n".format(
  111.                    lot_number, transmission) +
  112.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','wpcm_doors',0);\n".format(
  113.                    lot_number) +
  114.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','wpcm_engine',\'{}\');\n".format(
  115.                    lot_number, engine) +
  116.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','wpcm_power_kw',0);\n".format(
  117.                    lot_number) +
  118.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','wpcm_pwer_hp',0);\n".format(
  119.                    lot_number) +
  120.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','wpcm_test',0);\n".format(
  121.                    lot_number) +
  122.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','zawieszenie',\'{}\');\n".format(
  123.                    lot_number, drive) +
  124.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','vin',\'{}\');\n".format(
  125.                    lot_number, vin) +
  126.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','kategoria_abi',\'{}\');\n".format(
  127.                    lot_number, lot_cond) +
  128.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','dowod_rejestracyjny_v5','Zawieszenie4');\n".format(
  129.                    lot_number) +
  130.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','kluczyki',\'{}\');\n".format(
  131.                    lot_number, has_keys) +
  132.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','weryfikacja','-');\n".format(
  133.                    lot_number) +
  134.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','uszkodzenia',\'{} {}\');\n".format(
  135.                    lot_number, damage_description, secondary_damage) +
  136.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','data_zakonczenia','test');\n".format(
  137.                    lot_number) +
  138.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','miejscowosc',\'{}\');\n".format(
  139.                    lot_number, location_city) +
  140.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','id_pojazdu',\'{}\');\n".format(
  141.                    lot_number, lot_number) +
  142.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','marka',\'{}\');\n".format(
  143.                    lot_number, make) +
  144.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','model',\'{}\');\n".format(
  145.                    lot_number, model_detail) +
  146.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','wpcm_body_style',\'{}\');\n".format(
  147.                    lot_number, body) +
  148.                "INSERT INTO `admin_strona`.`auta_postmeta`(`meta_id`, `post_id`, `meta_key`, `meta_value`) VALUES (NULL, \'{}\','_car_gallery',\'{}\');\n".format(
  149.                    lot_number, imgs)
  150.                )  # """)
  151.  
  152.  
  153. def get_sales_date(date):
  154.     # input 10/12/2018
  155.     # o 2018-12-10
  156.     # l = date.split('/')
  157.     # print('XD')
  158.     print('DATA', date)
  159.     l = date
  160.     return l[0] + l[1] + "." + l[3] + l[4] + "." + l[6] + l[7] + l[8] + l[9] + " " + l[11] + l[12] + ":" + l[14] + l[15]
  161.  
  162.  
  163. def get_actual_date():
  164.     # howtime = strftime("%Y-%m-%d %H:%M:%S", gmtime())
  165.     showtime = strftime("%Y-%m-%d %H:%M", gmtime())
  166.     return showtime
  167.     # 2015-10-15 07:49:18
  168.     # yyyy-mm-dd hh:mm:ss
  169.  
  170.  
  171. def get_vin(soup):
  172.     try:
  173.         a = soup.select('span[data-uname="lotdetailVin"]')[0].text
  174.     except Exception as e:
  175.         a = soup.select('span[data-uname="lotdetailVinvalue"]')[0].text
  176.     return a
  177.    
  178.  
  179. def get_current_bid(soup):
  180.     try:
  181.         a = soup.select('label[for="Current Bid"]')[0].find_next_sibling('span').text
  182.     except Exception as e:
  183.         try:
  184.             a = soup.select('label[for="Starting Bid"]')[0].find_next_sibling('span').text
  185.         except Exception as e:
  186.             a = "0"
  187.     return a
  188.  
  189. def get_odometer(soup):
  190.     try:
  191.         a = soup.select('span[data-uname="lotdetailOdometervalue"]')[0].text
  192.     except Exception as e:
  193.             a = soup.select('label[for="mileage"]')[0].find_next_sibling('span').text
  194.  
  195.     return a
  196.  
  197.  
  198. def get_description(soup, ifd):
  199.     if (not ifd): return '-'
  200.  
  201.     try:
  202.         # print("")
  203.         desc = soup.select('div[ng-repeat="lotNotes in additionalLotNotes"]')
  204.         desc = [i.text.rstrip() for i in desc]
  205.         desc = ",\n".join(desc)
  206.         return desc
  207.     except Exception as e:
  208.         return '-'
  209.     return '-'
  210.  
  211.  
  212. def get_imgs(soup):
  213.     imgs = soup.find_all("img", class_="img-responsive")
  214.     # print('zdj',imgs)
  215.     # imgs = [el['src'] for el in imgs if el['src'].endswith(".JPG")]
  216.     imgss = []
  217.     for el in imgs:
  218.         try:
  219.             if el['src'].endswith(".JPG"):
  220.                 imgss.append(el['src'])
  221.         except Exception as e:
  222.             print(el, e)
  223.     # print(imgs)
  224.     imgss = ','.join(imgss)
  225.     return imgss
  226.  
  227.  
  228. def get_price(price):
  229.     return ''.join(filter(lambda x: x.isdigit(), price))
  230.  
  231. try:
  232.     delete_if_csv_exists()
  233.  
  234.     display = Display(visible=0, size=(1366, 768))
  235.     display.start()
  236.  
  237.     outputdir = "log_chrome"
  238.  
  239.     options = webdriver.ChromeOptions()
  240.  
  241.     options.add_argument('--no-sandbox')
  242.     options.add_argument('--window-size=1366x768')
  243.     # options.add_argument('--headless')
  244.     options.add_argument('--disable-gpu')
  245.  
  246.     options.binary_location = '/usr/bin/chromium-browser'
  247.     service_log_path = "chromedriver.log"
  248.     service_args = ['--verbose']
  249.  
  250.     path = os.getcwd() + r"/chromedriver"
  251.     # path = '/usr/bin/chromedriver'
  252.     # path = '/usr/bin/google-chrome'
  253.  
  254.     driver = webdriver.Chrome(executable_path=path,
  255.                             options=options,
  256.                             # service_args=service_args,
  257.                             # service_log_path=service_log_path
  258.                             )
  259.  
  260.     enable_downloading_in_google_headless(driver)
  261.  
  262.     driver.get("https://www.copart.co.uk/login")
  263.  
  264.     try:
  265.         username = driver.find_element_by_id("username")
  266.         password = driver.find_element_by_id("password")
  267.     except Exception as e:
  268.         sleep(5)
  269.         username = driver.find_element_by_id("username")
  270.         password = driver.find_element_by_id("password")
  271.  
  272.     username.send_keys("dabrowskikrzysztof44@gmail.com")
  273.     password.send_keys("AutaLawik2")  # "Laurka12")
  274.  
  275.     sleep(5)
  276.  
  277.     driver.find_element_by_class_name("loginfloatright").click()
  278.  
  279.     sleep(5)
  280.     driver.get("https://www.copart.co.uk/watchList/")
  281.     sleep(5)
  282.     driver.find_element_by_css_selector('a[ng-csv="getCSVResult()"]').click()
  283.  
  284.     filename = wait_until_csv_file_exists()
  285.  
  286.     #   ___ _____   __
  287.     #  / __/ __\ \ / /
  288.     # | (__\__ \\ V /
  289.     #  \___|___/ \_/
  290.  
  291.     queries = []
  292.  
  293.     #with open(filename) as csv_file:
  294.     with open(filename, 'r', encoding="utf-8") as csv_file:
  295.  
  296.         csv_reader = csv.reader(csv_file, delimiter=',')
  297.         line_count = 0
  298.         for row in csv_reader:
  299.             if line_count == 0:
  300.                 print('Column names are {}'.format(", ".join(row)))
  301.                 line_count += 1
  302.                 for i, cell in enumerate(row):
  303.                     print(i, cell)
  304.             # else:
  305.             #   driver.get(row[0])
  306.  
  307.             # print(driver.find_element_by_xpath('//span[@data-uname="DriverValue"]').text)
  308.             # print(driver.find_element_by_name('DriverValue').text)
  309.             # print(soup.find("span", {"data-uname" : "DriverValue"}).text)
  310.             # print(soup.select('span[data-uname="DriverValue"]')[0].text)
  311.             else:
  312.                 description = False
  313.  
  314.                 driver.get(row[0])
  315.                 sleep(2)
  316.                 try:
  317.                     driver.find_element_by_css_selector('a[ng-click="showAllPhotosView($event)"]').click()
  318.                 except Exception as e:
  319.                     pass
  320.                     #print(e)
  321.                     # continue
  322.                 sleep(2)
  323.                 try:
  324.                     driver.find_element_by_css_selector('a[ng-click="showAdditionalLotNotes()"]').click()
  325.                     description = True
  326.                 except Exception as e:
  327.                     #print(e)
  328.                     description = False
  329.                     # continue
  330.                
  331.                 html = driver.page_source
  332.                 soup = BeautifulSoup(html, 'html.parser')
  333.                 # driver.find_element_by_class_name("ctsymbol").text
  334.                 # print(soup.find("label", {"for" : "category"})[0].find_next_sibling('span').text)
  335.                 # print(line_count, soup.select('label[for="category"]')[0].find_next_sibling('span').text)
  336.                 #print(row[1])
  337.                 try:
  338.                     query = make_a_query(lot_number=row[1],  # good
  339.                                         actual_date=get_actual_date(),
  340.                                         description=get_description(soup, description),
  341.                                         sales_date=get_sales_date(row[3]),  # good
  342.                                         year=row[4],  # row[4],#good
  343.                                         high_bid=get_price(get_current_bid(soup)),
  344.                                         # soup.select('label[for="category"]')[0].find_next_sibling('span').text,#soup.find("label", {"for" : "category"}).find_next_siblings('span').text,#soup.select('label[for="category"]')[0].find_next_siblings('span').text,
  345.                                         odometer=get_odometer(soup),
  346.                                         fuel_type=soup.select('span[data-uname="lotdetailFuelvalue"]')[0].text,
  347.                                         color=soup.select('span[data-uname="lotdetailColorvalue"]')[0].text,
  348.                                         transmission=soup.select('label[data-uname=""]')[2].find_next_sibling('span').text,
  349.                                         # wtf
  350.                                         engine=soup.select('span[data-uname="lotdetailEnginetype"]')[0].text,
  351.                                         drive=soup.select('span[data-uname="DriverValue"]')[0].text,
  352.                                         vin=get_vin(soup),
  353.                                         lot_cond=soup.select('label[for="category"]')[0].find_next_sibling('span').text,
  354.                                         # soup.select('span[data-uname=""]')[0].text, # wtf ,
  355.                                         has_keys=soup.select('span[data-uname="lotdetailKeyvalue"]')[0].text,
  356.                                         damage_description=soup.select('span[data-uname="lotdetailPrimarydamagevalue"]')[
  357.                                             0].text,
  358.                                         secondary_damage=soup.select('span[data-uname="lotdetailSecondarydamagevalue"]')[
  359.                                             0].text,
  360.                                         location_city=soup.select('label[for="location"]')[0].find_next_sibling('span').text,
  361.                                         make=row[5],  # good
  362.                                         model_detail=row[6],  # prob. good
  363.                                         imgs=get_imgs(soup),
  364.                                         body=soup.select('label[data-uname="lotdetailBodystyle"]')[0].find_next_sibling(
  365.                                             'span').text)  # get_imgs())
  366.                     queries.append(query)
  367.                 except Exception as e:
  368.                     print("ERROR id:",row[1])
  369.                     print(e)
  370.                     print()
  371.                 line_count += 1
  372.                
  373.  
  374.         # print(f'Processed {line_count} lines.')
  375.     #print(get_actual_date())
  376.  
  377.  
  378.     #print()
  379.  
  380. except Exception as e:
  381.     print(line_count)
  382. finally:
  383.     driver.close()
  384.     display.stop()
  385.  
  386.  
  387. if len(queries)>0:
  388.     DELETE_CARS1 = """
  389.    DELETE FROM auta_postmeta WHERE meta_key='wpcm_expiration' OR meta_key='wpcm_sold'OR meta_key='wpcm_featured'OR meta_key='wpcm_make'OR meta_key='wpcm_model'OR meta_key='wpcm_frdate'OR meta_key='wpcm_price' OR meta_key='wpcm_mileage'OR meta_key='wpcm_fuel_type'OR meta_key='wpcm_color'OR meta_key='wpcm_transmission'OR meta_key='wpcm_doors'OR meta_key='wpcm_engine'OR meta_key='wpcm_power_kw'OR meta_key='wpcm_power_hp'OR meta_key='wpcm_test'OR meta_key='zawieszenie'OR meta_key='vin'OR meta_key='dowod_rejestracyjny_v5'OR meta_key='kluczyki'OR meta_key='weryfikacja'OR meta_key='uszkodzenia'OR meta_key='data_zakonczenia'OR meta_key='miejscowosc'OR meta_key='id_pojazdu'OR meta_key='marka'OR meta_key='model'OR meta_key='_car_gallery'
  390.    OR meta_key='_zawieszenie'OR meta_key='_vin'OR meta_key='_dowod_rejestracyjny_v5'OR meta_key='_kluczyki'OR meta_key='_weryfikacja'OR meta_key='_uszkodzenia'OR meta_key='_data_zakonczenia'OR meta_key='_miejscowosc'OR meta_key='_id_pojazdu'OR meta_key='_marka'OR meta_key='_model'OR meta_key='_car_gallery' OR meta_key='kategoria_abi' OR meta_key='_kategoria_abi' OR meta_key='wpcm_pwer_hp' OR meta_key='_wpcm_pwer_hp' OR meta_key='wpcm_solds' OR meta_key='_wpcm_solds' OR meta_key='wpcm_body_style' OR meta_key='_wpcm_body_style' OR meta_key='wpcm_solds' OR meta_key='_wpcm_solds'
  391.    """
  392.     DELETE_CARS2 = """
  393.    DELETE FROM auta_posts WHERE post_type='wpcm_vehicle';
  394.    """
  395.  
  396.     cnx = mysql.connector.connect(user='admin_user', password='Laurka12',
  397.                                 host='185.243.55.83',
  398.                                 database='admin_strona')
  399.  
  400.     try:
  401.         cursor = cnx.cursor()
  402.         cursor.execute(DELETE_CARS1)
  403.         print(DELETE_CARS1)
  404.     except Exception as e:
  405.         print(e)
  406.     finally:
  407.         cnx.close()
  408.  
  409.     cnx = mysql.connector.connect(user='admin_user', password='Laurka12',
  410.                                 host='185.243.55.83',
  411.                                 database='admin_strona')
  412.  
  413.     try:
  414.         cursor = cnx.cursor()
  415.         cursor.execute(DELETE_CARS2)
  416.         print(DELETE_CARS2)
  417.     except Exception as e:
  418.         print(e)
  419.     finally:
  420.         cnx.close()
  421.  
  422.     for q in queries:
  423.  
  424.         cnx = mysql.connector.connect(user='admin_user', password='Laurka12',
  425.                                     host='185.243.55.83',
  426.                                     database='admin_strona')
  427.  
  428.         try:
  429.             cursor = cnx.cursor()
  430.             cursor.execute(q)
  431.             print(q)
  432.         except Exception as e:
  433.             print(e)
  434.         finally:
  435.             cnx.close()
  436.  
  437.  
  438.  
  439.  
  440. # cnx = mysql.connector.connect(user='p524807_maro', password='Maro6969',
  441. #                               host='time4it.xaa.pl',
  442. #                               database='admin_strona')
  443.  
  444.  
  445. # DELETE_CARS1 = """
  446. # DELETE FROM auta_postmeta WHERE meta_key='wpcm_expiration' OR meta_key='wpcm_sold'OR meta_key='wpcm_featured'OR meta_key='wpcm_make'OR meta_key='wpcm_model'OR meta_key='wpcm_frdate'OR meta_key='wpcm_price' OR meta_key='wpcm_mileage'OR meta_key='wpcm_fuel_type'OR meta_key='wpcm_color'OR meta_key='wpcm_transmission'OR meta_key='wpcm_doors'OR meta_key='wpcm_engine'OR meta_key='wpcm_power_kw'OR meta_key='wpcm_power_hp'OR meta_key='wpcm_test'OR meta_key='zawieszenie'OR meta_key='vin'OR meta_key='dowod_rejestracyjny_v5'OR meta_key='kluczyki'OR meta_key='weryfikacja'OR meta_key='uszkodzenia'OR meta_key='data_zakonczenia'OR meta_key='miejscowosc'OR meta_key='id_pojazdu'OR meta_key='marka'OR meta_key='model'OR meta_key='_car_gallery'
  447. # OR meta_key='_zawieszenie'OR meta_key='_vin'OR meta_key='_dowod_rejestracyjny_v5'OR meta_key='_kluczyki'OR meta_key='_weryfikacja'OR meta_key='_uszkodzenia'OR meta_key='_data_zakonczenia'OR meta_key='_miejscowosc'OR meta_key='_id_pojazdu'OR meta_key='_marka'OR meta_key='_model'OR meta_key='_car_gallery' OR meta_key='kategoria_abi' OR meta_key='_kategoria_abi' OR meta_key='wpcm_pwer_hp' OR meta_key='_wpcm_pwer_hp' OR meta_key='wpcm_solds' OR meta_key='_wpcm_solds' OR meta_key='wpcm_body_style' OR meta_key='_wpcm_body_style' OR meta_key='wpcm_solds' OR meta_key='_wpcm_solds'
  448. # """
  449. # DELETE_CARS2 = """
  450. # DELETE FROM auta_posts WHERE post_type='wpcm_vehicle';
  451. # """
  452.  
  453. # try:
  454. #     cursor = cnx.cursor()
  455. #     cursor.execute(DELETE_CARS1)
  456. #     rs = cursor.fetchall()
  457. #     #cursor.close()
  458. #     #cursor = cnx.cursor()
  459. #     cursor.execute(DELETE_CARS2)
  460. #     rs = cursor.fetchall()
  461. #     #cursor.close()
  462. #     #cursor = cnx.cursor()
  463.  
  464. #     for q in queries:
  465. #         cursor.execute(q)
  466. #         print(q, '\n\n\n')
  467. #         rs = cursor.fetchall()
  468. #         #cursor.close()
  469. #         #cursor = cnx.cursor()
  470. #     #result = cursor.fetchall()
  471. #     #print(result)
  472. # finally:
  473. #     cnx.close()
  474.  
  475.  
  476.  
  477.  
  478.  
  479. # here comes checking if file is downloaded
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement