Example #1
0
def report_mail():
    trans = {
        "YJ": "玉佳电子",
        "YK": "玉佳企业店",
        "KY": "开源电子",
        "TB": "赛宝电子",
        "report": "报告",
        "insert.txt": "添加",
        "delete.txt": "删除",
        "empty.txt": "空编码",
        "repeat.txt": "重复编码",
    }

    filenames = os.listdir("reports")
    for file in filenames:
        txt = re.search("txt", file)
        if txt:
            with open("reports/" + file, "r") as file_obj:
                a = file_obj.read()
                if a:
                    x = file.split("_")
                    title = trans[x[1]] + trans[x[2]] + trans[x[0]]
                    content = a
                    mail_receiver = my_user.copy()
                    mail_receiver.append(STORE_INFO[x[1]]['manager_mail'])
                    mail(title, content, mail_receiver)
            with open("reports/" + file, "w") as file_obj:
                pass  # 清除文件内容
Example #2
0
def Verify():
    l_orderNo = []
    column_name = [
        'orderNo', 'deliverFee', 'actualFee', 'couponPrice', 'fromStore',
        'orderStatus'
    ]
    condition = {'isVerify': '0', 'isDetaildown': '1'}
    # kwargs = {'isVerify': '2', 'isDetaildown': '1'}
    result = mysql.get_data(t="tb_order_spider", cn=column_name, c=condition)
    if result:
        for i in result:
            total = 0
            orderNo = i[0]
            deliverFee = i[1]
            actualFee = i[2]
            couponPrice = i[3]
            fromStore = i[4]
            column_name = ['unitPrice', 'sellNum', 'unitBenefits']
            condition = {'orderNo': orderNo}
            result2 = mysql.get_data(t="tb_order_detail_spider",
                                     cn=column_name,
                                     c=condition)
            for j in result2:
                unitPrice = j[0]
                sellNum = j[1]
                unitBenefits = j[2]
                total = total + unitPrice * sellNum - unitBenefits
            a = round(total, 3) + deliverFee - actualFee - couponPrice
            if int(a) != 0 and i[5] != '交易关闭':
                list_tmp = []
                list_tmp.append(str(round(total, 2)))
                list_tmp.append(str(deliverFee))
                list_tmp.append(str(actualFee))
                list_tmp.append(str(couponPrice))
                list_tmp.append(str(round(a, 2)))
                list_tmp.append(store_trans(fromStore))
                list_tmp.append(orderNo)
                l_orderNo.append("|".join(list_tmp))
                mysql.update_data(t="tb_order_spider",
                                  set={'isVerify': 2},
                                  c={'orderNo': orderNo})
            else:
                mysql.update_data(t="tb_order_spider",
                                  set={'isVerify': 1},
                                  c={'orderNo': orderNo})
                # print('没有异常数据,验证完成!')
    if l_orderNo:
        s = "\n".join(l_orderNo)
        # print(s)
        mail("数据异常报告", s, ["*****@*****.**"])
    taobao_check()
Example #3
0
    def on_post(self, req, resp):
        """
        Handle a forgotpassword POST request.

        Arguments:
            req: the request
            resp: the response

        Returns:
            None

        The method expects its input as www-formencoded parameters in the request body.

        On success it will create a password reset request and send an email with a confirmation link.

        On failure it will do nothing.

        It will always set the `Location` header to :attr:`LOGINSCREEN`.

        It will always set the response status to ;attr:`falcon.HTTP_303`.

        Other Parameters:
            email: the username of the user (a valid email address)
            login: the literal text `Forgot`

        Typically these parameters would correspond to input fields in an
        HTML form and a submit button with a `name=Forgot` attribute and
        send as input parameters in the body of the request.
        """
        logger.info('ForgotPasswordResource')
        global DBSession
        session = DBSession()
        # we always send the same response, no matter if the user exists or not
        resp.status = falcon.HTTP_303
        resp.location = f"{LOGINSCREEN}?checkemail"

        params = req.params
        if not login_forgot_params.check(params):
            logger.info('unauthorized, login forgot params do not have proper format')
        else:
            with timing_equalizer(3.0):
                email = params['email'].lower()
                user = session.query(User).filter(User.email == email).first()

                user = session.query(User).filter(User.email == email).first()
                if not user:  # no user found but we are not providing this information
                    logger.info(f"no user found {email}")
                else:
                    logger.info(f"password reset request received for existing user {email}")
                    pr = PasswordReset(id=guid().hex, userid=user.id)
                    session.add(pr)
                    session.commit()
                    logger.info(f"sending confirmation mail to {user.email} ({user.name})")
                    logger.info(f"reset confirmation id: {pr.id}")
                    u, p, s = fetch_smtp_params()
                    if mail(EMAILTEMPLATE_FORGOTPASSWORD.format(name=user.name, website=WEBSITE, link=f"{RESETPASSWORD}?confirmationid={pr.id}"), "Password change request", fromaddr=u, toaddr=user.email, smtp=s, username=u, password=p):
                        logger.success('mail successfully sent')
                    else:
                        logger.error('mail not sent')
