Beispiel #1
0
    def handle_img(self, img_b, account_id):
        num = int(account_id) // 1000
        IMAGE_DIR = os.path.join(self.BASE_DIR, str(num))
        if not os.path.exists(IMAGE_DIR):
            os.makedirs(IMAGE_DIR)

        image_path = os.path.join(IMAGE_DIR, str(account_id) + '.jpg')
        try:
            with open(image_path, 'wb') as f:
                f.write(img_b)
            log('头像上传成功')
        except Exception as e:
            log('头像上传失败', e)

        # 更新数据库
        config_mysql_old = get_mysql_old()
        db = pymssql.connect(**config_mysql_old)
        cursor = db.cursor()
        path = 'Images/' + str(account_id // 1000) + '/' + str(account_id)
        try:
            sql_insert = """UPDATE  WXAccount SET ImageUrl='{}' WHERE ID='{}'""".format(path, account_id)
            cursor.execute(sql_insert)
            db.commit()
            log('更新数据成功', account_id)
        except Exception as e:
            log('更新数据错误', e)
            db.rollback()
Beispiel #2
0
def uploads_account_info(self, e):
    url = ''
    info = dict()
    info['name'] = e(".tit").text()
    info['account'] = self.name
    show_list = e("dl")
    features, certified = '', ''
    for show in show_list:
        if '功能介绍' in pq(show).text():
            features = pq(show).text().replace('功能介绍:\n', '')
        if '认证' in pq(show).text():
            certified = pq(show).text().split('\n')[-1]
    info['features'] = features
    info['certified'] = certified
    count_loop = 0
    while True:
        # 查询
        count_loop += 1
        if count_loop > 4:
            break
        url_public = 'http://183.131.241.60:38011/MatchAccount?account={}'.format(
            self.name)
        result1 = requests.get(url_public)
        info_image = result1.json()
        image_url = info_image.get("imageUrl")
        image_id = info_image.get("id")
        if not image_id:
            # 增源
            config_mysql_old = get_mysql_old()
            db = pymssql.connect(**config_mysql_old)
            cursor = db.cursor()
            account_link = e(".tit").find('a').attr('href')
            homepage = self.s.get(account_link, cookies=self.cookies)
            # var biz = "MzU0MDUxMjM4OQ==" || ""
            biz_find = re.search('var biz = ".*?"', homepage.text)
            biz = ''
            if biz_find:
                biz = biz_find.group().replace('var biz = ', '')
            info["biz"] = biz
            try:
                sql_insert = """
                        INSERT INTO WXAccount(Name, Account, CollectionTime, Biz, Feature, Certification)
                        VALUES ('{}', '{}', GETDATE(), '{}', '{}', '{}')""".format(
                    info.get('name'), info.get('account'), info.get('biz'),
                    info.get('features'), info.get('certified'))
                cursor.execute(sql_insert)
                db.commit()
                log('插入数据成功', info.get('name'))
                log("当前账号id为0 需要添加{}".format(self.name))
            except Exception as e:
                log('插入数据错误', e)
                db.rollback()
                continue
            time.sleep(5)
            continue
Beispiel #3
0
    def run(self):
        search_url = self.url.format(self.account)
        print(search_url)
        resp_search = self.s.get(search_url, headers=self.headers)
        if '相关的官方认证订阅号' in resp_search.text:
            log("找不到该公众号: {}".format(self.name))
            return
        e = pq(resp_search.text)
        info = dict()
        info['name'] = e(".tit").text()
        info['account'] = self.account
        show_list = e("dl")
        features, certified = '', ''
        for show in show_list:
            if '功能介绍' in pq(show).text():
                features = pq(show).text().replace('功能介绍:\n', '')
            if '认证' in pq(show).text():
                certified = pq(show).text().split('\n')[-1]
        info['features'] = features
        info['certified'] = certified

        count_loop = 0
        while True:
            count_loop += 1
            if count_loop > 2:
                break
            config_mysql_old = get_mysql_old()
            db = pymssql.connect(**config_mysql_old)
            cursor = db.cursor()
            account_link = e(".tit").find('a').attr('href')
            homepage = self.s.get(account_link, headers=self.headers)
            # var biz = "MzU0MDUxMjM4OQ==" || ""
            biz_find = re.search('var biz = ".*?"', homepage.text)
            biz = ''
            if biz_find:
                biz = biz_find.group().replace('var biz = ',
                                               '').replace('"', '')
            info["biz"] = biz
            try:
                sql_insert = """
                        INSERT INTO WXAccount(Name, Account, CollectionTime, Biz, Feature, Certification)
                        VALUES ('{}', '{}', GETDATE(), '{}', '{}', '{}')""".format(
                    info.get('name'), info.get('account'), info.get('biz'),
                    info.get('features'), info.get('certified'))
                cursor.execute(sql_insert)
                db.commit()
                log('插入数据成功', info.get('name'))
                log("当前账号id为0 需要添加{}".format(self.name))
            except Exception as e:
                log('插入数据错误', e)
                db.rollback()
                continue
            time.sleep(5)
Beispiel #4
0
def save_images():
    name = request.args.get('account')
    mysql_config = get_mysql_old()
    db = pymssql.connect(**mysql_config)
    cursor = db.cursor()
    sql_select = """
            select id from wxaccount where account=%s 
    """
    cursor.execute(sql_select, (name, ))
    info = list(cursor.fetchmany(1))[0]
    account_id = info[0]
    account.name = name
    account.account = account_id
    account.run()
    return '完成'
Beispiel #5
0
 def handle_img(self, img_b, image_id, info, path):
     url_img = 'http://47.99.50.93:8009/SaveImage'
     data_img = {'content': base64.b64encode(img_b), 'account_id': image_id}
     r = requests.post(url_img, data=data_img)
     log('头像上传:', r.status_code)
     # 更新数据库
     config_mysql_old = get_mysql_old()
     db = pymssql.connect(**config_mysql_old)
     cursor = db.cursor()
     try:
         sql_insert = """UPDATE  WXAccount SET ImageUrl='{}' WHERE ID='{}'""".format(
             path, image_id)
         cursor.execute(sql_insert)
         db.commit()
         log('更新数据成功', info.get('name'))
     except Exception as e:
         log('更新数据错误', e)
         db.rollback()
Beispiel #6
0
def save_and_back_images(account_id):
    mysql_config = get_mysql_old()
    db = pymssql.connect(**mysql_config)
    cursor = db.cursor()
    sql_select = """
            select * from wxaccount where id=%s 
    """
    cursor.execute(sql_select, (account_id,))
    result = cursor.fetchall()
    log(result)
    if len(result) > 0:
        info = result[0]
        account.name = info[2]
        account.account = info[2]
        account.account_id = account_id
        result = account.run()
    else:
        return '数据库找不到该账号'
    return result
Beispiel #7
0
def uploads_account_info_params(name, account, biz, feature, certification):
    # 微信手机版增源
    config_mysql_old = get_mysql_old()
    db = pymssql.connect(**config_mysql_old)
    cursor = db.cursor()
    try:

        sql_insert = """
                INSERT INTO WXAccount(Name, Account, CollectionTime, Biz, Feature, Certification)
                VALUES ('{}', '{}', GETDATE(), '{}', '{}', '{}')""".format(
            name, account, biz, feature, certification)
        cursor.execute(sql_insert)
        db.commit()
        log('插入数据成功', name)
        log("当前账号id为0 需要添加{}".format(name))
    except Exception as e:
        log('插入数据错误', name, e)
        db.rollback()
    time.sleep(5)
Beispiel #8
0
def save_images():
    name = request.args.get('account')
    mysql_config = get_mysql_old()
    db = pymssql.connect(**mysql_config)
    cursor = db.cursor()
    sql_select = """
            select id from wxaccount where account=%s 
    """
    cursor.execute(sql_select, (name,))
    result = cursor.fetchall()
    log(result)
    if len(result) > 0:
        info = result[0]
        account_id = info[0]
        account.name = name
        account.account = account_id
        result = account.run()
    else:
        return '数据库找不到该账号'
    return result
Beispiel #9
0
 def get_name(self):
     with open('ids.txt', 'r', encoding='utf-8') as f:
         name_all = f.read()
     id_list = name_all.split("\n")
     # print(id_list)
     _config_mysql = get_mysql_old()
     db = pymssql.connect(**_config_mysql)
     cursor = db.cursor()
     name_list = []
     for count, name in enumerate(id_list):
         sql_select = "SELECT * from WXAccount where ID={}".format(name)
         cursor.execute(sql_select)
         data = cursor.fetchone()
         if data:
             name_list.append(data[2])
         else:
             print(count, data)
     cursor.close()
     db.close()
     print(name_list)
     return name_list
Beispiel #10
0
        '64536202', '50977625', '54310231', '50505082', '107623230',
        '85599493', '123896060', '61695298', '65565426', '123607435',
        '52248207', '123298375', '65158352', '124892730', '86077671',
        '51240000', '80959290', '53692168', '51510765', '53856454', '58290550',
        '113890702', '57179802', '53632762', '58278437', '50970461',
        '52299078', '54613330', '51390169', '51390173', '50972978', '53339625',
        '51159454', '58434922', '52881323', '52803572', '2936022', '2936022'
    ]
    from config import get_mysql_old
    account_list = []
    for _id in _id_list:
        sql = '''   
                        SELECT * FROM WXAccount where id=%s
                '''

        try:
            config_mysql = get_mysql_old()
            db = pymssql.connect(**config_mysql)
            # print('链接成功')
            cursor = db.cursor()
            cursor.execute(sql, (_id, ))
            result = cursor.fetchone()
            account_list.append(result[2])
            print(result[2])
            # cursor.close()
            # db.close()
            # break
        except Exception as e:
            print('数据库上传错误 {}'.format(e))
        # break
    print(account_list)