예제 #1
0
파일: HDH.py 프로젝트: AaronGeist/Llama
    def say_thank(self, id):
        site = self.generate_site()
        assert self.login(site)

        url = "http://hdhome.org/thanks.php"

        form_data = {"id": id}
        HttpUtils.post(url,
                       data=form_data,
                       headers=self.site.login_headers,
                       returnRaw=True)
        print("Say thanks to " + str(id))
예제 #2
0
파일: login.py 프로젝트: AaronGeist/Llama
    def login(self, site):
        if not self.isLogin and site.login_needed and not self.check_login(site):
            if site.need_captcha:
                site.login_captcha_value = self.parse_captcha(site)

            # trigger login action
            HttpUtils.post(site.login_page, data=self.build_post_data(site),
                           headers=site.login_headers, returnRaw=True)

            self.isLogin = self.check_login(site)
            return self.isLogin
        else:
            self.isLogin = True
            return True
예제 #3
0
 def check_login(self, site):
     resp = HttpUtils.post(site.home_page, data={}, returnRaw=True).text
     jsonValue = json.loads(resp)
     if jsonValue['errNo'] == 0:
         content = jsonValue['data']['name']
         return content is not None and content == site.login_verify_str
     else:
         return False
예제 #4
0
    def init_setting(self):
        self.login_if_not()

        # enable adult torrent
        setting_url = "https://kp.m-team.cc/usercp.php"
        lab_data = {
            "action": "laboratory",
            "type": "save",
            "laboratory_adult_mode": "0",
            "laboratory_torrent_page_https": "0"
        }
        res = HttpUtils.post(url=setting_url,
                             data=lab_data,
                             headers=self.site.login_headers,
                             returnRaw=True)
        assert res.status_code == 200

        # do not show picture
        tracker_data = {
            "action": "tracker",
            "type": "save",
            "t_look": "1",  # show pic
            "tooltip": "off",
            "timetype": "timealive",
            "appendsticky": "yes",
            "radio": "icon",
            "smalldescr": "yes",
            "dlicon": "yes",
            "bmicon": "yes",
            "show_hot": "yes",
            "showfb": "yes",
            "showdescription": "yes",
            "showimdb": "yes",
            "showcomment": "yes",
            "appendnew": "yes",
            "appendpicked": "yes",
            "showcomnum": "yes"
        }
        res = HttpUtils.post(url=setting_url,
                             data=tracker_data,
                             headers=self.site.login_headers,
                             returnRaw=True)
        assert res.status_code == 200
예제 #5
0
    def send_msg(self, user_id, subject, body):
        if self.cache.get(self.msg_bucket_name + str(user_id)) is not None:
            print("Skip sending msg, user in cache: " + str(user_id))
            return

        self.login_if_not()

        url = "https://kp.m-team.cc/takemessage.php"
        data = {
            "receiver": user_id,
            "subject": subject,
            "body": body,
            "save": "yes"
        }

        HttpUtils.post(url=url, data=data, headers=self.site.login_headers)
        print(">>>>>>>>> Send msg to {0}, subject={1}, body={2} >>>>>>>>>>".
              format(user_id, subject, body))

        self.cache.set_with_expire(self.msg_bucket_name + str(user_id), "",
                                   86400)

        # sleep 30 ~ 120 seconds before sending next message
        time.sleep(round(30 + random.random() * 90))
예제 #6
0
    def download_seed_file(self, seed_id):
        self.login_if_not()

        data = {
            "id": seed_id,
            "type": "ratio",
            "hidenotice": "1",
            "letmedown": "ratio"
        }
        res = HttpUtils.post("https://kp.m-team.cc/downloadnotice.php?",
                             data=data,
                             headers=self.site.login_headers,
                             returnRaw=True)
        try:
            with open("%s.torrent" % seed_id, "wb") as f:
                f.write(res.content)
        except Exception as e:
            print("Cannot download seed file: " + seed_id, e)
