Exemplo n.º 1
0
 def create_board(self):
     print('Start create board')
     sql = "SELECT board_name from board_template order by RAND() limit 5"
     results = fetch_all_sql(self.conn, sql)
     for board_echo in results:
         board_name = board_echo['board_name']
         print('Boardname', board_name)
         sql = "SELECT home_page from account where id=%s"
         result = fetch_one_sql(self.conn, sql, self.account_id)
         if result:
             home_page = result['home_page'] + 'boards/'
         try:
             self.driver.get(home_page)
             time.sleep(5)
             self.driver.find_element_by_xpath(
                 '//button[@aria-label="Profile actions overflow"]').click()
             time.sleep(2)
             self.driver.find_element_by_xpath(
                 '//div[@class="fixedHeader"]//div[text()="Create board"]').click()
             time.sleep(5)
             self.driver.find_element_by_xpath(
                 '//form//input[@id="boardEditName"]').send_keys(board_name)
             time.sleep(1)
             self.driver.find_element_by_xpath(
                 '//form//button[@type="submit"]').click()
             time.sleep(2)
             sql = "UPDATE account set created_boards=created_boards+1 where id=%s"
             commit_sql(self.conn, sql, self.account_id)
             time.sleep(3)
         except:
             pass
     self.driver.get('https://www.pinterest.com')
     time.sleep(5)
Exemplo n.º 2
0
 def follow(self):
     print('Turn on the follow function, count:', self.follow_num)
     sql = 'SELECT * from follow_url where for_config=10 limit %s'
     results = fetch_all_sql(self.conn2, sql, self.follow_num)
     if results:
         for res in results:
             web_url_id = res['Id']
             web_url = res['web_url']
             home_url = res['home_url']
             sql = 'SELECT * from follow_history where user_id=%s and follow_account=%s'
             judge_exist = fetch_one_sql(self.conn2, sql,
                                         (web_url_id, self.email))
             if judge_exist:
                 print('Already followed!')
             else:
                 try:
                     self.driver.get(home_url)
                 except:
                     pass
                 time.sleep(5)
                 try:
                     follow_state = self.driver.find_element_by_xpath(
                         '//div[@class="fixedHeader"]//div[3]//div[2]/button/div'
                     ).text
                     if follow_state == 'Follow':
                         self.driver.find_element_by_xpath(
                             '//div[@class="fixedHeader"]//div[3]//div[2]/button'
                         ).click()
                         time.sleep(1)
                 except:
                     pass
                 try:
                     follow_state = self.driver.find_element_by_xpath(
                         '//div[@class="CreatorFollowButton step0"]//div[2]/div'
                     ).text
                     if follow_state == 'Follow':
                         self.driver.find_element_by_xpath(
                             '//div[@class="CreatorFollowButton step0"]/div/div/div/div'
                         ).click()
                         time.sleep(1)
                 except:
                     pass
                 sql = 'INSERT INTO follow_history (user_id, user, user_homepage, follow_account) values (%s, %s, %s, %s)'
                 commit_sql(self.conn2, sql,
                            (web_url_id, web_url, home_url, self.email))
             write_txt_time()
