Example #1
0
    def statistics(self, list_str):
        # 获取当前时间
        # tz = pytz.timezone('Asia/Shanghai')
        # current_time = str(datetime.datetime.now(tz))[0:16]

        # 获取当前的create_time的数字
        current_create_time = list_str[3][11:16]
        current_create_time = int(current_create_time[0:2] +
                                  current_create_time[3:6])
        current_create_time = current_create_time

        # 打开ini文件
        result = self.open_ini_result_object()
        # 如果没有检查过
        if result['is_check'] == 0:
            # 当当前创建时间超过早上9点的时候记录当前、当前前一天、当前前一天的一天的id
            if ((current_create_time >= 915)
                    and (current_create_time <= 1000)):
                result['is_check'] = 1
                num1 = str(int(list_str[0]) - int(result["today_id"]))
                num1_perhour = str(
                    round((int(list_str[0]) - int(result["today_id"])) / 24,
                          1))
                result['pre_pre_day_id'] = result['pre_day_id']
                result['pre_day_id'] = result["today_id"]
                result['today_id'] = list_str[0]

                info = "过去一天有" + num1 + "个词条,平均一小时" + num1_perhour + "个"
                pop(bar_pop, [2, '更新统计:' + info])
                send_statics_email(info)
        self.write_str_result_to_ini(result)
        if current_create_time > 1000:
            result['is_check'] = 0
            self.write_str_result_to_ini(result)
        # 得到早上到目前的创建词条数
        today_num = str(int(list_str[0]) - int(result["today_id"]))

        # 得到早上到现在平均每小时多少个词
        sub_minute = (current_create_time - 915) / 60
        if sub_minute == 0:  # 防止sub_minute=0
            sub_minute = 1
        today_persent = str(round(int(today_num) / sub_minute, 1))

        # 前一天总数
        pre_num = str(int(result["today_id"]) - int(result['pre_day_id']))
        # 前一天平均
        pre_persent = str(round(int(pre_num) / 24, 1))
        # 大前天总数
        pre_pre_num = str(
            int(result['pre_day_id']) - int(result['pre_pre_day_id']))
        # 大前天平均
        pre_pre_persent = str(round(int(pre_pre_num) / 24, 1))
        if int(result['count']) % 100 == 0:
            info = "最后创建时间" + list_str[
                3] + ",早上到目前:" + today_num + "个,平均一小时:" + today_persent + "个,前一天总数:" + pre_num + "个,前一天平均一小时" + pre_persent + "个,大前天总数" + pre_pre_num + "个,大前天平均一小时" + pre_pre_persent + "个,当前词:" + list_str[
                    1] + ",当前num:" + list_str[2]
            print(info)
            pop(bar_pop, ['2', info])
Example #2
0
    def send_message(self, result, num):
        directory = result['directory']

        info = ''
        if len(directory) > 20:
            info = ',有目录'
        info = '当前第' + str(num['num']) + '个词条,标题是:' + result['title'] + info
        print(info)
        pop(bar_pop, [0, info])
        num['num'] += 1
Example #3
0
    def end_order_user_create(self, start_time, create_funs, user_info):
        end_time = d.datetime.now().strftime("%Y-%m-%d %H:%M:%S")  # 结束时间
        start = create_funs.str_to_int(start_time)
        end = create_funs.str_to_int(end_time)
        num = (end - start) / 60
        m = int(num)
        s = (end - start) - m * 60
        end_time = d.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

        info = user_info + '顺序循环结束,开始时间:' + start_time + ',结束时间:' + end_time + ',用时' + str(
            m) + '分' + str(s) + '秒'
        function.send_statics_email(info)
        pop(bar_pop, [0, info])
Example #4
0
 def end_sigal_user_edit(self, start_time, edit_funs, users, mod):
     end_time = d.datetime.now().strftime("%Y-%m-%d %H:%M:%S")  # 结束时间
     start = edit_funs.str_to_int(start_time)
     end = edit_funs.str_to_int(end_time)
     num = (end - start) / 60
     m = int(num)
     s = (end - start) - m * 60
     end_time = d.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
     index = mod['index'] - 1
     user = users[index]
     info = '账号:' + user['name'] + '已编辑' + str(
         mod['each_num']
     ) + '个词条(结束),开始时间:' + start_time + ',结束时间:' + end_time + ',用时' + str(
         m) + '分' + str(s) + '秒'
     function.send_statics_email(info)
     print(info)
     pop(bar_pop, [1, info])
