-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathaippt_demo3.py
More file actions
53 lines (41 loc) · 1.64 KB
/
aippt_demo3.py
File metadata and controls
53 lines (41 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import time
from api import *
if __name__ == '__main__':
# 根据文件异步流式生成PPT
# 官网 https://docmee.cn
# 开放平台 https://docmee.cn/open-platform/api
# 填写你的API-KEY
api_key = 'YOUR API KEY'
# 第三方用户ID(数据隔离)
uid = 'test'
# 文档文件,支持 word/excel/ppt/md/txt/pdf 等类型
file_path = os.getcwd() + '/README.md'
# 创建 api token (有效期2小时,建议缓存到redis,同一个 uid 创建时之前的 token 会在10秒内失效)
api_token = create_api_token(api_key, uid, None)
print(f'api token: {api_token}')
# 解析文件
data_url = parse_file_data(api_token, file_path, None, None)
# 生成大纲
print('\n\n========== 正在生成大纲 ==========')
outline = generate_outline(api_token, None, data_url, None)
# 生成大纲内容同时异步生成PPT
print('\n\n========== 正在异步生成大纲内容 ==========')
pptInfo = async_generate_content(api_token, outline, data_url, None, None)
ppt_id = pptInfo['id']
print(f"pptId: {ppt_id}")
# 下载PPT
print('\n\n========== 正在下载PPT ==========')
count = 0
while count < 30:
# 等待PPT文件可下载
pptInfo = download_pptx(api_token, ppt_id)
if pptInfo and 'fileUrl' in pptInfo and pptInfo['fileUrl']:
break
count = count + 1
time.sleep(1)
url = pptInfo['fileUrl']
save_path = os.getcwd() + f'/{ppt_id}.pptx'
print(f'ppt链接: {url}')
download(url, save_path)
print('ppt下载完成,保存路径:' + save_path)