-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSONRunner.py
70 lines (53 loc) · 1.58 KB
/
JSONRunner.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import Tools as tools
def linkByAuthor_url_token(jsonList):
authors = {}
for i in range(0,len(jsonList)):
# 没有剔除原有id的item,因为,这样可以偷懒,,
if jsonList[i]["url_token"] != "":
authors[jsonList[i]["url_token"]] = jsonList[i]
return authors
def featuresToAuthor(author):
author = author["author"]
# author JSON格式
# 提取id、url_token、name、headline、gender、badge
features = {
"id":{},
"url_token":{},
"name":{},
"gender":{},
"headline":{},
"badge":{},
}
# author = json.loads(author)
features["id"] = author["id"]
features["url_token"] = author["url_token"]
features["name"] = author["name"]
features["gender"] = author["gender"]
features["headline"] = author["headline"]
features["badge"] = author["badge"]
return features
def featuresAllSave(data):
return data
def main():
print("encoding:")
# encoding = utf-8
encoding = input()
print("link:")
# link = "D:\GoldbachResearchGroup\data-master\\12.31\answers"
link = input()
print("targetLink:")
# targetLink = "D:\GoldbachResearchGroup\data-master\\12.31"
targetLink = input()
print("targetFilename:")
# targetFilename = "authorsofAnswers_12_31_18_23"
targetFilename = input()
print("开始遍历:" + link)
jsonList = tools.foreachFolder(link,encoding,featuresToAuthor)
print("遍历完成:" + link)
jsonList = linkByAuthor_url_token(jsonList)
print("开始写入:" + targetFilename + ".json")
tools.writeJSONList(jsonList,targetLink,targetFilename,encoding)
print("写入完成:" + targetFilename +".json")
if __name__ == '__main__':
main()