Exemplo n.º 1
0
    def create_post(self,
                    board_name,
                    title,
                    content_string,
                    mail_re=True,
                    no_reply=False,
                    signature=None,
                    parent_id: int = None):
        content = get_content_from_raw_string(content_string)
        bid = self._get_board_info(board_name, 'id')

        data = {
            'title': title,
            'content': content,
            'bid': bid,
            'postinfo': self._get_post_info(mail_re, no_reply, parent_id),
        }
        if signature is not None:
            data['signature'] = signature

        action = '回帖' if parent_id else '发帖'
        response_data = self._get_response_data('ajax/create_post', data,
                                                action)
        postid = response_data['result']['postid']
        post_link = self._get_action_url('post-read-single',
                                         bid=bid,
                                         postid=postid)
        print(bold_green(action + '成功!') + '帖子链接:{}'.format(post_link))
        return response_data['result']
Exemplo n.º 2
0
 def forward_mail_to_board(self, to_board_name, postid: int):
     data = {
         "from": "mail",
         "postid": postid,
         "to": "post",
         "tobid": self._get_board_info(to_board_name, 'id'),
     }
     self._get_response_data('ajax/forward', data,
                             '转发邮件到{}版'.format(to_board_name))
     print(bold_green('已成功转发到{}版!'.format(to_board_name)))
Exemplo n.º 3
0
 def operate_post(self, board_name, postid_list, action):
     assert action in self._POST_ACTION_NAME, '无效的帖子操作!'
     data = {
         "bid": self._get_board_info(board_name, 'id'),
         "list": '[{}]'.format(','.join(postid_list)),
         "action": action
     }
     self._get_response_data('ajax/operate_post', data,
                             '{}帖子'.format(self._POST_ACTION_NAME[action]))
     print(bold_green('{}帖子成功!'.format(self._POST_ACTION_NAME[action])))
Exemplo n.º 4
0
 def add_new_collection(self, board_name, path, postid: int):
     data = {
         "from": "post",
         "bid": self._get_board_info(board_name, 'id'),
         "postid": postid,
         "base": path
     }
     response_data = self._get_response_data('ajax/collection_import', data,
                                             '添加精华区文件')
     print(bold_green('添加精华区文件成功!'))
     return response_data['name']
Exemplo n.º 5
0
 def forward_post(self, from_board_name, to_board_name, postid: int):
     data = {
         'from': 'post',
         'bid': self._get_board_info(from_board_name, 'id'),
         'postid': postid,
         'to': 'post',
         'tobid': self._get_board_info(to_board_name, 'id'),
     }
     self._get_response_data('ajax/forward', data,
                             '转帖到{}版'.format(to_board_name))
     print(bold_green('已成功转发到{}版!'.format(to_board_name)))
Exemplo n.º 6
0
 def forward_post(self, from_board_name, to_board_name, postid):
     data = {
         'from': 'post',
         'bid': self._BID_MAP[from_board_name.lower()],
         'postid': postid,
         'to': 'post',
         'tobid': self._BID_MAP[to_board_name.lower()]
     }
     self._get_response_data('ajax/forward', data,
                             '转帖到{}版'.format(to_board_name))
     print(bold_green('已成功转发到{}版!'.format(to_board_name)))
Exemplo n.º 7
0
 def add_new_collection(self, board_name, postid, threadid, path):
     data = {
         "from": "post",
         "bid": self._BID_MAP[board_name.lower()],
         "postid": postid,
         "threadid": threadid,
         "base": path
     }
     response_data = self._get_response_data('ajax/collection_import', data,
                                             '添加精华区文件')
     print(bold_green('添加精华区文件成功!'))
     return response_data['name']
Exemplo n.º 8
0
    def main(self):
        """主过程"""
        print(bold_string("在执行程序之前,请检查各区的帖子标题、格式是否正确,帖子正文里无采编内容外其他信息。"))
        print('标题正确格式:"X@MMDD" / "X@MMDD kong" / "X@MMDD void"')
        print(bold_yellow("注:由于院士代码的限制,当我们找到同一个区的多个帖子时(如有多个8@0328),"
              "我们只保留发表时间最后的主题帖。如果有需要合并多个采编的爆料,请手动修改版上的帖子。"))
        ans = input("按任意键开始爬取帖子~ 【注:若种子文件{}已经生成,请按e跳过该步骤】".format(self._seed_file))
        if not (ans and ans[0] in ['e', 'E']):
            crawler = QJZCrawler(self._bdwm, self._year, self._month, self._day)
            while True:
                print(bold_string(wrap_separate_bar("开始从WMQJZ版爬取帖子:")))
                if crawler.generate_seed_file():
                    break
                print(bold_red("自动爬取帖子失败!请检查各区是否齐全,发帖格式是否正确,后重试~"))
                ans = input("按任意键重新爬取帖子,或输入e退出程序")
                if ans and ans[0] in ['e', 'E']:
                    return
            print(bold_green("爬取帖子完毕!"))

        input("按任意键开始跑院士的脚本~")

        reviewer = None
        while True:
            print(bold_string(wrap_separate_bar('开始跑院士的脚本')))
            try:
                reviewer = editor_main(self._date)
            except Exception:
                print(traceback.format_exc())
                ans = input('院士脚本报错,可能是种子文件格式有误~\n'
                            '请【将种子文件{}修改正确后】输入y重跑脚本;按任意键退出程序:'.format(self._seed_file))
                if ans and ans[0] in ['y', 'Y']:
                    continue
                else:
                    return
            break

        print(bold_string(wrap_separate_bar('院士脚本跑完啦,接下来开始帮你自动发帖')))
        num = input('请选择你要发贴的版面代号 0.WMReview(正式出刊), 1.WMQJZ(给校对看), 2.Test(测试):')
        while num not in {'0', '1', '2'}:
            num = input(bold_red('请输入0,1或2!==>'))
        self._auto_post_pipeline(int(num), reviewer)

        input('按任意键结束~')
Exemplo n.º 9
0
 def edit_post(self,
               board_name,
               postid,
               title,
               content_string,
               signature=None):
     content = get_content_from_raw_string(content_string)
     bid = self._BID_MAP[board_name.lower()]
     data = {
         'title': title,
         'content': content,
         'bid': bid,
         'postid': postid,
         'postinfo': '{}',
     }
     if signature is not None:
         data['signature'] = signature
     self._get_response_data('ajax/edit_post', data, '修改帖子')
     post_link = '{}?bid={}&postid={}'.format(
         self._get_action_url('post-read-single'), bid, postid)
     print(bold_green('修改帖子成功!') + '帖子链接:{}'.format(post_link))
Exemplo n.º 10
0
 def create_collection_dir(self, path, title, bms=''):
     data = {"base": path, "title": title, "bms": bms}
     response_data = self._get_response_data('ajax/create_collection_dir',
                                             data, '创建精华区目录')
     print(bold_green('已创建精华区目录 "{}"'.format(title)))
     return response_data['name']