Example #1
0
def form():
    if request.method == 'GET':
        config = configparser.RawConfigParser()
        config.read("group-answer.ini", encoding="utf-8")
        return render_template("amz/track-form.html",
                               groups=config.sections(),
                               user=session.get('user'),
                               active="amzTrackForm")
    if request.method == 'POST':
        data = request.get_data()
        json_data = json.loads(data.decode("utf-8"))
        mp = MysqlPool()
        sql = "insert into tb_amz_track_pro(user_id,keyword,asin,status,page_size,add_time) values(%s,%s,%s,%s,%s,now())"
        param = [
            session.get('user')['id'],
            json_data.get("keyword"),
            json_data.get("asin"), "1",
            json_data.get('page_size')
        ]
        try:
            mp.insert(sql, param)
            res_json = {"code": "0000", "message": "已成功提交追踪任务"}
        except IntegrityError as e:
            res_json = {"code": "1000", "message": "%s" % e}
        return jsonify(res_json)
def getFbDataByUser():
    data = request.get_data()
    json_data = []
    if data:
        json_data = json.loads(data.decode("utf-8"))
    mp = MysqlPool()
    sql = "select * from tb_post where user_id=%s "
    param = [session.get('user')['id']]
    try:
        if json_data.get('status'):
            sql += "and status=%s "
            param.append(json_data.get('status'))
    except:
        pass
    try:
        if json_data.get('keyword'):
            keyword = '%' + str(json_data.get('keyword')) + '%'
            sql += " and keyword like %s "
            param.append(keyword)
    except:
        pass
    try:
        if json_data.get('group_id'):
            group_id = '%' + str(json_data.get('group_id')) + '%'
            sql += " and group_id like %s "
            param.append(group_id)
    except:
        pass
    sql += "order by id desc"
    post_list = mp.fetch_all(sql,param)
    res_json = {"code":"0000","list":post_list}
    return jsonify(res_json)
Example #3
0
def getTrackData():
    data = request.get_data()
    json_data = []
    if data:
        json_data = json.loads(data.decode("utf-8"))
    mp = MysqlPool()
    sql = "SELECT t.*,DATE_FORMAT(t.add_time,'%%Y-%%m-%%d %%H') update_time, tt.asin, tt.keyword, tt.page_size, tt.status FROM tb_amz_track_data t, tb_amz_track_pro tt " \
          "WHERE t.add_time IN ( SELECT MAX(t1.add_time) FROM tb_amz_track_data t1 GROUP BY t1.pro_id ) " \
          "AND t.pro_id = tt.id AND tt.user_id = %s"
    param = [session.get('user')['id']]
    try:
        if json_data.get('status'):
            sql += "and tt.status=%s "
            param.append(json_data.get('status'))
    except:
        pass
    try:
        if json_data.get('keyword'):
            keyword = '%' + str(json_data.get('keyword')) + '%'
            sql += " and tt.keyword like %s "
            param.append(keyword)
    except:
        pass
    try:
        if json_data.get('asin'):
            sql += " and tt.asin = %s "
            param.append(json_data.get('asin'))
    except:
        pass
    sql += " order by t.id desc"
    post_list = mp.fetch_all(sql, param)
    res_json = {"code": "0000", "list": post_list}
    return jsonify(res_json)
Example #4
0
def addComment():
    data = request.get_data()
    json_data = json.loads(data.decode("utf-8"))
    mp = MysqlPool()
    sql = "insert into tb_comment(content,add_time) values(%s,%s)"
    mp.insert(sql, [json_data.get('content'), datetime.now()])
    res_json = {"code": "0000"}
    return jsonify(res_json)
Example #5
0
def updateComment():
    data = request.get_data()
    json_data = json.loads(data.decode("utf-8"))
    mp = MysqlPool()
    sql = "update tb_comment set content=%s where id=%s"
    mp.insert(sql, [json_data.get('content'), json_data.get('id')])
    res_json = {"code": "0000"}
    return jsonify(res_json)
