-
Notifications
You must be signed in to change notification settings - Fork 6
/
parse_reviews.py
executable file
·63 lines (52 loc) · 2.13 KB
/
parse_reviews.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
#!/bin/python3
import json
import sys
import os
def help():
print("Usage:")
print(" ", sys.argv[0], "path/to/file")
print()
print("args:", sys.argv)
def main():
if len(sys.argv) < 2:
help()
exit(1)
for file in sys.argv[1:]:
data_p=[]
print("=================",file)
with open(file) as f:
data=json.load(f)
for item in data:
if "comment_at" in item.keys() or "review_at" in item.keys() or "latestReview_at" in item.keys():
data_p.append(item)
continue
if "comments" in item.keys():
for comment in item["comments"]:
tem = {}
tem["number"] = item["number"]
tem["repo"] = item["repo"]
tem["comment_at"] = comment["createdAt"]
tem["comment_author"] = comment["author"]["login"]
tem["comment_body"] = comment["body"]
data_p.append(tem)
if "reviews" in item.keys():
for review in item["reviews"]:
tem = {}
tem["number"] = item["number"]
tem["repo"] = item["repo"]
tem["review_at"] = review["submittedAt"]
tem["review_author"] = review["author"]["login"]
data_p.append(tem)
if "latestReviews" in item.keys():
for latest_review in item["latestReviews"]:
tem = {}
tem["number"] = item["number"]
tem["repo"] = item["repo"]
tem["latestReview_at"] = latest_review["submittedAt"]
tem["latestReview_author"] = latest_review["author"]["login"]
tem["latestReview_state"] = latest_review["state"]
data_p.append(tem)
with open(file, 'w', encoding='utf8') as f:
json.dump(data_p, f, indent=4)
if __name__ == "__main__":
main()