Example #4
0
    def reports_mail(self):
        # results = self.sql_element.select_dict("""select * from spider_reports
        # where reports_date='%s'
        # """ % (str(datetime.date.today())))
        # string = ""
        # for result in results:
        #     if result['reports_type'] == '订单爬虫报告':
        #         string += str(result['reports_date']) + " "
        #         string += result['store_name'] + " " + result['reports_type'] + ":\n"
        #         string += "今日共爬取新订单数:" + str(result['count']) + " 条\n"
        #         string += "订单总金额:" + str(result['price']) + " 元\n"
        #     elif result['reports_type'] == '优惠差额报告':
        #         string += str(result['reports_date']) + " "
        #         string += result['store_name'] + " " + result['reports_type'] + ":\n"
        #         string += "今日导入修正订单优惠价格数量:" + str(result['count']) + " 条\n"
        #         string += "总优惠金额:" + str(result['price']) + " 元\n"
        # print(result)
        # print(string)

        # mail('订单爬虫报告', string, ['*****@*****.**', '*****@*****.**'])
        mail('订单爬虫报告', "abc", ['*****@*****.**'])
Example #5
0
    async def parse(self, data):
        if data != "q":
            for i in range(len(data)):
                self.item = {}
                self.item = self.common.copy()
                self.item['stockid'] = re.search(
                    "编码:(.*)",
                    data[i]['itemDesc']['desc'][1]['text']).group(1).upper()
                self.item['link_id'] = data[i]['itemId']
                self.item['attribute'] = ""
                self.item['flag'] = "update"
                self.item['typeabbrev'] = self.fromStore
                self.item['shop_id'] = self.shop_id(self.fromStore)
                self.item['SpiderDate'] = time_now()
                temp_des = data[i]['itemDesc']['desc'][0]['text']
                self.item['description'] = temp_des.replace("(", "(").replace(
                    ")", ")")
                self.item['price_tb'] = re.findall(
                    "(\d+.?\d*)", data[i]["managerPrice"]['currentPrice'])[0]
                self.item['promotionprice'] = self.promo_price.get(
                    self.item['link_id'])
                # print(self.promo_price)

                sql = "select spe_link from prices_tb_fix where link_id='%s' and server='%s'" % (
                    self.item['link_id'], self.sn)
                spe_link_id = mysql.get_data(db=self.db_test,
                                             sql=sql,
                                             return_one=True)
                isMut = re.search("^MUT\D*", self.item['stockid'])

                if isMut or spe_link_id:
                    await self.page.setRequestInterception(True)
                    self.page.on('request', self.intercept_request)
                    self.page.on('response', self.intercept_response)
                    await asyncio.sleep(1)
                    net_check()
                    await self.page.click(
                        ".next-table-row td:nth-child(2) div.product-desc-hasImg span:nth-child(2) i"
                    )
                    await asyncio.sleep(1)
                    await self.page.keyboard.press('Escape')
                else:
                    # print(self.item)
                    if self.item['promotionprice'] is None:
                        mail("price_tb_error",
                             self.fromStore + ":" + self.item['link_id'],
                             ["*****@*****.**"])
                        logger.error("error:" + self.fromStore + " : " +
                                     self.item['link_id'] + " and " +
                                     mysql.concat(self.promo_price, "="))
                        self.complete = 2
                        break
                    condition = {
                        "stockid": self.item['stockid'],
                        "link_id": self.item['link_id'],
                        "shop_id": self.item['shop_id'],
                    }
                    res = mysql.get_data(t="prices_tb",
                                         l=1,
                                         cn=["id"],
                                         c=condition,
                                         db=self.target_server)
                    if res:
                        self.item['ratio'] = round(
                            float(self.item['price_tb']) / float(res[0][0]), 2)
                        print(self.item)
                        mysql.update_data(t="prices_tb",
                                          set=self.item,
                                          c=condition,
                                          db=self.target_server)
                    else:
                        insert_item = self.item.copy()
                        insert_item["currabrev"] = "CNY"
                        insert_item["price_erp"] = 0
                        insert_item["operator"] = self.operator
                        insert_item["last_time"] = time_now()
                        if self.operator == "爬虫维护":
                            insert_item["flag"] = "create"
                        else:
                            insert_item['flag'] = "add"
                        insert_item["ratio"] = 1
                        insert_item["package_number"] = 1
                        insert_item["Checker"] = ""
                        insert_item["CheckDate"] = "0000-00-00 00:00:00"
                        print(insert_item)

                        with open(
                                "reports/report_" + self.fromStore +
                                "_insert.txt", "a") as file:
                            file.writelines("物料编码:" + insert_item['stockid'] +
                                            " 与 商品ID:" +
                                            insert_item['link_id'] +
                                            " 为最新匹配,添加至ERP系统。\n" +
                                            self.item_url +
                                            insert_item['link_id'] + "\n" +
                                            self.item_erp_url +
                                            insert_item['link_id'] + "\n\n")

                        mysql.insert_data(t="prices_tb",
                                          d=insert_item,
                                          db=self.target_server)
                    result = mysql.get_data(
                        t="prices_tb",
                        cn=["*"],
                        c={"link_id": self.item['link_id']},
                        db=self.target_server,
                        dict_result=True)

                    if len(result) > 1:
                        for r in result:
                            if r['stockid'] != self.item['stockid'] and r[
                                    'flag'] != "del":
                                with open(
                                        "reports/report_" + self.fromStore +
                                        "_delete.txt", "a") as file:
                                    file.writelines("物料编码:" + r['stockid'] +
                                                    " 与 商品ID:" +
                                                    self.item['link_id'] +
                                                    " 不匹配,已被爬虫从ERP系统中删除。\n" +
                                                    self.item_url +
                                                    self.item['link_id'] +
                                                    "\n" + self.item_erp_url +
                                                    self.item['link_id'] +
                                                    "\n\n")

                                mysql.update_data(t="prices_tb",
                                                  c={"id": r['id']},
                                                  db=self.target_server,
                                                  set={"flag": "del"})

                    self.complete = 1
        else:
            pass
            self.complete = 1