Example #6
0
def deleteComment():
    data = request.get_data()
    json_data = json.loads(data.decode("utf-8"))
    mp = MysqlPool()
    sql = "delete from tb_comment where id=%s"
    mp.update(sql, json_data.get('id'))
    res_json = {"code": "0000"}
    return jsonify(res_json)
Example #7
0
def getDataByProId():
    data = request.get_data()
    json_data = json.loads(data.decode("utf-8"))
    sql = "select *,DATE_FORMAT(t.add_time,'%%m月%%d日%%H时') update_time from tb_amz_track_data t where t.pro_id = %s order by t.id asc"
    param = [json_data.get('pro_id')]
    mp = MysqlPool()
    pro_list = mp.fetch_all(sql, param)
    res_json = {"code": "0000", "list": pro_list}
    return jsonify(res_json)
def updateAsinStatus():
    data = request.get_data()
    json_data = json.loads(data.decode("utf-8"))
    sql = "update tb_task_asin set status=%s where id=%s"
    param = [json_data.get('status'), json_data.get('id')]
    mp = MysqlPool()
    mp.update(sql, param)
    res_json = {"code": "0000", "msg": "上架状态修改成功!"}
    return jsonify(res_json)
def updateTaskDiscount():
    data = request.get_data()
    json_data = json.loads(data.decode("utf-8"))
    sql = "update tb_review_task set discount=%s where id=%s"
    param = [json_data.get('discount'), json_data.get('id')]
    mp = MysqlPool()
    mp.update(sql, param)
    res_json = {"code": "0000", "msg": "折扣修改成功!"}
    return jsonify(res_json)
def reviewList():
    mp = MysqlPool()
    user = session.get('user')
    user_sql = "select * from tb_user"
    user_list = None
    if user['level'] == 1:
        user_list = mp.fetch_all(user_sql, None)
    return render_template("review/review-list.html",
                           user=session.get('user'),
                           active="reviewList",
                           user_list=user_list)
def updateUser():
    data = request.get_data()
    json_data = []
    if data:
        json_data = json.loads(data.decode("utf-8"))
    mp = MysqlPool()
    sql = "update tb_user set status=%s where id=%s"
    param = [json_data.get('status'), json_data.get('id')]
    mp.update(sql, param)
    res_json = {"code": "0000", "msg": "修改成功"}
    return jsonify(res_json)
Example #12
0
def updateTrackStatus():
    data = request.get_data()
    json_data = json.loads(data.decode("utf-8"))
    status = json_data.get('status')
    sql = "update tb_amz_track_pro set status=%s where id=%s"
    if status == 1: update_status = 0
    else: update_status = 1
    param = [update_status, json_data.get('id')]
    mp = MysqlPool()
    mp.update(sql, param)
    res_json = {"code": "0000", "msg": "状态修改成功!"}
    return jsonify(res_json)
def getOrderData():
    data = request.get_data()
    json_data = []
    if data:
        json_data = json.loads(data.decode("utf-8"))
    mp = MysqlPool()
    sql = "SELECT t.*,DATE_FORMAT(t.order_time,'%%Y-%%m-%%d') order_time_str,tb.profile " \
          "from tb_task_order t,tb_buyer tb where t.task_id = %s and t.buyer_id = tb.id"
    param = [json_data.get('task_id')]
    sql += " order by t.order_time desc"
    order_list = mp.fetch_all(sql, param)
    res_json = {"code": "0000", "list": order_list}
    return jsonify(res_json)
Example #14
0
def init(msg, import_id, uid_tid_lid):
    global mysql_pool, mongo_cn, fp_err_t1, fp_err_t2
    conf = pyetc.load(os.path.join(ROOT, 'conf', 'setting.conf'))

    # 获取数据库
    dbconf = {'mysql': conf.mysql, 'mongo': conf.mongo}

    try:
        mysql_pool = MysqlPool.Mysql(dbconf, log)
    except BaseException as e:
        log.error(u'{}. init mysql pool exception.'.format(msg))
        log.error(traceback.format_exc())
        do_except(uid_tid_lid)

    try:
        mongo_cn = MongoPool.Mongo(dbconf, log)
        mongo_cn.init()
    except BaseException as e:
        log.error(traceback.format_exc())
        do_except(uid_tid_lid)

    try:
        # 错误类型 1
        err_t1_name = '{}_{}_err_t1.txt'.format(import_id, 'maillist')
        err_t1_path = os.path.join(ERR_ADDR_PATH, err_t1_name)
        fp_err_t1 = open(err_t1_path, "a")
        # 错误类型 2
        err_t2_name = '{}_{}_err_t2.txt'.format(import_id, 'maillist')
        err_t2_path = os.path.join(ERR_ADDR_PATH, err_t2_name)
        fp_err_t2 = open(err_t2_path, "a")
    except:
        log.error(u'{}. init error file failure.'.format(msg))
        do_except(uid_tid_lid)
Example #15
0
def fileUpload():
    if request.method == 'POST':
        if 'file' not in request.files:
            return redirect(request.url)
        file = request.files['file']
        mp = MysqlPool()
        sql = "insert into tb_comment(content,add_time) values(%s,now())"
        params = []
        while True:
            lines = file.readline()  # 整行读取数据
            if not lines:
                break
            params.append(lines)
        mp.insertMany(sql, params)
    res_json = {"code": "0000"}
    return jsonify(res_json)
def login():
    if request.method == 'GET':
        return render_template("login.html")
    if request.method == 'POST':
        '''
        设置session过期时间,默认1个月
        session.permanent = True
        app.permanent_session_lifetime = timedelta(minutes=1)
        '''
        account = request.form.get("account").lower()
        mp = MysqlPool()
        user = mp.fetch_one("select * from tb_user where account=%s", account)
        if user:
            if pyUtils.getMd5(request.form.get("pwd")) == user['password']:
                if user['status'] == 3:
                    flash("帐号已停用,请联系管理员")
                elif user['status'] == 2:
                    flash("帐号待审核,请联系管理员")
                else:
                    session['user'] = user
                    mp = MysqlPool()
                    sql = "update tb_user set login_time=now() where id=%s"
                    mp.update(sql, user['id'])
                    if user['level'] == 1: return redirect('/index')
                    elif user['level'] == 2:
                        return redirect('/review/reviewList')
            else:
                flash("密码错误")
        else:
            flash("帐号未注册")
        return redirect(url_for("login"))
def getUserData():
    data = request.get_data()
    json_data = []
    if data:
        json_data = json.loads(data.decode("utf-8"))
    mp = MysqlPool()
    sql = "select t.id,t.account,t.level,t.nickname,t.status,DATE_FORMAT(t.reg_time,'%%Y-%%m-%%d %%H:%%i:%%s') reg_time," \
          "DATE_FORMAT(t.login_time,'%%Y-%%m-%%d %%H:%%i:%%s') login_time from tb_user t where 1=1 "
    param = []
    try:
        if json_data.get('level'):
            sql += "and level=%s "
            param.append(json_data.get('level'))
    except:
        pass
    user_list = mp.fetch_all(sql, param)
    res_json = {"code": "0000", "list": user_list}
    return jsonify(res_json)
def form():
    if request.method == 'GET':
        config = configparser.RawConfigParser()
        config.read("group-answer.ini", encoding="utf-8")
        return render_template("fb/form.html", groups=config.sections(), user=session.get('user'),active="fbForm")
    if request.method == 'POST':
        data = request.get_data()
        json_data = json.loads(data.decode("utf-8"))
        mp = MysqlPool()
        try:
            for i,group_id in enumerate(json_data.get('group_id')):
                sql = "insert into tb_post(group_id,keyword,nums,share_num,done_num,done_share,content,user_id,status,add_time,accounts) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,'')"
                param = [group_id, json_data.get("keyword"), json_data.get("nums"),json_data.get("share_num"),"0","0",
                         json_data.get('content'), session.get('user')['id'], 'working', datetime.now()]
                mp.insert(sql, param)
            res_json = {"code": "0000", "message": "已成功提交%s个任务" % (len(json_data.get('group_id')))}
        except IntegrityError as e:
            res_json = {"code":"1000","message":"%s"%e}
        return jsonify(res_json)