Exemplo n.º 3
0
 def click_specific_pin(self):
     print('Start searching for our company images')
     sql = "SELECT count(-1) as allnum from pin_history where account_id=%s and add_time>=%s"
     pin_count = fetch_one_sql(
         self.conn, sql, (self.account_id, self.current_time))['allnum']
     if pin_count < int(self.pin_self_count):
         sql = "SELECT web_url from follow_url"
         results = fetch_all_sql(self.conn2, sql)
         http_in_sql_list = []
         for res in results:
             http_in_sql = res['web_url']
             http_in_sql_list.append(http_in_sql)
         sql = "SELECT * from search_words where us=1 order by RAND() limit %s"
         key_wrods = fetch_all_sql(self.conn2, sql, self.search_words_count)
         if key_wrods:
             for key_wrod in key_wrods:
                 search_key_words = key_wrod['word']
                 board_name = key_wrod['boards']
                 # belong = result['us']
                 try:
                     self.driver.find_element_by_name('q').click()
                     time.sleep(1)
                     self.driver.find_element_by_name('q').clear()
                     time.sleep(1)
                     self.driver.find_element_by_name('q').send_keys(
                         search_key_words)
                     time.sleep(1)
                     win32api.keybd_event(13, 0, 0, 0)
                     win32api.keybd_event(13, 0, win32con.KEYEVENTF_KEYUP,
                                          0)
                 except:
                     pass
                 try:
                     self.driver.find_element_by_name(
                         "searchBoxInput").click()
                     time.sleep(1)
                     self.driver.find_element_by_name(
                         "searchBoxInput").clear()
                     time.sleep(1)
                     self.driver.find_element_by_name(
                         "searchBoxInput").send_keys(search_key_words)
                     time.sleep(1)
                     win32api.keybd_event(13, 0, 0, 0)
                     win32api.keybd_event(13, 0, win32con.KEYEVENTF_KEYUP,
                                          0)
                 except:
                     pass
                 time.sleep(8)
                 for _ in range(self.scroll_num):
                     try:
                         web_pin_arr = self.driver.find_elements_by_xpath(
                             "//div[@data-grid-item='true']")
                         # print(len(web_pin_arr))
                     except:
                         time.sleep(3)
                         web_pin_arr = self.driver.find_elements_by_xpath(
                             "//div[@data-grid-item='true']")
                     for web_pin_one in web_pin_arr:
                         try:
                             ActionChains(self.driver).move_to_element(
                                 web_pin_one).perform()
                             time.sleep(3)
                             write_txt_time()
                         except:
                             pass
                         try:
                             web_pin = self.driver.find_element_by_xpath(
                                 '//a[@rel="nofollow"]//div[2]/div')
                             time.sleep(2)
                             web_pin_url = web_pin.text
                             # print(web_pin_url)
                             if web_pin_url in http_in_sql_list:
                                 time.sleep(1)
                                 specific_pin_url = web_pin_one.find_element_by_xpath(
                                     './/div[@class="pinWrapper"]/div/a'
                                 ).get_attribute('href')
                                 time.sleep(1)
                                 specific_pin_pic_url = web_pin_one.find_element_by_xpath(
                                     './/div[@class="pinWrapper"]//img'
                                 ).get_attribute('src')
                                 self.save_pic(
                                     board_name=board_name,
                                     belong=1,
                                     specific_pin_url=specific_pin_url,
                                     specific_pin_pic_url=
                                     specific_pin_pic_url)
                                 sql = "SELECT count(-1) as allnum from pin_history where account_id=%s and add_time>=%s"
                                 pin_count = fetch_one_sql(
                                     self.conn, sql,
                                     (self.account_id,
                                      self.current_time))['allnum']
                         except Exception as e:
                             # self.logs.error('This is an error message!', exc_info=True)
                             pass
                         if pin_count >= int(self.pin_self_count):
                             break
                     if pin_count >= int(self.pin_self_count):
                         break
                     else:
                         win32api.keybd_event(35, 0, 0, 0)
                         win32api.keybd_event(35, 0,
                                              win32con.KEYEVENTF_KEYUP, 0)
                         time.sleep(5)
                 if pin_count >= int(self.pin_self_count):
                     break
     else:
         print('Saved enough!')
Exemplo n.º 4
0
 def upload_pic(self):
     upload_flag = 1
     sql = 'SELECT * from domain where account_id=%s'
     id_result = fetch_one_sql(self.conn1, sql, self.account_id)
     if id_result:
         print('Today has been spread!')
     else:
         sql = 'SELECT * from domain where state=0 order by RAND() limit 1'
         result = fetch_one_sql(self.conn1, sql)
         if result:
             domain = result['domain']
             complete_domain = 'https://www.' + domain
             upload_pic_num = random.randint(self.upload_pic_min_num,
                                             self.upload_pic_max_num)
             print('Upload number of picture processing:', upload_pic_num)
             sql = 'SELECT * from pin_upload where saved=0 and belong_web=%s order by RAND() limit %s'
             results = fetch_all_sql(self.conn1, sql,
                                     (complete_domain, upload_pic_num))
             if results:
                 sql = "UPDATE domain set state=1, account_id=%s where domain=%s"
                 commit_sql(self.conn1, sql, (self.account_id, domain))
                 for rows in results:
                     upload_pic_path = rows['savelink']
                     upload_pic_path = upload_pic_path.replace(
                         'http://guanli.lianstone.net',
                         'http://guanli2.lianstone.net')
                     upload_pic_board = rows['saveboard']
                     upload_pic_id = rows['Id']
                     self.driver.get(upload_pic_path)
                     time.sleep(5)
                     try:
                         self.driver.find_element_by_xpath(
                             "//input[@id='pickerSearchField']").send_keys(
                                 upload_pic_board)
                         time.sleep(2)
                     except Exception as e:
                         print('Image save failed, Element not found')
                         upload_flag = 0
                     if upload_flag == 1:
                         try:
                             win32api.keybd_event(13, 0, 0, 0)
                             win32api.keybd_event(13, 0,
                                                  win32con.KEYEVENTF_KEYUP,
                                                  0)
                             time.sleep(5)
                         except Exception as e:
                             pass
                         if self.driver.page_source.find(
                                 'Sorry! We blocked this link because it may lead to spam.'
                         ) > -1:
                             print('Domain name banned!')
                             sql = "UPDATE domain set state=4 where domain=%s"
                             commit_sql(self.conn1, sql, complete_domain)
                             upload_flag = 0
                             break
                         try:
                             self.driver.find_element_by_xpath(
                                 "//div[@class='mainContainer']//div[1]/div/button"
                             ).click()
                             time.sleep(5)
                             sql = "UPDATE pin_upload set saved=1 where id=%s"
                             commit_sql(self.conn1, sql, upload_pic_id)
                             write_txt_time()
                         except Exception as e:
                             pass
                     time.sleep(3)
             else:
                 sql = "UPDATE domain set state=9 where domain=%s"
                 commit_sql(self.conn1, sql, complete_domain)
         else:
             print('No data in domain!')
     time.sleep(2)