예제 #7
0
파일: putao.py 프로젝트: AaronGeist/Llama
    def exchange_mp(self, times=1):
        site = self.generate_site()
        assert self.login(site)

        data = dict()
        data['option'] = 3  # 1=1GB 2=5GB 3=10GB
        data['art'] = "traffic"

        with ThreadPoolExecutor(max_workers=times) as executor:
            {
                executor.submit(
                    HttpUtils.post(
                        "https://pt.sjtu.edu.cn/mybonus.php?action=exchange",
                        data=data,
                        headers=site.login_headers,
                        returnRaw=True)): item
                for item in range(1, times + 1)
            }
예제 #8
0
파일: putao.py 프로젝트: AaronGeist/Llama
    def login(self, site):
        if not self.isLogin and site.login_needed and not self.check_login(
                site):

            soup_obj = HttpUtils.get("https://pt.sjtu.edu.cn/login.php",
                                     headers=site.login_headers)

            # parse captcha image and return result
            image_url = "https://pt.sjtu.edu.cn/" + soup_obj.select(
                "form img")[0]["src"]
            HttpUtils.download_file(image_url, "/tmp/cap.png", over_write=True)
            site.check_code = PuTaoCaptchaParser.analyze("/tmp/cap.png")

            resp = HttpUtils.post(site.login_page,
                                  data=self.build_post_data(site),
                                  headers=site.login_headers,
                                  returnRaw=True)

            self.isLogin = self.check_login(site)
            return self.isLogin
        else:
            self.isLogin = True
            return True
예제 #9
0
    def water(self):
        self.check_in()

        url_prefix = "http://www.miui.com/forum.php?mod=forumdisplay&fid=5&orderby=dateline&filter=author&orderby=dateline&page="
        page = 1
        cnt = 1
        max_cnt = 50
        chinese_char = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"]

        id_list = []
        while True:
            soup_obj = HttpUtils.get(url_prefix + str(page))
            print("new page: " + str(page))
            id_list.extend(HttpUtils.get_attrs(soup_obj, "tbody", "id"))

            page += 1

            if len(id_list) > max_cnt:
                break

        id_list = id_list[:max_cnt]
        for id in id_list:
            if not id.startswith("normalthread"):
                continue

            id = id[13:]
            page_url = self.page_url_template.format(id)

            page_soup_obj = HttpUtils.get(page_url)
            assert page_soup_obj is not None

            i = str(cnt)
            length = len(i)
            num = ""
            for index in range(length):
                num += chinese_char[int(i[index])]

            id_num = ""
            for index in range(len(id)):
                id_num += chinese_char[int(id[index])]

            random_id = str(int(random() * 1000000000000000))
            chinese_char = ["零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"]

            random_id_num = ""
            for index in range(len(random_id)):
                random_id_num += chinese_char[int(random_id[index])]

            title = HttpUtils.get_content(page_soup_obj,
                                          "title").strip().replace(
                                              "_灌者为王_MIUI论坛", "")

            message = "时间{0},帖子ID{1},标题\"{2}\",随机数{3},第{4}个积分,打扰".format(
                time.strftime("%b %d %Y %H:%M:%S", time.localtime()), id_num,
                title, random_id_num, num)
            # form_hash = page_soup_obj.select("input[name='formhash']")[0]["value"]
            post_data = dict()
            post_data["posttime"] = str(int(time.time()))
            post_data["formhash"] = self.form_hash_mirror
            post_data["usesig"] = "1"
            post_data["subject"] = "  "
            post_data["message"] = message

            form_submit_url = "http://www.miui.com/forum.php?mod=post&action=reply&fid=5&tid={0}&extra=page=1&replysubmit=yes&infloat=yes&handlekey=fastpost".format(
                id)

            # print(post_data)

            post_result = HttpUtils.post(form_submit_url,
                                         headers=self.site.login_headers,
                                         data=post_data,
                                         returnRaw=False)
            assert post_result is not None
            time.sleep(int(random() * 60) + 90)
            cnt += 1
