Skip to content

Commit ff68b64

Browse files
author
Teun
committed
Added 'dice: false' to statblock so it doesn't interfere with other plugins
1 parent e2cd307 commit ff68b64

File tree

2,118 files changed

+2137
-10
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,118 files changed

+2137
-10
lines changed

5e_monsters/convert.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import re
22
import json
3+
from bs4 import BeautifulSoup
34

45
book_regex = re.compile('(?<=-).*')
56

@@ -33,7 +34,7 @@ def parse_abilities(md_file, ability_json, name):
3334

3435
def parse_cr(cr):
3536
if cr >= 1 or cr == 0:
36-
return str(cr)
37+
return str(int(cr))
3738
elif cr == 0.5:
3839
return '1/2'
3940
elif cr == 0.25:
@@ -42,12 +43,25 @@ def parse_cr(cr):
4243
return '1/8'
4344
else:
4445
ValueError
46+
47+
def add_link(slug, url):
48+
with open(f'monsters_html/{slug}.html', "r", encoding='utf-8') as file:
49+
contents = file.read()
50+
soup = BeautifulSoup(contents, 'html.parser')
51+
paragraph = soup.find_all('p')[-1]
52+
paragraph.append(' - ')
53+
link_tag = soup.new_tag(name='a', attrs=dict(href=url))
54+
link_tag.string = 'Obsidian statblock'
55+
paragraph.append(link_tag)
56+
with open(f'monsters_html/{slug}.html', "w", encoding='utf-8') as file:
57+
file.write(str(soup))
4558

4659
def generate_mdfile(monster):
4760
if monster['document__title'] == 'Black Flag':
4861
return
4962
name_doc = f'{monster["name"]}-{doc_shorthand(monster['document__title'])}'
50-
with open(f"obsidian_statblock/{re.sub(r' ','-', name_doc).lower()}.md", 'w', encoding="utf-8") as md_file:
63+
filename = f'obsidian_statblock/{re.sub(r' ','-', name_doc).lower()}.md'
64+
with open(filename, 'w', encoding="utf-8") as md_file:
5165
md_file.write('---\n')
5266
md_file.write('obsidianUIMode: preview\n')
5367
md_file.write('cssclasses: json5e-monster\n')
@@ -63,6 +77,7 @@ def generate_mdfile(monster):
6377
md_file.write(f'*Source: {monster['document__title']} Page {monster['page_no']}*\n')
6478
md_file.write('\n')
6579
md_file.write('```statblock\n')
80+
md_file.write(f'"dice": false\n')
6681
md_file.write(f'"name": "{name_doc.replace('-',' ').title()}"\n')
6782
md_file.write(f'"size": "{monster['size']}"\n')
6883
md_file.write(f'"type": "{monster['type']}"\n')
@@ -123,17 +138,12 @@ def generate_mdfile(monster):
123138
md_file.write('source:\n')
124139
md_file.write(f'- [{monster["document__title"]}]({monster["document__url"]})\n')
125140
md_file.write('```\n')
126-
141+
add_link(monster['slug'], f'../{filename}')
127142

128143
with open("monsters.json", 'r', encoding='utf-8',
129144
errors='ignore') as f:
130145
monsters = json.load(f)
131146
print(f'Starting Monster statblock generation')
132147
for monster in monsters:
133-
generate_mdfile(monster)
134-
135-
136-
# directory = os.fsencode("monsters_html")
137-
# for file in os.listdir(directory):
138-
# filename = os.fsdecode(file)
139-
# use BeautifulSoup to edit html and add link
148+
# print(f'Generating: {monster['name']}')
149+
generate_mdfile(monster)

5e_monsters/obsidian_statblock/a-mi-kuk-tob2.md

Lines changed: 1 addition & 0 deletions

5e_monsters/obsidian_statblock/aalpamac-tob2.md

Lines changed: 1 addition & 0 deletions

5e_monsters/obsidian_statblock/aatxe-cc.md

Lines changed: 1 addition & 0 deletions

5e_monsters/obsidian_statblock/abaasy-tob3.md

Lines changed: 1 addition & 0 deletions

5e_monsters/obsidian_statblock/abbanith-giant-tob2.md

Lines changed: 1 addition & 0 deletions

5e_monsters/obsidian_statblock/aboleth-a5emm.md

Lines changed: 1 addition & 0 deletions

5e_monsters/obsidian_statblock/aboleth-thrall-a5emm.md

Lines changed: 1 addition & 0 deletions

5e_monsters/obsidian_statblock/abominable-beauty-tob2023.md

Lines changed: 1 addition & 0 deletions

5e_monsters/obsidian_statblock/abominable-snowman-a5emm.md

Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)