-
Notifications
You must be signed in to change notification settings - Fork 1
/
log-to-readable-md.py
125 lines (100 loc) · 2.79 KB
/
log-to-readable-md.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"""
This is for making the log.json readable as an article in MarkDown format.
You should pass the log.json file to the program while excuting it.
"""
import json, sys
file = sys.argv[1]
log = json.load(open(file, "r"))
roles = {}
text = ""
def emojing_roles(role):
roles = ["Medic", "Seer", "Villager_simple", "Werewolf_leader", "Werewolf_simple"]
roles_emoji = ["🩺", "🔍", "👤", "😈", "😈"]
return role + roles_emoji[roles.index(role)]
def results(votes):
s = ""
for i in range(7):
if votes[i] > 0:
s += f"``` Player {i} : {'+' * votes[i]} ```"
s += "<br>"
return s
def new_lines_quote(s):
return s.replace("\n", "<br> ")
for i in log:
event = i["event"]
if "content" in i.keys():
content = i["content"]
if event == "roles":
roles[content["player"]] = emojing_roles(content["role"])
text += f"""
Player *{content['player']}* is *{emojing_roles(content['role'])}*
"""
elif event == "cycle":
text += f"""
# It's **{content}** !
"""
elif event == "speech":
s = new_lines_quote(content["context"])
text += f"""
**Player {content['player']}** ({roles[content['player']]}) :
> {s}
"""
elif event == "vote_start":
text += f"""
# Voting starts
"""
elif event == "vote_end":
text += f"""
# Voting ends
"""
elif event == "vote_results":
text += f"""
{results(content)}
"""
elif event == "voted":
text += f"""
Player *{content['player']}* ({roles[content['player']]}) Voted to Player *{content['voted_to_player']}* ({roles[content['voted_to_player']]}).
Reason :
> {new_lines_quote(content['reason'])}
"""
elif event == "healed":
text += f"""
Medic decided to heal Player *{content['player']}* ({roles[content['player']]})
Reason :
> {new_lines_quote(content['reason'])}
"""
elif event == "targeted":
text += f"""
Werewolves decided to kill Player *{content['player']}* ({roles[content['player']]})
Reason :
> {new_lines_quote(content['reason'])}
"""
elif event == "killed":
text += f"""
*{content['player']}* ({roles[content['player']]}) is DEAD! 💀
"""
elif event == "inquiried":
text += f"""
Seer decided to inquiry Player *{content['player']}* ({roles[content['player']]})
Reason :
> {new_lines_quote(content['reason'])}
Answer :
{content['context']}
"""
elif event == "notetaking":
s = new_lines_quote(content["context"])
text += f"""
**Player {content['player']}** ({roles[content['player']]}) is taking note for himself : 📝
> {s}
"""
elif event == "end":
text += f"""
# Game is over! and the winner is **{i['winner']}**
"""
text += """
---
"""
# Saving the file
with open("new.md", "w") as file:
file.write(text)
print("Saved as new.md!")