예제 #10
0
    def vote(self):
        self.check_in()

        source_list_url_template = "http://www.miui.com/home.php?mod=space&uid=133153462&do=thread&view=me&order=dateline&from=space&page={0}"
        page_num = 1
        max_cnt = 10
        cnt = 0
        stop_flag = False
        while not stop_flag:
            soup = HttpUtils.get(source_list_url_template.format(page_num),
                                 headers=self.site.login_headers)
            assert soup is not None

            page_num += 1

            current_score = self.get_score()
            previous_score = current_score

            article_urls = HttpUtils.get_attrs(soup, "div.tl th > a", "href")
            for article_url in article_urls:
                try:
                    article_url = "http://www.miui.com/" + article_url
                    article_soup = HttpUtils.get(
                        article_url, headers=self.site.login_headers)
                    assert article_soup is not None
                    title = HttpUtils.get_content(article_soup, "title")
                    form = article_soup.select("#poll", limit=1)
                    option = article_soup.select("#option_1", limit=1)
                    if form is None or len(form) == 0:
                        continue
                    if option is None or len(option) == 0:
                        continue
                    print(title)

                    # do vote here
                    post_url = "http://www.miui.com/" + HttpUtils.get_attr(
                        article_soup, "#poll", "action") + "&inajax=1"

                    post_data = dict()
                    post_data["pollanswers[]"] = HttpUtils.get_attr(
                        article_soup, "#option_1", "value")
                    post_data["formhash"] = self.form_hash_mirror
                    post_result = HttpUtils.post(
                        post_url,
                        headers=self.site.login_headers,
                        data=post_data,
                        returnRaw=False)
                    assert post_result is not None

                    current_score = self.get_score()
                    print(previous_score)
                    print(current_score)

                    cnt += 1
                    if cnt >= max_cnt or previous_score == current_score:
                        stop_flag = True
                        break

                    previous_score = current_score
                    time.sleep(60)
                except:
                    pass
예제 #11
0
    def zz(self):
        source_url_template = "https://bh.sb/post/category/main/page/{0}/"
        post_url = "http://www.miui.com/forum.php?mod=post&action=newthread&fid=5&extra=&topicsubmit=yes"

        self.check_in()

        max_cnt = 10
        cnt = 0
        page_num = 1
        articles = list()
        stop_flag = False
        while not stop_flag:
            # get article of bhsb
            soup = HttpUtils.get(source_url_template.format(page_num))
            article_urls = HttpUtils.get_attrs(soup, "h2 a", "href")
            page_num += 1

            for article_index in range(len(article_urls)):
                article_url = article_urls[article_index]
                if Cache().get(article_url) is not None:
                    continue

                article_soup = HttpUtils.get(article_url)
                titles = HttpUtils.get_contents(article_soup,
                                                ".article-content p")

                title_cnt = int(len(titles) / 2)

                for title_index in range(0, title_cnt):
                    try:
                        title = titles[title_index * 2].split("】")[1]
                        image = titles[title_index * 2 + 1]

                        if type(image) != Tag:
                            continue

                        src = image.attrs["src"]
                        if src.endswith("jpg"):
                            continue

                        message = "好玩您就点个赞,不好笑请期待下一贴~\n"
                        message += "[img]{0}[/img]".format(src)

                        if Cache().get(title) is not None:
                            continue
                        Cache().set(title, message)

                        articles.append((title, message))

                        cnt += 1

                        if cnt >= max_cnt:
                            stop_flag = True
                            break
                    except:
                        pass

                if stop_flag:
                    break

                # only if all articles are included, then mark this url
                Cache().set(article_url, article_url)

        type_id_list = ["1629", "1631", "1633", "4481", "1641"]
        type_index = 0
        for (title, message) in articles:
            print((title, message))

            post_data = dict()
            post_data["posttime"] = str(int(time.time()))
            post_data["formhash"] = self.form_hash_mirror
            post_data["wysiwyg"] = "1"
            post_data["typeid"] = type_id_list[type_index]
            post_data["allownoticeauthor"] = "1"
            post_data["addfeed"] = "1"
            post_data["usesig"] = "1"
            post_data["save"] = ""
            post_data["uploadalbum"] = "-2"
            post_data["newalbum"] = "请输入相册名称"
            post_data["subject"] = title
            post_data["message"] = message

            post_result = HttpUtils.post(post_url,
                                         headers=self.site.login_headers,
                                         data=post_data,
                                         returnRaw=False)
            assert post_result is not None
            type_index = (type_index + 1) % len(type_id_list)
            time.sleep(int(random() * 300) + 2700)
예제 #12
0
    def zz_copy(self):
        source_url_template = "http://www.miui.com/forum.php?mod=forumdisplay&fid=773&orderby=dateline&filter=author&orderby=dateline&page={0}"
        thread_url_template = "http://www.miui.com/thread-{0}-1-1.html"
        post_url = "http://www.miui.com/forum.php?mod=post&action=newthread&fid=773&extra=&topicsubmit=yes"
        min_page_num = 300

        self.check_in()

        title_white_list = ["问题", "探索版", "怎么", "什么"]
        title_black_list = ["内测", "发货", "积分", "在线"]

        page_num = min_page_num + int(random() * 700)
        max_cnt = 20
        article_candidates = dict()
        stop_flag = False
        while not stop_flag:
            try:
                soup_obj = HttpUtils.get(source_url_template.format(page_num))
                page_num -= 1
                assert soup_obj is not None
                print("current page: " + str(page_num))

                article_list = soup_obj.select("tbody")

                for article in article_list:
                    id = article.attrs["id"]
                    if not id.startswith("normalthread"):
                        continue

                    id = id[13:]

                    if Cache().get("ZZ_" + id) is not None:
                        print("Skip " + id)
                        # has been ZZed within a few days, skip
                        continue

                    title = HttpUtils.get_content(
                        article, ".sub-tit > a:nth-of-type(1)")
                    reply_num = int(
                        HttpUtils.get_content(
                            article, "span.number_d a:nth-of-type(1)"))

                    if reply_num > 8:
                        continue

                    is_white_list = False
                    for white_list in title_white_list:
                        if white_list in title:
                            is_white_list = True

                    if not is_white_list:
                        break

                    is_black_list = False
                    for black_list in title_black_list:
                        if black_list in title:
                            is_black_list = True

                    if is_black_list:
                        break

                    thread_soup_obj = HttpUtils.get(
                        thread_url_template.format(id))
                    assert thread_soup_obj is not None
                    content = HttpUtils.get_content(thread_soup_obj,
                                                    "#postlist > div .t_f")

                    if content is None or content.strip() == "":
                        continue

                    article_candidates[id] = (title, content.strip())

                    if len(article_candidates) >= max_cnt:
                        stop_flag = True
                        break
            except:
                pass

        for id in article_candidates:
            try:
                (title, message) = article_candidates[id]

                post_data = dict()
                post_data["posttime"] = str(int(time.time()))
                post_data["formhash"] = self.form_hash_mirror
                post_data["wysiwyg"] = "1"
                post_data["typeid"] = "7562"
                post_data["allownoticeauthor"] = "1"
                post_data["addfeed"] = "1"
                post_data["usesig"] = "1"
                post_data["save"] = ""
                post_data["uploadalbum"] = "-2"
                post_data["newalbum"] = "请输入相册名称"
                post_data["subject"] = title
                post_data["message"] = message

                print((title, message))

                post_result = HttpUtils.post(post_url,
                                             headers=self.site.login_headers,
                                             data=post_data,
                                             returnRaw=False)
                assert post_result is not None

                Cache().put("ZZ_" + id)

                time.sleep(int(random() * 300) + 1800)
            except:
                pass
