-
Notifications
You must be signed in to change notification settings - Fork 0
/
wikicreator.py
32 lines (27 loc) · 1.14 KB
/
wikicreator.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
from chem import Chem
import re
class Wikicreator:
def __init__(self):
self.chems = []
def createRecipeEntry(self, chem: Chem):
output = []
output.append(f'<span id="{chem.name}"></span>')
output.append('|-')
output.append(f'!style=\'background-color:#B452CD;\'|{chem.name}<span style="color:{chem.color};background-color:white">▮</span>')
output.append(f'|{self.createRecipe(chem.recipe)}')
output.append(f'|{chem.description}')
output.append(f'|{chem.metabolism}')
output.append(f'|{chem.overdose}')
output.append('|-')
return "\n".join(output)
def createRecipe(self, recipe):
output = []
for ingred in recipe:
output.append(f"{recipe[ingred]} part{'s' if recipe[ingred] == 0 else ''} {self.getchemname(ingred)}")
return "<br>".join(output)
def getchemname(self, name):
result = next((chem for chem in self.chems if chem.id == name), None)
if result is None:
return name.capitalize()
else:
return f"[[#{result.name}|{result.name}]]"