예제 #1
0
 def get_account(self):
     lock_computer = self.hostname[:6]
     sql = 'SELECT count(1) from account where action_time="%s" and belong="%s"' % (
         self.current_time, lock_computer)
     operated_account = read_one_sql(self.conn, sql)['count(1)']
     sql = 'SELECT count(1) from account where state=1 and action_time<"%s" and belong="%s"' % (
         self.current_time, lock_computer)
     inactive_account = read_one_sql(self.conn, sql)['count(1)']
     print('Operated account: ', operated_account, ';'
           'Inactive account: ', inactive_account)
     sql = 'SELECT * from account where priority>0 and belong="%s"' % lock_computer
     self.priority_result = read_all_sql(self.conn, sql)
     if self.priority_result:
         sql = 'SELECT * from account where priority=1 and action_computer="%s"' % self.hostname
     else:
         sql = "SELECT * from account where action_computer='%s' and action_time<'%s' and state=1 and login_times<4 order by action_time asc limit 1" % (
             self.hostname, self.current_time)
     result = read_one_sql(self.conn, sql)
     if result:
         self.account_id = result["id"]
         self.email = result["email"]
         self.pwd = result["pw"]
         self.vpn = result['vpn']
         self.cookie = result['cookie']
         self.domain = result['domain']
         self.agent = result['agent']
         if not self.agent:
             sql = 'SELECT * from user_agent where terminal="computer" and read_time<4 order by RAND() limit 1'
             agent_in_sql = read_one_sql(self.conn, sql)
             if agent_in_sql:
                 self.agent = agent_in_sql['user_agent']
                 agent_id = agent_in_sql['Id']
                 sql = 'UPDATE account set agent="%s" where id=%s' % (
                     self.agent, self.account_id)
                 write_sql(self.conn, sql)
                 sql = 'UPDATE user_agent set read_time=read_time+1 where id=%s' % agent_id
                 write_sql(self.conn, sql)
         print("Start account processing:", "ID:", self.account_id,
               "Email:", self.email, "password", self.pwd)
     else:
         print('Not Data!')
         time.sleep(3)
예제 #2
0
 def get_account_count(self):
     sql = 'SELECT * from account_count'
     result = read_one_sql(self.conn, sql)
     if result:
         all_count = result['all_count']
         real_time_num = result['real_time_num']
         last_update_time = result['last_update_time']
         if str(last_update_time) < self.current_time:
             sql = '''UPDATE account_count set last_update_time="%s", all_count=
                 (SELECT count(1) from `account` where state=1) where id=1''' % self.current_time
         else:
             sql = 'UPDATE account_count set real_time_num=(SELECT count(1) from `account` where state=1) where id=1'
         write_sql(self.conn, sql)
     if all_count - real_time_num > 10:
         os.system('shutdown -r -t 1800')
         time.sleep(9999)
         print('Too many account errors today to suspend operations!')
예제 #3
0
 def get_config(self):
     print('Run configuration:', self.config_id)
     if self.hostname == 'ChangePassword':
         sql = 'SELECT * from configuration where priority=0'
     else:
         sql = 'SELECT * from configuration where priority=%s' % self.config_id
     result = read_one_sql(self.conn, sql)
     # choice_config_sorted = sorted(results, key=lambda priority: priority['priority'])
     if result:
         self.random_browsing_control = result['random_browsing_control']
         self.browsing_pic_min_num = result['browsing_pic_min_num']
         self.browsing_pic_max_num = result['browsing_pic_max_num']
         self.access_home_page_control = result['access_home_page_control']
         self.save_pic_control = result['save_pic_control']
         self.follow_num = result['follow_num']
         self.pin_self_count = result['pin_self_count']
         self.search_words_count = result['search_words_count']
         self.scroll_num = result['scroll_num']
