create attachment object

This commit is contained in:
lostecho
2024-05-26 10:00:10 +08:00
parent 2449c137f9
commit 6e4c28fb76
2 changed files with 18 additions and 2 deletions

View File

@@ -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)