Example #5
0
 def get_status(self, users):
     is_true = True
     list1 = []
     try:
         WebDriverWait(self.driver, 10, 0.5).until(
             EC.presence_of_element_located(
                 (By.CSS_SELECTOR, '.product-page')))
         iframe = self.driver.find_element_by_css_selector('.product-page')
         self.driver.switch_to_frame(iframe)
         sleep(1)
         level = self.driver.find_element_by_css_selector(
             '.block-level > div:nth-child(1) > h3:nth-child(1) > b:nth-child(1)'
         ).text  # 等级
         score = self.driver.find_element_by_css_selector(
             '.block-level > div:nth-child(1) > h3:nth-child(1) > b:nth-child(2)'
         ).text  # 经验值
         money = self.driver.find_element_by_css_selector(
             '.block-level > div:nth-child(1) > h3:nth-child(2) > b:nth-child(1)'
         ).text  # 财富值
         pass_num = self.driver.find_element_by_css_selector(
             '.version_content_pie > div:nth-child(3) > span:nth-child(1)'
         ).text  # 通过版本数
         rate = self.driver.find_element_by_css_selector(
             '.ratio_content_pie > div:nth-child(3) > span:nth-child(1)'
         ).text  # 通过率
         latest_modify_time = self.driver.find_element_by_css_selector(
             '.list-container > tr:nth-child(1) > td:nth-child(3)'
         ).text  # 最近通过时间
         list1 = [level, score, money, pass_num, rate, latest_modify_time]
     except:
         is_true = False
     finally:
         if is_true == False:
             result = self.open_ini_result_object()
             result['current_index'] += 1
             if result['current_index'] == len(users):
                 result['current_index'] = 0
             self.save_ini(result)
             print('元素没找到,过一个')
             pop(bar_pop, [3, '元素没找到,过一个'])
             return False
         else:
             return list1