예제 #4
0
 def create_board(self):
     print('Start create board')
     board_name = 'My favourite'
     sql = "SELECT home_page from account where id=%s" % self.account_id
     result = read_one_sql(self.conn, sql)
     if result:
         home_page = result['home_page'] + 'boards/'
     self.driver.get(home_page)
     time.sleep(3)
     self.driver.find_element_by_xpath(
         '//div[@data-test-id="create_boardCard"]').click()
     time.sleep(2)
     self.driver.find_element_by_xpath(
         '//form//input[@id="boardEditName"]').send_keys(board_name)
     time.sleep(1)
     self.driver.find_element_by_xpath(
         '//div[@class="ReactModalPortal"]//button[@type="submit"]').click(
         )
     time.sleep(2)
예제 #5
0
 def change_hardware(self):
     lock_computer = self.hostname[:6]
     sql = 'SELECT * from account where priority>0 and belong="%s"' % lock_computer
     self.priority_result = read_all_sql(self.conn, sql)
     if self.priority_result:
         sql = 'SELECT * from account where priority=1 and computer_state=0 and belong="%s" order by id limit 1' % lock_computer
     else:
         sql = "SELECT * from account where computer_state=0 and belong='%s' and action_time<'%s' and state=1 and login_times<4 order by action_time asc limit 1" % (
             lock_computer, self.current_time)
     next_account = read_one_sql(self.conn, sql)
     if next_account:
         account_id = next_account["id"]
         email = next_account["email"]
         pwd = next_account["pw"]
         vpn = next_account['vpn']
         cookie = next_account['cookie']
         print("Next account processing:", "ID:", account_id, "Email:",
               email)
         self.mac_adress = next_account['mac_adress']
         sql_hostname = next_account['action_computer']
         if self.mac_adress:
             with open('D:\\work\\pin_login_system\\nameandmac.txt',
                       'w') as fp:
                 fp.write(sql_hostname + ',' + self.mac_adress)
         sql = 'UPDATE account set computer_state=1 where id=%s' % account_id
         write_sql(self.conn, sql)
         time.sleep(6)
         p = subprocess.Popen(
             'D:\\work\\pin_login_system\\editor_mac_computername.bat',
             shell=False)
         p.wait()
         print('Is about to restart')
         time.sleep(10)
         os.system('shutdown -r -t 0')
         time.sleep(100)
     else:
         print('Not useable data!')
         time.sleep(3)
예제 #6
0
def add_product():
    driver = webdriver.Chrome()
    hostname = socket.gethostname()
    conn = pymysql.connect(host='localhost',
                           port=3306,
                           user='******',
                           password='******',
                           db='opencartcpcj',
                           charset='utf8mb4',
                           cursorclass=pymysql.cursors.DictCursor)
    login_storenvy(driver)
    product_flag = 0
    next_step = 0
    while True:
        sql = "SELECT * from %s where state=1 and upload_computer='%s' and read_num<4 order by Id asc limit 1" % (
            DATABASE, hostname)
        result = read_one_sql(conn, sql)
        if result:
            next_step = 1
        else:
            sql = "SELECT * from %s where state=0 order by Id asc limit 1" % DATABASE
            result = read_one_sql(conn, sql)
            if result:
                next_step = 2
            else:
                print("Not data...")
                break
        if next_step == 1 or next_step == 2:
            product_flag = 1
            product_id = result["Id"]
            product_title = result["meta_title"]
            if len(product_title) > 140:
                product_title = product_title[0:150]
            set_new_title = requests.get(
                'http://www.pin.com/wangfei/GetTitleByStr.php?pwd=wangfeicode&str=%s'
                % product_title)
            new_title_res = set_new_title.text
            i = new_title_res.index('<')
            new_title = new_title_res[0:i]
            if len(new_title) > 140:
                new_title = new_title[0:150]
            product_tag = new_title_res[0:i]
            try:
                product_price = result["sprice"]
                new_product_price = '%.2f' % (round(float(product_price)) / 2)
                product_image = result["images"]
                if next_step == 2:
                    sql = 'UPDATE %s set state=1, upload_computer="%s" where Id=%s' % (
                        DATABASE, hostname, product_id)
                    write_sql(conn, sql)
            except:
                product_flag = 0
                sql = 'UPDATE %s set state=4, upload_computer="-" where Id=%s' % (
                    DATABASE, product_id)
                write_sql(conn, sql)
                print('Data error!')
            sql = "UPDATE %s set read_num=read_num+1  where Id=%s " % (
                DATABASE, product_id)
            write_sql(conn, sql)
            if product_flag == 1:
                all_a_link_flag = driver.find_elements_by_xpath(
                    "//ul[@class='main-nav-dropdown']//a")
                for a_link in all_a_link_flag:
                    if a_link.get_attribute("text") == "Products":
                        web_http = a_link.get_attribute("href")
                driver.get(web_http)
                time.sleep(2)
                driver.find_element_by_xpath(
                    '//a[@id="btn_add_product"]').click()
                time.sleep(2)
                add_info(driver, conn, product_id, new_title, product_tag,
                         new_product_price, product_image)
                test_product(driver)
