예제 #1
0
    def post(self, *args, **kwargs):
        """
        执行登录
        :param args:
        :param kwargs:
        :return:
        """
        try:
            weibouser_model = WeiboUser()

            account_id = self.get_args("id", "")
            if not account_id:
                self.send_fail_json("account_id不能为空")
                return

            # 获取验证码
            verifycode = self.get_args("verifycode", "")

            # 执行登录
            user = WeiboUser().get_one_specific_fields8id(("id", "username", "pwd", "cookies"), account_id)
            res = Weibo(init_session=False).do_login(user, verifycode)
            # res = do_login(verifycode)
            if not res.get("status"):
                # 登录失败,账号或者密码错误,或者需要验证码
                self.send_fail_json(res.get("reason"), data={"needverify": res.get("needverify")})
                return

            # 登录成功
            data = dict(islogin=True, last_login_time=datetime.now())

            # cookies 入库
            cookies = res.get("cookies", "")
            if cookies:
                data.update(cookies=myjson.dumps(cookies))

            uniqueid = res.get("uniqueid", "")
            if uniqueid:
                data.update(uniqueid=uniqueid)

            userdomain = res.get("userdomain", "")
            if userdomain:
                data.update(userdomain=userdomain)

            weibouser_model.update({"id": account_id}, data)

            write_log("'{}'成功登录了微博(微博ID为:{})".format(self.user["id"], account_id), LOG_TYPE_OPERATE)
            self.send_ok_json("")
        except Exception as ex:
            write_log("{}.{} raise exception, ex={}".format(
                self.__class__.__name__,
                sys._getframe().f_code.co_name,
                repr(ex)
            ))
            self.send_fail_json("系统错误,稍会儿再试")
예제 #2
0
    def get(self, *args, **kwargs):
        """
        加载修改微博账号表单页
        :param args:
        :param kwargs:
        :return:
        """
        # 获取用户
        account_id = self.get_args("id", "")
        if is_empty(account_id):
            self.send_fail_json("用户id不能为空")
            return
        user = WeiboUser().get_one8id(account_id)
        if not user:
            self.send_fail_json("查无用户")
            return
        user = self.tran_rowproxy2variable(user)
        user.pwd = aes_decrypt(user.pwd)

        self.render("weibo/account-add.html", one=user)
예제 #3
0
    def post(self, *args, **kwargs):
        """
        执行修改微博账号
        :param args:
        :param kwargs:
        :return:
        """
        try:
            account_id = self.get_args("account_id", "")
            if is_empty(account_id):
                self.send_fail_json("账号id不能为空")
                return

            # 用户名
            username = self.get_args("username")
            if is_empty(username):
                # 用户名不能为空
                self.send_fail_json("用户名不能为空")
                return

            # 登录密码
            pwd = self.get_args("pwd", "")
            if is_empty(pwd):
                # 密码不能为空
                self.send_fail_json("密码不能为空")
                return
            pwd = aes_encrypt(pwd)

            data = dict(
                username=username,
                pwd=pwd,
                update_time=datetime.now(),
            )

            # 备注
            comments = self.get_args("comments")
            if comments:
                data["comments"] = comments

            res = WeiboUser().update(where={"id": account_id}, data=data)
            if not res:
                self.send_fail_json("修改失败")
                return

            write_log("'{}'修改了一个微博账号(ID为:{})".format(self.user["id"], account_id), LOG_TYPE_OPERATE)
            self.send_ok_json("")
        except Exception as ex:
            write_log("{}.{} raise exception, ex={}".format(
                self.__class__.__name__,
                sys._getframe().f_code.co_name,
                repr(ex)
            ))
            self.send_fail_json("系统错误,稍会儿再试")
예제 #4
0
    def get(self, *args, **kwargs):
        try:
            account_id = self.get_args("id", "")
            if not account_id:
                self.send_fail_json("id不能为空")
                return

            user_model = WeiboUser()
            res = user_model.delete(where={"id": account_id})
            if not res:
                self.send_fail_json("删除失败")
                return

            write_log("'{}'删除了一个微博账号(ID为:{})".format(self.user["id"], account_id), LOG_TYPE_OPERATE)
            self.send_ok_json("")
        except Exception as ex:
            write_log("{}.{} raise exception, ex={}".format(
                self.__class__.__name__,
                sys._getframe().f_code.co_name,
                repr(ex)
            ))
            self.send_fail_json("系统错误,稍会儿再试")
예제 #5
0
def main():
    wb = WeiboUser()
    account_file = "{}/doc/weiboaccount.txt".format(project_path)
    with open(account_file, "r") as conn:

        account_pwd = conn.readline()
        while 1:
            if not account_pwd:
                break
            try:
                temp = account_pwd.split("----")
            except:
                continue

            account = temp[0].strip("-").strip()
            pwd = temp[1].strip("-").strip()
            data = {
                "username": account,
                "pwd": aes_encrypt(pwd),
                "create_time": datetime.datetime.now()
            }
            wb.add(data=data)
            account_pwd = conn.readline()
def main():
    proxy_obj = myproxy.TaiyangProxy()
    weibo_user = WeiboUser()
    generator = weibo_user.get_some_generator()
    for user_list in generator:
        proxy_list = proxy_obj.get_proxies_direct(len(user_list))
        for index, user in enumerate(user_list):
            wb = weibo_login.Weibo(
                user_name=user.username,
                password=myaescrypto.aes_decrypt(user.pwd),
                proxy=proxy_list[index],
            )
            islogin = wb.check_login(user.cookies, user.headers)
            if islogin is None:
                # 异常了,则不做处理
                continue

            if not islogin:
                # 未登录,将登录状态字段改为false
                res = wb.login()
                if res["status"]:
                    # 登录成功
                    data = {
                        "islogin": True,
                        "cookies": res["cookies"],
                        "headers": res["headers"],
                        "uniqueid": res["uniqueid"],
                        "userdomain": res["userdomain"],
                    }
                    WeiboUser().update({"id": user.id}, data)
                else:
                    # 登录失败
                    WeiboUser().update({"id": user.id}, {
                        "islogin": False,
                        "cookies": ""
                    })
예제 #7
0
    def get(self, *args, **kwargs):
        try:
            account_id = self.get_args("id", "")
            if not account_id:
                self.send_fail_json("account_id不能为空")
                return

            user = WeiboUser().get_one_specific_fields8id(("id", "username", "pwd", "cookies"), account_id)

            res = Weibo().load_login_page(user)
            if res["islogin"]:
                # 已登录
                self.send_ok_json("")
            else:
                # 未登录
                self.send_fail_json(data={"needverify": res["needverify"]})
        except Exception as ex:
            write_log("{}.{} raise exception, ex={}".format(
                self.__class__.__name__,
                sys._getframe().f_code.co_name,
                repr(ex)
            ))
            self.send_fail_json("系统错误,稍会儿再试")