Advertisement
Guest User

Untitled

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