예제 #7
0
 def save_pic(self,
              board_name='like',
              belong=2,
              specific_pin_url='empty',
              specific_pin_pic_url='empty'):
     saved_flag = ''
     if specific_pin_url != 'empty':
         pin_url = specific_pin_url
         pin_pic_url = specific_pin_pic_url
     else:
         pin_url = self.driver.current_url
         time.sleep(1)
         pin_pic_url = self.driver.find_element_by_xpath(
             '//a[@class="imageLink"]//img').get_attribute('src')
     add_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
     try:
         saved_flag = self.driver.find_elements_by_xpath(
             '//div[@data-test-id="saved-info"]/div/a/span').text
     except:
         pass
     if saved_flag == 'Saved to ':
         print('The picture has been saved.')
     else:
         if belong == 2:
             sql = '''SELECT * from other_pin_history where pin_pic_url="%s" or pin_url="%s" and account_id=%s''' % (
                 pin_pic_url, pin_url, self.account_id)
         elif belong == 1:
             sql = '''SELECT * from pin_history where pin_pic_url="%s" or pin_url="%s" and account_id=%s''' % (
                 pin_pic_url, pin_url, self.account_id)
         result = read_one_sql(self.conn, sql)
         if result:
             print('The picture has been saved.')
         else:
             try:
                 self.driver.find_element_by_xpath(
                     '//div[@data-test-id="boardSelectionDropdown"]').click(
                     )
                 time.sleep(5)
                 self.driver.find_element_by_xpath(
                     "//input[@id='pickerSearchField']").send_keys(
                         board_name)
                 time.sleep(2)
             except Exception as e:
                 pass
             try:
                 board_selector = self.driver.find_elements_by_xpath(
                     '//div[@data-test-id="board-picker-section"]//div[2]/div'
                 )
                 board_selector_list = []
                 for board_selector_one in board_selector:
                     board_text = board_selector_one.text
                     if board_text == board_name:
                         board_selector_list.append(board_selector_one)
                 if len(board_selector_list) > 0:
                     board_selector_list[0].click()
                     time.sleep(2)
                 else:
                     raise Exception
             except:
                 time.sleep(3)
                 self.driver.find_element_by_xpath(
                     '//div[@data-test-id="create-board"]/div').click()
                 time.sleep(3)
                 self.driver.find_element_by_name('boardName').clear()
                 time.sleep(1)
                 self.driver.find_element_by_name('boardName').send_keys(
                     board_name)
                 self.driver.find_element_by_xpath(
                     "//form//button[@type='submit']").click()
                 time.sleep(2)
             if belong == 2:
                 sql = '''INSERT INTO other_pin_history (account_id, pin_url, pin_pic_url, add_time) values (
                     %s, %s, %s, %s)'''
             elif belong == 1:
                 sql = '''INSERT INTO pin_history (account_id, pin_url, pin_pic_url, add_time) values (
                     %s, %s, %s, %s)'''
             params = (self.account_id, pin_url, pin_pic_url, add_time)
             cur = self.conn.cursor()
             cur.execute(sql, params)
             self.conn.commit()
             cur.close()
             time.sleep(3)
     write_txt_time()