예제 #13
0
    def water_copy(self):
        self.check_in()

        forum_id_list = ["772", "773"]
        forum_id = forum_id_list[int(random() * len(forum_id_list)) - 1]
        article_url_template = "http://www.miui.com/forum.php?mod=forumdisplay&fid={0}&orderby=replies&filter=reply&orderby=replies&page={1}"
        page_num = 1
        max_cnt = 50

        reply_list = dict()
        stop_flag = False
        while not stop_flag:
            soup_obj = HttpUtils.get(
                article_url_template.format(forum_id, page_num))
            print("current page: " + str(page_num))
            page_num += 1

            article_list = soup_obj.select("tbody")

            for article in article_list:
                id = article.attrs["id"]
                if not id.startswith("normalthread"):
                    continue

                id = id[13:]

                if Cache().get(id) is not None:
                    print("Skip " + id)
                    # has been replied within a few days, skip
                    continue

                title = HttpUtils.get_content(article,
                                              ".sub-tit > a:nth-of-type(1)")
                # don't want to copy comments of author
                author = HttpUtils.get_content(article,
                                               ".sub-infos a:nth-of-type(1)")
                reply_num = HttpUtils.get_content(
                    article, "span.number_d a:nth-of-type(1)")

                total_thread_page_num = int(int(reply_num) / 10)
                start_thread_page_num = int(total_thread_page_num / 3)
                end_thread_page_num = start_thread_page_num * 2
                current_thread_page_num = start_thread_page_num + int(
                    random() * 3)

                content_candidates = list()

                while len(
                        content_candidates
                ) == 0 and current_thread_page_num <= end_thread_page_num:
                    page_url = self.page_url_template_copy.format(
                        id, current_thread_page_num)
                    current_thread_page_num += 1
                    page_soup_obj = HttpUtils.get(
                        page_url, headers=self.site.login_headers)
                    assert page_soup_obj is not None

                    # check if allow to reply
                    edit_content = HttpUtils.get_content(
                        page_soup_obj, "#fastposteditor .pt")
                    if edit_content is not None and "您现在无权发帖" in str(
                            edit_content):
                        Cache().set(id, "")
                        print(id + " not allowed to reply")
                        break

                    # skip vote(less score)
                    form = page_soup_obj.select("#poll", limit=1)
                    if form is not None and len(form) > 0:
                        Cache().set(id, "")
                        print(id + " skip vote")
                        break

                    post_list = page_soup_obj.select("#postlist > div")
                    for post in post_list:
                        try:
                            current_author = HttpUtils.get_content(
                                post, ".authi a")
                            if current_author == author:
                                continue

                            score = int(
                                HttpUtils.get_content(post, ".pil dd a"))
                            if score < 1500:
                                continue

                            content = HttpUtils.get_content(
                                post, ".pct table tr td.t_f")
                            if content is None or content.strip(
                            ) == "" or len(content) < 10 or len(content) > 50:
                                continue

                            if author in content:
                                continue

                            contain_black_list = False
                            for black_word in self.comments_black_list:
                                if black_word in content:
                                    contain_black_list = True
                                    break

                            if contain_black_list:
                                continue

                            content_candidates.append(content.strip())
                        except:
                            pass

                print(title)
                print(content_candidates)
                if len(content_candidates) > 0:
                    # randomly pick one
                    reply_list[id] = content_candidates[
                        int(random() * len(content_candidates)) - 1]
                    print(id + " -- " + reply_list[id])

                print("current reply=" + str(len(reply_list)))
                if len(reply_list) >= max_cnt:
                    stop_flag = True
                    break

        # start reply
        for thread_id in reply_list:
            try:
                message = reply_list[thread_id]
                post_data = dict()
                post_data["posttime"] = str(int(time.time()))
                post_data["formhash"] = self.form_hash_mirror
                post_data["usesig"] = "1"
                post_data["subject"] = "  "
                post_data["message"] = message

                form_submit_url = "http://www.miui.com/forum.php?mod=post&action=reply&fid={0}&tid={1}&extra=page=1&replysubmit=yes&infloat=yes&handlekey=fastpost".format(
                    forum_id, thread_id)
                print(thread_id, message, self.get_score())

                post_result = HttpUtils.post(form_submit_url,
                                             headers=self.site.login_headers,
                                             data=post_data,
                                             returnRaw=False)
                assert post_result is not None
                Cache().set_with_expire(thread_id, message, 86400 * 4)
                time.sleep(int(random() * 60) + 90)
            except:
                pass