def getCpData():
    data = request.get_data()
    json_data = []
    if data:
        json_data = json.loads(data.decode("utf-8"))
    param = []
    mp = MysqlPool()
    sql = "select * from tb_comment "
    try:
        if json_data.get('content'):
            content = '%' + str(json_data.get('content')) + '%'
            sql += "where content like %s "
            param.append(content)
    except:
        pass
    sql += "order by id desc"
    cp_list = mp.fetch_all(sql,param)
    res_json = {"code":"0000","list":cp_list}
    return jsonify(res_json)
Example #20
0
def startTrack():
    url = "http://ip.ipjldl.com/index.php/api/entry?method=proxyServer.tiqu_api_url&packid=0&fa=0" \
          "&dt=0&groupid=0&fetch_key=&qty=1&time=1&port=1&format=json&ss=5&css=&dt=0&pro=&city=&usertype=6"
    i = 1
    find_mp = MysqlPool()
    find_sql = "select * from tb_amz_track_pro where status=1"
    product_list = find_mp.fetch_all(find_sql, None)
    success_list = []
    track_list = [x for x in product_list if x not in success_list]
    all_log.logger.info("#######亚马逊关键词ASIN追踪开始#######")
    while len(track_list) > 0 and i < 10:
        ip_data = urllib.request.urlopen(url).read()
        json_list = list(json.loads(ip_data)['data'])
        json_data = json_list[0]
        ip = "%s:%s" % (json_data['IP'], json_data['Port'])
        success_list += getProData(ip, track_list)
        print("success_list=",len(success_list))
        track_list = [x for x in product_list if x not in success_list]
        all_log.logger.info("##########第%s轮追踪结束##########" % i)
        i += 1
    all_log.logger.info("#######亚马逊关键词ASIN追踪结束#######")
def addUser():
    data = request.get_data()
    json_data = []
    if data:
        json_data = json.loads(data.decode("utf-8"))
    mp = MysqlPool()
    sql = "insert into tb_user(account, password, nickname, level, status, reg_time) values (%s,%s,%s,%s,1,now())"
    param = [
        json_data.get('account'),
        pyUtils.getMd5(json_data.get("password")),
        json_data.get('nickname'),
        json_data.get('level')
    ]
    msg = "用户添加成功"
    try:
        mp.update(sql, param)
    except pymysql.err.IntegrityError:
        msg = "添加失败,用户名已存在"
    except Exception as e:
        msg = "添加失败,%s" % e
    res_json = {"code": "0000", "msg": msg}
    return jsonify(res_json)
def getReviewData():
    data = request.get_data()
    json_data = []
    if data:
        json_data = json.loads(data.decode("utf-8"))
    mp = MysqlPool()
    sql = "SELECT t.*,DATE_FORMAT(t.add_time,'%%Y-%%m-%%d') add_time_str,u.nickname," \
          "(select count(0) from tb_task_order t1 where t1.task_id=t.id) num," \
          "(select count(0) from tb_task_order t1 where t1.task_id=t.id and t1.status=1) done_num," \
          "REPLACE(t.asin,'|',' ') as asin_str" \
          " from tb_review_task t,tb_user u where t.user_id = u.id "
    param = []
    if session.get('user')['level'] != 1:
        sql += 'and t.user_id = %s'
        param.append(session.get('user')['id'])
    try:
        if json_data.get('keyword'):
            keyword = '%' + str(json_data.get('keyword')) + '%'
            sql += " and t.keyword like %s "
            param.append(keyword)
    except:
        pass
    try:
        if json_data.get('asin'):
            asin = '%' + str(json_data.get('asin')) + '%'
            sql += " and t.asin like %s "
            param.append(asin)
    except:
        pass
    try:
        if json_data.get('user_id'):
            sql += " and t.user_id = %s "
            param.append(json_data.get('user_id'))
    except:
        pass
    sql += " order by t.status desc,t.id desc"
    review_list = mp.fetch_all(sql, param)
    res_json = {"code": "0000", "list": review_list}
    return jsonify(res_json)
def getKeyword():
    mp = MysqlPool()
    options = webdriver.ChromeOptions()
    options.add_argument("--start-maximized")
    options.add_argument("--headless")
    options.add_argument("--disable-gpu")
    options.add_argument('blink-settings=imagesEnabled=false')
    options.add_experimental_option('useAutomationExtension', False)
    options.add_experimental_option('excludeSwitches',
                                    ['enable-logging', 'enable-automation'])
    driver = webdriver.Chrome(options=options)
    driver.get(
        "https://www.amz123.com/usatopkeywords-1-1-.htm?rank=0&uprank=0")
    txt = '▶'
    while txt == '▶':
        try:
            data_lists = driver.find_elements_by_xpath(
                '//div[@class="listdata"]')
            for data in data_lists:
                try:
                    keyword = data.find_element_by_xpath('./div').text
                    cur_rank = data.find_element_by_xpath('./div[2]').text
                    last_rank = data.find_element_by_xpath('./div[3]').text
                    sql = "insert into amz123_keyword set keyword=%s,cur_rank=%s,last_rank=%s,add_time=now()"
                    param = [keyword, cur_rank, last_rank]
                    mp.insert(sql, param)
                    print("---%s入库成功---" % keyword)
                except:
                    continue
            sleep(1)
            next_page = driver.find_element_by_xpath('//nav/ul/li[last()]')
            txt = next_page.text
            if next_page.text == '▶':
                next_page.click()
        except:
            continue
    print("采集完毕")
    driver.close()
    driver.quit()
def getGroundingData():
    data = request.get_data()
    json_data = []
    if data:
        json_data = json.loads(data.decode("utf-8"))
    mp = MysqlPool()
    sql = "select t.*,t1.price,t1.status as task_status,u.nickname,t1.img," \
          "DATE_FORMAT(t.put_time,'%%Y-%%m-%%d %%H:%%i') put_time_str" \
          " from tb_task_asin t,tb_review_task t1,tb_user u where t1.id=t.task_id and t1.user_id=u.id "
    param = []
    try:
        if json_data.get('order_status'):
            sql += " and t.status = %s "
            param.append(json_data.get('order_status'))
    except:
        pass
    try:
        if json_data.get('asin'):
            sql += " and t.asin = %s "
            param.append(json_data.get('asin'))
    except:
        pass
    try:
        if json_data.get('task_id'):
            sql += " and t.task_id = %s "
            param.append(json_data.get('task_id'))
    except:
        pass
    try:
        if json_data.get('task_status'):
            sql += " and t1.status = %s "
            param.append(json_data.get('task_status'))
    except:
        pass
    sql += " order by t1.status desc,t1.user_id desc,t.id desc"
    asin_list = mp.fetch_all(sql, param)
    res_json = {"code": "0000", "list": asin_list}
    return jsonify(res_json)
def updatePassword():
    data = request.get_data()
    json_data = []
    if data:
        json_data = json.loads(data.decode("utf-8"))
    mp = MysqlPool()
    find_sql = "select * from tb_user where password=%s and id=%s"
    find_param = [
        pyUtils.getMd5(json_data.get('old_psw')),
        session.get('user')['id']
    ]
    find_req = mp.fetch_all(find_sql, find_param)
    if len(find_req) == 1:
        sql = "update tb_user set password=%s where id=%s"
        param = [
            pyUtils.getMd5(json_data.get('new_psw')),
            session.get('user')['id']
        ]
        mp.update(sql, param)
        res_json = {"code": "0000", "msg": "修改成功"}
    else:
        res_json = {"code": "9999", "msg": "修改失败,原密码错误"}
    return jsonify(res_json)
Example #26
0
def getGroupData():
    data = request.get_data()
    json_data = []
    if data:
        json_data = json.loads(data.decode("utf-8"))
    mp = MysqlPool()
    sql = "select * from tb_group where 1=1 "
    param = []
    try:
        if json_data.get('type'):
            sql += "and type=%s "
            param.append(json_data.get('type'))
    except:
        pass
    try:
        if json_data.get('name'):
            name = '%' + str(json_data.get('name')) + '%'
            sql += " and name like %s "
            param.append(name)
    except:
        pass
    try:
        if json_data.get('bigNum'):
            sql += " and nums < %s "
            param.append(json_data.get('bigNum'))
    except:
        pass
    try:
        if json_data.get('smallNum'):
            sql += " and nums > %s "
            param.append(json_data.get('smallNum'))
    except:
        pass
    sql += "order by nums desc"
    group_list = mp.fetch_all(sql, param)
    res_json = {"code": "0000", "list": group_list}
    return jsonify(res_json)