Example #6
0
	def test_login(self):
		mod = {
			'order': 4,  # 1顺序,2随机,3倒叙,4单点
			'each_num': 10,  # 表示每个帐户创建的词条数
			'index': 17  # 从第几个账号开始
		}

		start_user_index = mod['index']
		users = [
			{'name': '欢乐麻酱', 'password': '******'},  # ————————————————1
			{'name': 'sukyyear', 'password': '******'},  # ———————————————2
			{'name': '天使焦7000', 'password': '******'},  # ——————————————3
			{'name': '神刀门们主', 'password': '******'},  # ——————————————4
			{'name': '让子弹跑路', 'password': '******'},  # ——————————————5
			{'name': '干扰者狂魔', 'password': '******'},  # ——————————————6
			{'name': '寒帝神牛', 'password': '******'},  # ————————————————7
			{'name': 'DOTA军团指挥官', 'password': '******'},  # ———-----——8
			{'name': '福瑞斯听我说', 'password': '******'},  # ————————————9
			{'name': '威海uncle', 'password': '******'},  # ——————————————10
			{'name': '这这亮响', 'password': '******'},  # ————————————————11
			{'name': '真没意思的', 'password': '******'},  # ————————————12
			{'name': '看似不懂算了', 'password': '******'},  # ——————13
			{'name': '亮仔美睸', 'password': '******'},  # ———————————————14
			{'name': '超凡入胜007', 'password': '******'},  # —————————————15
			{'name': 'saicodings', 'password': '******'},  # —————————————16
			{'name': '永恒领凡', 'password': '******'},  # ————————————————17
			{'name': '杭州同济医院v', 'password': '******'},  # ———————————18
			{'name': '何风一来风', 'password': '******'},  # ———————————————19
			{'name': '百科代王', 'password': '******'},  # —————————————————20
		]

		# 开始时间
		start_time = d.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

		# 实例化对象
		book_zgrm = Bookzgrm(self.driver)
		create_funs = CreateFuns()
		user_info = ''
		last_user_name = ''
		cookiestr = ''
		num = {'num': 1}
		while True:
			# arg1:表示模式1顺序,2随机,3倒叙,4单个,arg2:表示每个帐户创建的词条数,arg3:表示从第几个账号开始,
			user = create_funs.mod(users, mod, start_user_index)

			# 单个词条创建结束
			if user == 4:
				create_funs.end_sigal_user_create(start_time, create_funs, users, mod)
				break
			# 顺序或者倒序结束
			if user == 1 or user == 2:
				create_funs.end_order_user_create(start_time, create_funs, user_info)
				break
			if last_user_name != user['name']:
				last_user_name = user['name']
				# 设置定位器,登陆账号等信息
				options = {
					'username': user['name'],
					'password': user['password'],
					'base_url': 'https://passport.baidu.com/v2/?login',
					'username_loc': (By.ID, "TANGRAM__PSP_3__userName"),
					'password_loc': (By.ID, "TANGRAM__PSP_3__password"),
					'submit_loc': (By.ID, "TANGRAM__PSP_3__submit"),
					'pass_loc': (By.ID, "displayUsername"),
					'fail_loc': (By.ID, "TANGRAM__PSP_3__error"),
					'trade_loc': (By.ID, "TANGRAM__PSP_3__footerULoginBtn"),
					'url': ''
				}
				po = LoginBaike(self.driver, options)
				# 开始登陆
				po.login_action()
				# 等待页面加载指定的元素出现
				WebDriverWait(self.driver, 10, 0.5).until(EC.presence_of_element_located((By.ID, 'mod_feedback')))
				self.driver.get('https://baike.baidu.com/usercenter/lemmas#passed')
				WebDriverWait(self.driver, 10, 0.5).until(
					EC.presence_of_element_located((By.CLASS_NAME, 'list-container')))
				# 得到页面用户信息
				info = create_funs.get_current_user_info(self.driver, user)
				print(info)
				# 弹出系统气泡
				pop(bar_pop, [0, info])
				user_info += info
				# 得到cookie
				cookie = [item["name"] + "=" + item["value"] for item in self.driver.get_cookies()]
				cookiestr = ';'.join(item for item in cookie)

			# 得到初始搜索ID
			start_id = book_zgrm.get_start_page_num(create_funs)

			# 导航到这个初始ID的页面
			book_zgrm.go_to_start_page(start_id)

			# 等待5秒,让保证页面载入完全,然后找到要点击的链接
			book_zgrm.go_detail_page(create_funs)

			# 得到百科创建的标题和基本信息栏,内容,作者等
			result = book_zgrm.get_result()

			# 判断如果内容为空,就继续下个循环
			if result['content'] == "":
				create_funs.treatment_not_exist_baike(create_funs, start_id)
				continue
			# 打开创建页面
			self.driver.get('http://baike.baidu.com/create/' + result['title'])

			# 判断创建的词条名称是否存在
			if self.driver.title == "百度百科——全球最大中文百科全书" or self.driver.title == "百度百科_全球最大中文百科全书":
				create_funs.treatment_not_exist_baike(create_funs, start_id)
			# 词条名称不存在就开始创建
			else:
				# 创建词条
				baike = create_funs.get_baike(result)
				create_funs.create(baike, cookiestr)
				# 保存创建的词条
				create_funs.save_all_created_baike(result)
				# 创建成功后的处理
				create_funs.treatment_success_create(create_funs, start_id)
				# 发送消息
				create_funs.send_message(result, num)
Example #7
0
 def send_message(self, result, num):
     info = '当前编辑第' + str(num['num']) + '个词条,标题是:' + result['title']
     print(info)
     pop(bar_pop, [1, info])
     num['num'] += 1
