Created
May 6, 2019 11:24
-
-
Save naoyeye/240b0e7c36f6fd07dc21117f9e2a4f3a to your computer and use it in GitHub Desktop.
修复后的 post.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import requests | |
import json | |
from config import doubanurl | |
from util import doubanutil, tools | |
from verifycode import wordrecognition | |
def post_new_topic(group_url, topic_dict): | |
# 在指定的小组发帖 | |
# 这里直接写死 url 就可以了, group_url 其实可以不用传。 | |
r = requests.post("https://www.douban.com/j/group/topic/publish", cookies=doubanutil.get_cookies(), | |
data=topic_dict) | |
doubanutil.logger.info("in func post_new_topic(), " + | |
str(group_url) + ", status_code: " + str(r.status_code)) | |
return r | |
def make_topic_dict(group_id, rev_title, rev_text): | |
# 组装发帖需要的参数 | |
topic_new_url = doubanurl.DOUBAN_GROUP + str(group_id) + "/new_topic" | |
pic_url, pic_id = doubanutil.get_verify_code_pic(topic_new_url) | |
verify_code = "" | |
if len(pic_url): | |
pic_path = tools.save_pic_to_disk(pic_url) | |
verify_code = wordrecognition.get_word_in_pic(pic_path) | |
topic_dict = { | |
"group_id": group_id, | |
"ck": doubanutil.get_form_ck_from_cookie(), | |
"title": rev_title, | |
"content": json.JSONEncoder().encode({ | |
"blocks": [ | |
{ | |
"key":"de89q", | |
"text": rev_text, # 暂时就按这一个格式来吧。 | |
"type":"unstyled", | |
"depth":0, | |
"inlineStyleRanges":[], | |
"entityRanges":[], | |
"data":{} | |
} | |
], | |
"entityMap":{} | |
}), | |
"captcha-solution": verify_code, | |
"captcha-id": pic_id, | |
"rev_submit": "好了,发言" # 其实新版里没用了 | |
} | |
return topic_dict |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment