From 6e4c28fb7697b62f1ad261bd96a25cde365b1119 Mon Sep 17 00:00:00 2001 From: lostecho <752549025@qq.com> Date: Sun, 26 May 2024 10:00:10 +0800 Subject: [PATCH] create attachment object --- courses/Attachment.py | 2 +- courses/parse_course.py | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/courses/Attachment.py b/courses/Attachment.py index ff8a150..edca1e1 100644 --- a/courses/Attachment.py +++ b/courses/Attachment.py @@ -7,4 +7,4 @@ class Attachment: self.url = url def __repr__(self): - return f"Attachment(id={self.id}, course_id={self.course_id}, name={self.name}, url={self.url})" \ No newline at end of file + return f"Attachment(id={self.id}, course_id={self.course_id}, name={self.name}, content={self.content}, url={self.url})" \ No newline at end of file diff --git a/courses/parse_course.py b/courses/parse_course.py index 1b55046..267a400 100644 --- a/courses/parse_course.py +++ b/courses/parse_course.py @@ -6,6 +6,8 @@ from pathlib import Path import requests from pydub import AudioSegment +from courses.Attachment import Attachment + def get_course_id(date_file_path): with open(date_file_path, encoding="UTF-8") as file: @@ -91,8 +93,22 @@ def get_audio(audio_data): logging.info(f"All MP3 files have been downloaded, merged into {output_filename}, and temporary files have been removed.") +# 获取全部附件 +def get_all_attachments(attachment_json_data): + data = json.loads(attachment_json_data) + attachments = [item for item in data["data"]["course_contents"]] + attachmentlist = [] + for attachment in attachments: + attachment = Attachment(attachments[0]["id"], attachments[0]["course_id"], attachments[0]["content"], attachments[0]["content"], attachments[0]["attachment"].get("url")) + print(attachment) + attachmentlist.append(attachment) + print(attachments) + return attachmentlist + + if __name__ == '__main__': ids = get_course_id('all/course.json') token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiIxMDAwMDgzNDciLCJleHAiOjE3MTkxODk0ODQsImp0aSI6IjU3ZTJhMzdmLTMyZGEtNGQ2My1hZjQxLTY5NTRlNmU1OTg2MiIsImlhdCI6MTcxNjUxMTA4NCwiaXNzIjoiYXBwdXNlciIsInVpZCI6ImJlMmViOGIyLTFhOTItNGVmMC05ZDAwLTA1YTlkN2E2OWRiMiIsInNjaGVtZSI6Imp3dGhzIiwic2lkIjoiMWI4ZjE1ZTItYjQ5ZC00MmRmLWEwNDUtZmQxYTUwNzI5ZjkxIn0.IO7C2gtsi8lMdrOgWGNuxK-t2zzmDPvmI4BqISHeZEI" json_data = request_date(ids[0], token) - get_audio(json_data) + #get_audio(json_data) + get_all_attachments(json_data)