Example #6
0
    def on_post(self, req, resp):
        """
        Handle a register POST request.

        Arguments:
            req: the request
            resp: the response

        Returns:
            None

        The method expects its input as www-formencoded parameters in the request body.

        On success it will create a pending user request and send an email with a confirmation link.

        On failure it will do nothing.

        It will always set the `Location` header to :attr:`LOGINSCREEN`.

        It will always set the response status to :attr:`falcon.HTTP_303`.

        Other Parameters:
            email: the username of the user (a valid email address)
            name: the full name of the user
            password: the password ( 8 >= length <= 64, must contain at lease 1 lowercase, 1 uppercase, 1 digit and 1 special char.
            password2: must be identical to the password parameter
            login: the literal text `Register`

        Typically these parameters would correspond to input fields in an
        HTML form and a submit button with a `name=Register` attribute and
        send as input parameters in the body of the request.
        """
        logger.info('RegisterResource')
        global DBSession
        session = DBSession()
        resp.status = "303 Registration pending confirmation, email sent to email address"
        resp.location = f"{LOGINSCREEN}?pending"
        if not login_register_params.check(req.params):
            logger.info('unauthorized, login register params do not have proper format')
        else:
            with timing_equalizer(3.0):
                params = req.params
                # TODO lowercase email everywhere
                email = params['email'].lower()
                user = session.query(User).filter(User.email == email).first()
                # We always return the same response (and redirect) no matter
                # whether the email is in use or not or if anything else is wrong
                # this is to prevent indexing, i.e. checking which email addresses are in use
                if params['password'] != params['password2']:
                    logger.info("passwords are not identical")
                elif user:
                    logger.info(f'email already in use {user.email}')
                else:
                    user = session.query(PendingUser).filter(PendingUser.email == email).first()
                    if user:  # we delete previous pending registration to prevent database overfilling
                        logger.info('previous registration not yet confirmed')
                        session.delete(user)
                        session.commit()
                    else:
                        logger.info('first registration')
                    pu = PendingUser(id=guid().hex, email=email, password=newpassword(params['password']), name=params['name'])
                    session.add(pu)
                    session.commit()
                    # TODO limit number of emails sent to same address
                    user = session.query(PendingUser).filter(PendingUser.email == email).first()
                    logger.info(f"sending confirmation mail to {user.email} ({user.name})")
                    logger.info(f"confirmation id: {pu.id}")
                    u, p, s = fetch_smtp_params()
                    logger.info(f"mailer {u}@{s} (password not shown ...)")
                    if mail(EMAILTEMPLATE_REGISTER.format(name=user.name, website=WEBSITE, link=f"{CONFIRMREGISTRATION}?confirmationid={pu.id}"), "Confirm your registration", fromaddr=u, toaddr=user.email, smtp=s, username=u, password=p):
                        logger.success('mail successfully sent')
                    else:
                        logger.error('mail not sent')