Example #8
0
    def trade_modify(self, status_list, user, users):
        result = self.open_ini_result_object()
        index = result['current_index']
        info = user + '=>'
        sleep(5)
        # 开始启动,就初始化值
        if result['start_status'] == [] or len(
                result['start_status']) < len(users):
            result['start_status'].append(status_list)
        # 没有变化
        elif result['start_status'][index] == status_list:
            pass
        # 有了变化
        elif result['start_status'][index] != status_list:
            # a ={'w':result['start_status'][index],'index':index}
            # b = {'w':status_list,'index':index}
            # print(json.dumps(a)+'')
            # print(json.dumps(b))

            origin_list = result['start_status'][index]
            if status_list[3] != origin_list[3]:  # 通过版本数
                sub = int(status_list[3]) - int(origin_list[3])
                result['start_status'][index][3] = status_list[3]
                info += "通过了" + str(sub) + "个版本,"
                pop(bar_pop, [3, info])

            if status_list[0] != origin_list[0]:  # 等级
                result['start_status'][index][0] = status_list[0]
                info += "升级啦!从" + origin_list[0] + "升到" + status_list[0] + ","
                pop(bar_pop, [3, info])

            if status_list[1] != origin_list[1]:  # 经验值
                sub = int(status_list[1]) - int(origin_list[1])
                result['start_status'][index][1] = status_list[1]
                info += "总分经验值" + status_list[1] + "增加了" + str(sub) + ","
                pop(bar_pop, [3, info])

            if status_list[2] != origin_list[2]:  # 财富值
                info += "当前财富值" + status_list[2] + ","
                result['start_status'][index][2] = status_list[2]
                pop(bar_pop, [3, info])

            if status_list[4] != origin_list[4]:  # 通过率
                sub = int(status_list[4]) - int(origin_list[4])
                result['start_status'][index][4] = status_list[4]
                if sub > 0:
                    info += "通过率提升" + str(sub) + "%,"
                    pop(bar_pop, [3, info])
                if sub < 0:
                    info += "通过率降低" + str(sub) + "%,"
                    pop(bar_pop, [3, info])

            info += '通过率' + result['start_status'][index][4] + '%,'
            if status_list[5] != origin_list[5]:  # 最后通过时间
                result['start_status'][index][5] = status_list[5]
                info += "最后通过时间" + status_list[5]
                pop(bar_pop, [3, info])
                print(info)

        result['current_index'] += 1

        if result['current_index'] == len(users):
            result['current_index'] = 0

        # 保存变化
        self.save_ini(result)
