提交 0a696180 编写于 作者: ToTensor's avatar ToTensor

update code

上级 68567051
此差异已折叠。
...@@ -2,8 +2,8 @@ from src.ebook.extract_book_code import extract_code ...@@ -2,8 +2,8 @@ from src.ebook.extract_book_code import extract_code
from src.ebook.community import send_topic from src.ebook.community import send_topic
if __name__ == "__main__": if __name__ == "__main__":
extract_code() # extract_code()
web_url = 'https://gitcode.net/csdn/content/book_code_08fd0c7025a4a34a97a29897b067d24/-/tree/master/' web_url = 'https://gitcode.net/csdn/content/book_code_08fd0c7025a4a34a97a29897b067d24/-/tree/master/'
print('-------' * 20) print('-------' * 20)
print('开始向社区发帖') print('开始向社区发帖')
# send_topic(web_url) send_topic(web_url)
\ No newline at end of file \ No newline at end of file
...@@ -23,6 +23,21 @@ def get_files_path(file_dir, filetype='.txt'): ...@@ -23,6 +23,21 @@ def get_files_path(file_dir, filetype='.txt'):
return files_path return files_path
def get_all_files(current_address):
files = []
for parent, dirnames, filenames in os.walk(current_address):
# Case1: traversal the directories
# for dirname in dirnames:
# print("Parent folder:", parent)
# print("Dirname:", dirname)
# # Case2: traversal the files
for filename in filenames:
# print("Parent folder:", parent)
file_path = os.path.join(parent, filename)
files.append(file_path)
return files
def post(url, params, retry=3, headers=None): def post(url, params, retry=3, headers=None):
if headers is None: if headers is None:
hdrs = {"Content-Type": "application/json"} hdrs = {"Content-Type": "application/json"}
...@@ -52,12 +67,16 @@ def post(url, params, retry=3, headers=None): ...@@ -52,12 +67,16 @@ def post(url, params, retry=3, headers=None):
def send_topic(web_url): def send_topic(web_url):
data_dir = 'data' data_dir = 'data'
book_dir = 'data/全程软件测试(第3版)/' book_dir = 'data/深入剖析Nginx/'
# web_url = "https://codechina.csdn.net/csdn/book_code_c798a5992a654857867ec15660e1c32a/-/blob/master/" # web_url = "https://codechina.csdn.net/csdn/book_code_c798a5992a654857867ec15660e1c32a/-/blob/master/"
request_url = 'http://ccloud.internal.csdn.net/v1/internal/community/content/sendTopic' request_url = 'http://ccloud.internal.csdn.net/v1/internal/community/content/sendTopic'
files = get_files_path('data/全程软件测试(第3版)', '.java') # files = get_files_path('data/全程软件测试(第3版)', '.java')
mapping_path = 'data/全程软件测试(第3版).json'
files = get_all_files(book_dir)
print(files)
mapping_path = 'data/深入剖析Nginx.json'
if not os.path.exists(mapping_path): if not os.path.exists(mapping_path):
chapter_code_mapping = {} chapter_code_mapping = {}
...@@ -83,11 +102,11 @@ def send_topic(web_url): ...@@ -83,11 +102,11 @@ def send_topic(web_url):
send_topic_request_param = { send_topic_request_param = {
"type": "long_text", "type": "long_text",
"cateId": 20965, "cateId": 20966,
"content": topic_content, "content": topic_content,
"topicTitle": topic_title, "topicTitle": topic_title,
"mdContent": topic_content, "mdContent": topic_content,
"communityId": 3822, "communityId": 3821,
"loginUserName": "BBS_Assistant", "loginUserName": "BBS_Assistant",
"bizNo": "ebook" "bizNo": "ebook"
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册