Esempio n. 1
0
    def GetDetails(self, url, muti):
        resp = self.session.get(url)
        resp.encoding = "utf8"
        if not self.CheckIfNeedLogin(resp):
            return
        jqdata = jq(resp.text)
        jqdetail = jqdata(".v_table_1")
        jqperson = jqdata(".v_table_2")

        try:
            uid = FixNums(jqperson("tr:nth-child(5) > td:nth-child(2)").text())
            sid = FixNums(jqdetail("tr:nth-child(3) > td:nth-child(2)").text())
            details = DarkNet_DataSale.select().where((DarkNet_DataSale.sid == sid))
            person = DarkNet_Saler.select().where((DarkNet_Saler.uid == uid))
            notice = DarkNet_Notice.select().where((DarkNet_Notice.sid == sid))
            img = DarkNet_IMGS.select().where((DarkNet_IMGS.sid == sid))
            personDatas = {
                "salenums": FixNums(
                    jqperson("tr:nth-child(3) > td:nth-child(4)").text()
                ),
                "totalsales": float_format(
                    jqperson("tr:nth-child(5) > td:nth-child(4)").text()
                ),
                "totalbuys": float_format(
                    jqperson("tr:nth-child(7) > td:nth-child(4)").text()
                ),
            }
            username = jqperson("tr:nth-child(3) > td:nth-child(2)").text()
            if not person:
                personDatas.update(
                    {
                        "uid": uid,
                        "user": username,
                        "regtime": moment.date(jqperson("tr:nth-child(7) > td:nth-child(2)").text()).format("YYYY-MM-DD"),
                    }
                )
                person = DarkNet_Saler.create(**personDatas)
            else:
                DarkNet_Saler.update(personDatas).where(
                    (DarkNet_Saler.uid == uid)
                ).execute()
                person = person[0].uid

            if not notice:
                notice = DarkNet_Notice.create(**{"sid": sid})
            else:
                notice = notice[0].sid

            detailImages = None
            detailContent = " ".join(jqdata(".postbody .content").text().split())
            if not img:
                urls = [_.attr("src") for _ in jqdata(".postbody img").items()]
                img = DarkNet_IMGS.create(
                    **{"sid": sid, "img": urls, "detail": detailContent}
                )
                detailImages = self.SavePics(urls, sid)
            else:
                img = img[0].sid

            currentYear = moment.now().year
            soldNum = FixNums(
                jqdetail("tr:nth-child(7) > td:nth-child(4)").text(), to=99999
            )
            toCurrentYearDateTime = moment.date(
                f"{currentYear} " + jqdetail("tr:nth-child(3) > td:nth-child(6)").text()
            )
            RealUpTimeJQ = jqdata(".author")
            RealUpTimeJQ.remove("a")
            RealUpTimeJQ.remove("span")

            RealUpTime = moment.date(
                RealUpTimeJQ.text().replace("年", "").replace("月", "").replace("日", "")
            )
            RealUpTime = RealUpTime if RealUpTime._date else toCurrentYearDateTime
            detailsDatas = {
                "lasttime": moment.date(
                    f"{currentYear} "
                    + jqdetail("tr:nth-child(7) > td:nth-child(6)").text()
                ).format("YYYY-MM-DD HH:mm:ss"),
                "priceBTC": float_format(
                    jqdetail("tr:nth-child(3) > td:nth-child(4) > span").text()
                ),
                "priceUSDT": float_format(
                    jqdetail("tr:nth-child(5) > td:nth-child(4)").text().split()[0]
                ),
                "lines": muti["lines"],
                "uptime": RealUpTime.format("YYYY-MM-DD HH:mm:ss"),
                "hot": muti["hot"],
                "types": jqdetail("tr:nth-child(5) > td:nth-child(2)").text(),
                "status": jqdetail("tr:nth-child(7) > td:nth-child(2)").text(),
                "oversell": jqdetail("tr:nth-child(9) > td:nth-child(2)").text(),
                "sold": soldNum,
            }

            if not details:
                detailsDatas.update(
                    {
                        "sid": sid,
                        "user": person,
                        "area": muti["area"],
                        "title": muti["title"],
                        "detailurl": url,
                        "img": img,
                        "notice": notice,
                    }
                )
                details = DarkNet_DataSale.create(**detailsDatas)
                self.MakeMsg(details, detailContent, detailImages, sid, username)
            else:
                self.warn(f'-{RealUpTime}- {muti["title"]}')
                DarkNet_DataSale.update(detailsDatas).where(
                    (DarkNet_DataSale.sid == sid)
                ).execute()

        except Exception as e:
            self.error(f"GetDetails {e}")
            self.SaveError("error_264.html", resp)
            # self.error(jqdata.text())
            raise
Esempio n. 2
0
 def create_details(datas):
     return DarkNet_DataSale.create(**datas)