Example #9
0
    def test_edit(self):
        mod = {
            'order': 4,  # 1顺序,2随机,3倒叙,4单点
            'each_num': 10,  # 表示每个帐户编辑的词条数
            'index': 16  # 从第几个账号开始4
        }
        start_user_index = mod['index']
        users = [
            {
                'name': '欢乐麻酱',
                'password': '******'
            },  # ————————————————1
            {
                'name': 'sukyyear',
                'password': '******'
            },  # ———————————————2
            {
                'name': '天使焦7000',
                'password': '******'
            },  # ——————————————3
            {
                'name': '神刀门们主',
                'password': '******'
            },  # ——————————————4
            {
                'name': '让子弹跑路',
                'password': '******'
            },  # ——————————————5
            {
                'name': '干扰者狂魔',
                'password': '******'
            },  # ——————————————6
            {
                'name': '寒帝神牛',
                'password': '******'
            },  # ————————————————7
            {
                'name': 'DOTA军团指挥官',
                'password': '******'
            },  # ———-----——8
            {
                'name': '福瑞斯听我说',
                'password': '******'
            },  # ————————————9
            {
                'name': '威海uncle',
                'password': '******'
            },  # ——————————————10
            {
                'name': '这这亮响',
                'password': '******'
            },  # ————————————————11
            {
                'name': '真没意思的',
                'password': '******'
            },  # ————————————12
            {
                'name': '看似不懂算了',
                'password': '******'
            },  # ——————13
            {
                'name': '亮仔美睸',
                'password': '******'
            },  # ———————————————14
            {
                'name': '超凡入胜007',
                'password': '******'
            },  # —————————————15
            {
                'name': 'saicodings',
                'password': '******'
            },  # —————————————16
            {
                'name': '永恒领凡',
                'password': '******'
            },  # ————————————————17
            {
                'name': '杭州同济医院v',
                'password': '******'
            },  # ———————————18
            {
                'name': '何风一来风',
                'password': '******'
            },  # ———————————————19
        ]
        # 开始时间
        start_time = d.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

        # 实例化对象
        edit_funs = EditFuns()
        last_user_name = ''
        user_info = ''
        book_zgrm = Bookzgrm(self.driver)
        num1 = {'num': 1}

        while True:
            # arg1:表示模式1顺序,2随机,3倒叙,4单个,arg2:表示每个帐户创建的词条数,arg3:表示从第几个账号开始,
            user = edit_funs.mod(users, mod, start_user_index)

            # 单个词条创建结束
            if user == 4:
                edit_funs.end_sigal_user_edit(start_time, edit_funs, users,
                                              mod)
                break
            # 顺序或者倒序结束
            if user == 1 or user == 2:
                edit_funs.end_order_user_edit(start_time, edit_funs, user_info)
                break

            if last_user_name != user['name']:
                last_user_name = user['name']
                # 设置定位器,登陆账号等信息
                options = {
                    'username': user['name'],
                    'password': user['password'],
                    'base_url': 'https://passport.baidu.com/v2/?login',
                    'username_loc': (By.ID, "TANGRAM__PSP_3__userName"),
                    'password_loc': (By.ID, "TANGRAM__PSP_3__password"),
                    'submit_loc': (By.ID, "TANGRAM__PSP_3__submit"),
                    'pass_loc': (By.ID, "displayUsername"),
                    'fail_loc': (By.ID, "TANGRAM__PSP_3__error"),
                    'trade_loc': (By.ID, "TANGRAM__PSP_3__footerULoginBtn"),
                    'url': ''
                }
                po = LoginBaike(self.driver, options)
                # 开始登陆
                po.login_action()
                # 等待页面加载指定的元素出现
                WebDriverWait(self.driver, 10, 0.5).until(
                    EC.presence_of_element_located((By.ID, 'mod_feedback')))
                self.driver.get(
                    'https://baike.baidu.com/usercenter/lemmas#passed')
                WebDriverWait(self.driver, 10, 0.5).until(
                    EC.presence_of_element_located(
                        (By.CLASS_NAME, 'list-container')))
                # 得到页面用户信息
                info = edit_funs.get_current_user_info(self.driver, user)
                print(info)
                pop(bar_pop, [1, info])
                user_info += info

            # 得到初始编辑url
            get_book_url = edit_funs.get_book_url()

            # 导航到网址,并得到结果
            if len(get_book_url) == 0:
                print('书目录已空')
                pop(bar_pop, [1, '书目录已空'])
                break
            else:
                book_zgrm.go_to_detal_page(get_book_url[0])
                result = book_zgrm.get_result()

            # 下载图片,判断图片是否存在(如果图片不存在下载时会有弹窗)
            self.driver.get(result['down_url'])
            try:
                alert = self.driver.switch_to.alert
                print('没有图片')
                alert.accept()
                result['down_url'] = ''
                pass
            except:
                pass

            self.driver.get('https://baike.baidu.com/item/' + result['title'])

            page_title = self.driver.title

            if (page_title == "百度百科——全球最大中文百科全书"
                    or page_title == "百度百科_全球最大中文百科全书"):
                edit_funs.trade_fail_open_url(get_book_url)
            else:
                # 判断修改次数
                url = 'https://baike.baidu.com/item/' + result['title']
                times = edit_funs.justfy_edit_times(self.driver, url)
                if times == '1':

                    # 编辑词条
                    WebDriverWait(self.driver, 10, 0.5).until(
                        EC.presence_of_element_located(
                            (By.CLASS_NAME,
                             'lemmaWgt-promotion-rightPreciseAd')))
                    num = self.driver.find_element_by_css_selector(
                        '.lemmaWgt-promotion-rightPreciseAd').get_attribute(
                            "data-lemmaid")
                    # 打开词条连接
                    self.driver.get('http://baike.baidu.com/edit/1/' +
                                    str(num))
                    is_new = False
                    try:
                        WebDriverWait(self.driver, 5, 0.5).until(
                            EC.presence_of_element_located(
                                (By.ID, 'introjs-skipbutton')))
                        is_new = True
                    except:
                        pass
                    finally:
                        if is_new:
                            print('是真的')
                            self.driver.find_element_by_id(
                                'introjs-skipbutton').click()
                    WebDriverWait(self.driver, 10, 0.5).until(
                        EC.presence_of_element_located((By.ID, 'bke_title')))
                    # 添加基本信息栏
                    edit_funs.add_card(self.driver, result)
                    sleep(2)

                    # 添加概述图
                    edit_funs.add_summary_pic(self.driver, result)
                    sleep(5)

                    # 切换到编辑界面
                    self.driver.switch_to_frame('ueditor_0')

                    # 编辑正文
                    edit_funs.add_content(self.driver, result)

                    sleep(10)
                    # 编辑成功后的处理
                    edit_funs.treatment_success_edit(get_book_url)
                    # 发送消息
                    edit_funs.send_message(result, num1)
                else:
                    edit_funs.trade_fail_open_url(get_book_url)