Example #27
0
def init():
    global mysql_pool, mongo_cn
    conf = pyetc.load(os.path.join(ROOT, 'conf', 'setting.conf'))

    # 获取数据库
    dbconf = {'mysql': conf.mysql, 'mongo': conf.mongo}

    try:
        mysql_pool = MysqlPool.Mysql(dbconf, log)
    except BaseException as e:
        log.error(u'init mysql pool exception.')
        log.error(traceback.format_exc())
        sys.exit(1)

    try:
        mongo_cn = MongoPool.Mongo(dbconf, log)
        mongo_cn.init()
    except BaseException as e:
        log.error(traceback.format_exc())
        sys.exit(1)
def reviewForm():
    mp = MysqlPool()
    if request.method == 'GET':
        user = session.get('user')
        user_sql = "select * from tb_user where status=1"
        user_list = None
        if user['level'] == 1:
            user_list = mp.fetch_all(user_sql, None)
        return render_template("review/review-form.html",
                               user=user,
                               user_list=user_list,
                               active="reviewForm")
    if request.method == 'POST':
        data = request.get_data()
        json_data = json.loads(data.decode("utf-8"))
        sql = "insert into tb_review_task(user_id,asin,brand,country,img,keyword,kw_page,store," \
              "price,days_order,total_order,is_vp,note,add_time,name) values(%s,%s,%s,'us',%s,%s," \
              "%s,%s,%s,%s,%s,1,%s,now(),%s)"
        try:
            user_id = json_data.get("user_id")
        except:
            user_id = session.get('user')['id']
        if not user_id:
            user_id = session.get('user')['id']
        param = [
            user_id,
            json_data.get("asin"),
            json_data.get("brand"),
            json_data.get("img"),
            json_data.get("keyword"),
            json_data.get("kw_page"),
            json_data.get("store"),
            json_data.get("price"),
            json_data.get("days_order"),
            json_data.get("total_order"),
            json_data.get("note"),
            json_data.get("name")
        ]
        try:
            task_id = mp.insert(sql, param)
            asin_sql = "insert into tb_task_asin(asin,task_id,status,is_put) values(%s,%s,%s,%s)"
            for asin in str(json_data.get("asin")).split("|"):
                asin_param = [asin, task_id, 1, 0]
                mp.insert(asin_sql, asin_param)
            res_json = {"code": "0000", "message": "已成功提交刷单任务"}
        except Exception as e:
            res_json = {"code": "9999", "message": "提交失败%s" % e}
        return jsonify(res_json)
Example #29
0
            traceback.print_exc()
            all_log.logger.error("---采集报错%s---" % e)
            total_list.pop(0)
            if driver is not None:
                driver.close()
                driver.quit()


def filterAsinForStr(asin_href):
    return re.findall("product-reviews/(.*)/ref", asin_href)[0]


def filter_str(desstr, restr=''):
    # 过滤除中英文及数字及英文标点以外的其他字符
    res = re.compile(
        "[^\u4e00-\u9fa5^. !//_,$&%^*()<>+\"'?@#-|:~{}+|—^a-z^A-Z^0-9]")
    return res.sub(restr, desstr)


def getRank(driver, spanNum):
    rank_txt = driver.find_element_by_xpath(
        '//th[contains(text(),"Best Sellers Rank")]/following-sibling::td/span/span[%s]'
        % spanNum).get_attribute('innerText')
    return rank_txt


if __name__ == "__main__":
    mp = MysqlPool()
    # findAsinByFilterTemp()
    getDataByAsin()
Example #30
0
def insetData(sql,param):
    mp = MysqlPool()
    mp.insertMany(sql, param)