Ejemplo n.º 1
0
def reject_user(session, groupid, requestid):
    # 拒绝入组申请
    url = 'https://www.douban.com/j/group/' + groupid + '/requests/reject'
    reply_dict = {
        'MIME Type': 'application/x-www-form-urlencoded',
        'req_item': requestid,
        "ck": util.get_ck_from_cookies(session)
    }
    print(reply_dict)
    response = session.post(url, reply_dict, cookies=util.loadCookies())
    print(response)
Ejemplo n.º 2
0
def self_intro(session, user_id):
    # 给非双关用户发消息,需要先打招呼,对方回复后才能聊天
    url = 'https://www.douban.com/j/doumail/selfintro'
    param_dict = {
        'to_user_id': user_id,
        "ck": util.get_ck_from_cookies(session)
    }
    print(param_dict)
    response = session.post(url, param_dict)
    print(response)
    logging.info(str(param_dict) + str(response))
Ejemplo n.º 3
0
def collect_to_list(session, listid, topicid, comment=''):
    # 收藏帖子到豆列
    url = 'https://www.douban.com/j/doulist/' + listid + '/additem'
    param_dict = {
        # 'MIME Type': 'application/x-www-form-urlencoded',
        'sid': topicid,
        'skind': '1013',
        "ck": util.get_ck_from_cookies(session),
        'comment': comment,
        'sync_to_mb': ''
        # "captcha-solution": verify_code,
        # "captcha-id": pic_id
    }
    response = session.post(url, param_dict)
Ejemplo n.º 4
0
def reply_to_post(session, url, content, topic_id=None):
    # 回复帖子
    if not topic_id:
        url = url + 'add_comment'
    else:
        url = topic_base_url + topic_id + '/add_comment'
    # https://www.douban.com/group/topic/198628115/
    # reply_url='https://api.douban.com/v2/group/topic/'+post_id+'/comments'
    pic_url, pic_id = captcha_util.get_verify_code_pic(session, url[:-12])
    verify_code = ""
    # pic_url, pic_id="",""
    post_retry_count = 3
    while post_retry_count > 0:
        try:
            if len(pic_url):
                retry_count = 0
                while verify_code == '' and retry_count < 2:  # 识别不出的话重试
                    pic_path = captcha_util.save_pic_to_disk(pic_url, session)
                    verify_code = captcha_util.get_word_in_pic(pic_path)
                    os.remove(pic_path)
                    retry_count = retry_count + 1
                    time.sleep(2)
            reply_dict = {
                "ck": util.get_ck_from_cookies(session),
                'rv_comment': content,
                "captcha-solution": verify_code,
                "captcha-id": pic_id,
                'start': 0,
                'submit_btn': '发送'
            }
            print(reply_dict)
            response = session.post(url, reply_dict)
            print(response)
            logging.info(str(reply_dict) + str(response))
            if response.status_code > 300:
                raise RuntimeError('post failed, status', response.status_code)
            post_retry_count = -100
        except:
            post_retry_count -= 1  # 发帖失败,重试
    if post_retry_count == 0:
        raise RuntimeError
Ejemplo n.º 5
0
def sent_doumail(session, user_id, content):
    # 向用户发送豆邮
    url = 'https://www.douban.com/j/doumail/send'
    user_url = 'https://www.douban.com/doumail/%s/' % user_id
    pic_url, pic_id = captcha_util.get_verify_code_pic_doumail(
        session, user_url)
    verify_code = ""
    # pic_url, pic_id="",""
    if len(pic_url):
        retry_count = 0
        while retry_count < 3:
            pic_path = captcha_util.save_pic_to_disk(pic_url, session)
            verify_code = captcha_util.get_word_in_pic(pic_path)
            os.remove(pic_path)
            retry_count = retry_count + 1
            time.sleep(5)
            if verify_code == '':  # 识别不出的话重试
                pic_url, pic_id = captcha_util.get_verify_code_pic_doumail(
                    session, user_url)
                verify_code = ""
            else:
                break
        if retry_count == 3:
            util.email_notify()
            raise RuntimeError('Captcha failed')

    param_dict = {
        "ck": util.get_ck_from_cookies(session),
        'to': user_id,
        "m_text": content,
        "m_image": '',
        "captcha-solution": verify_code,
        "captcha-id": pic_id
        #'m_submit': '%E5%A5%BD%E4%BA%86%EF%BC%8C%E5%AF%84%E5%87%BA%E5%8E%BB'#encoded '好了,寄出去'
    }
    print(param_dict)
    response = session.post(url, param_dict, cookies=util.loadCookies())
    print(response)
    logging.info(str(param_dict) + str(response))
Ejemplo n.º 6
0
def post_in_group(session, group_id, title, content):
    # 发布新帖子
    publish_url = 'https://www.douban.com/j/group/topic/publish'
    topic_new_url = 'https://www.douban.com/group/%s/new_topic' % group_id
    pic_url, pic_id = captcha_util.get_verify_code_pic(session, topic_new_url)
    verify_code = ""
    # pic_url, pic_id="",""
    if len(pic_url):
        pic_path = captcha_util.save_pic_to_disk(pic_url)
        verify_code = captcha_util.get_word_in_pic(pic_path)
    topic_dict = {
        "ck": util.get_ck_from_cookies(session),
        "title": title,
        "content": r"{'blocks':[{'key':'893dl','text':'" + content.strip() +
        '''','type':'unstyled','depth':0,'inlineStyleRanges':[],'entityRanges':[],data':{'page':0}}],'entityMap':{}}''',
        "captcha-solution": verify_code,
        "captcha-id": pic_id,
        "group_id": 696739
    }

    print(topic_dict)
    r = session.post(publish_url, topic_dict)
    print(r.text)
Ejemplo n.º 7
0
def like_post(session, post_id):
    # 点赞功能,api目前无法使用
    reply_url = 'https://www.douban.com/group/topic/' + post_id + '/like'
    # reply_url='http://api.douban.com/v2/group/topic/'+post_id+'/like'
    # reply_url='http://m.douban.com/rexxar/api/v2/group/topic/'+post_id+'/react'
    # pic_url, pic_id = DouUtil.get_verify_code_pic(session, reply_url)
    verify_code = ""
    pic_url, pic_id = "", ""
    if len(pic_url):
        retry_count = 0
        while verify_code == '' and retry_count < 2:  # 识别不出的话重试
            pic_path = captcha_util.save_pic_to_disk(pic_url, session)
            verify_code = captcha_util.get_word_in_pic(pic_path)
            os.remove(pic_path)
            retry_count = retry_count + 1
            time.sleep(2)
    reply_dict = {
        # 'MIME Type': 'application/x-www-form-urlencoded',
        'reaction_type': '1',
        "ck": util.get_ck_from_cookies(session)
    }
    print(reply_dict)
    response = requests.get(reply_url, cookies=getCookiesFromSession(session))
    print(response)