-
-
Notifications
You must be signed in to change notification settings - Fork 521
/
export.py
48 lines (40 loc) · 1.26 KB
/
export.py
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
#!/usr/bin/python3
# -*- coding: UTF-8 -*-
# SETP3 : 导出md的表格
import requests
import json
import urllib
import os
export = "|序号|图片|标题|单词数量|文件大小|背诵人数|下载地址|id|标签|\n";
export = export + "|---|---|---|---|---|---|---|---|---|\n";
def getTag( tag ):
result = [];
for i in tag:
result.append(i["tagName"]);
return "、".join(result);
with open("./bookLists.txt",'r',encoding='UTF-8') as load_f:
load_dict = json.load(load_f)
bookLists = load_dict['data']['normalBooksInfo']
bookLen = len(bookLists);
nowIndex = 0;
for i in bookLists:
nowIndex = nowIndex +1;
id = i['id']
picUrl = i['cover']
title = i['title']
wordNum = i['wordNum']
fizeSize = i['size']
reciteUserNum = i['reciteUserNum']
fileUrl = i['offlinedata'];
# tag = "";
tag = getTag(i['tags']);
filename = os.path.basename(fileUrl)
basefile = "book/";
picMD = "![{}]({})".format(title,picUrl);
downloadUrl = "[{}]({}{}) [{}]({})".format( "本地地址",basefile,filename, "原始地址",fileUrl,);
item = "|{}|{}|{}|{}|{}|{}|{}|{}|{}|\n".format(nowIndex,picMD,title,wordNum,fizeSize,reciteUserNum,downloadUrl,id,tag)
export = export + item;
print( export )
with open("./export.txt",'w',encoding='UTF-8') as f:
f.write( export );
f.close