def section_naming_pass(feat): p = find_section(feat, name="Prerequisite", section_type='section') if p != None: p['name'] = 'Prerequisites' b = find_section(feat, name="Benefit", section_type='section') if b != None: b['name'] = 'Benefits' p = find_section(feat, name="Prerequisites", section_type='section') if p != None: soup = BeautifulSoup(p['text']) p['description'] = ''.join(soup.findAll(text=True)) del p['text'] return feat
def structural_pass(struct, filename): if filename in ("druid.html"): struct = druid_structural_pass(struct) cs = find_section(struct, name="Class Skills", section_type="section") table = find_section(cs, name=struct["name"], section_type="table") idx = struct["sections"].index(cs) while table: idx = idx + 1 if table: remove_section(struct, table) struct["sections"].insert(idx, table) table = find_section(cs, name=struct["name"], section_type="table") return struct
def structural_pass(struct, filename): if filename in ('druid.html'): struct = druid_structural_pass(struct) cs = find_section(struct, name="Class Skills", section_type='section') table = find_section(cs, name=struct['name'], section_type='table') idx = struct['sections'].index(cs) while table: idx = idx + 1 if table: remove_section(struct, table) struct['sections'].insert(idx, table) table = find_section(cs, name=struct['name'], section_type='table') return struct
def section_naming_pass(feat): p = find_section(feat, name="Prerequisite", section_type="section") if p != None: p["name"] = "Prerequisites" b = find_section(feat, name="Benefit", section_type="section") if b != None: b["name"] = "Benefits" p = find_section(feat, name="Prerequisites", section_type="section") if p != None: soup = BeautifulSoup(p["text"]) p["description"] = "".join(soup.findAll(text=True)) del p["text"] return feat
def spell_list_pass(cl): field_dict = { "Alchemist": "Alchemist Formulae", "Inquisitor": "Inquisitor Spells", "Witch": "Witch Spells", "Summoner": "Summoner Spells", "Magus": "Magus Spell List" } if cl['name'] in field_dict.keys(): name = field_dict[cl['name']] sl = find_section(cl, name=name, section_type='section') sections = sl['sections'] for section in sections: section['type'] = 'spell_list' section['class'] = cl['name'] m = re.search('(\d)', section['name']) section['level'] = int(m.group(0)) soup = BeautifulSoup(section['text']) text = ''.join(soup.findAll(text=True)) text = text.replace('—', '') text = text.replace('*', '') text = text.replace('.', '') del section['text'] spells = [] section['spells'] = spells for spell_name in text.split(", "): spell_name = spell_name.strip() spell_name = cap_words(spell_name) spell_name = spell_name.replace(" (Mass)", ", Mass") spell_name = spell_name.replace(" (Greater)", ", Greater") spell_name = spell_name.replace(" (Lesser)", ", Lesser") spell_name = spell_name.replace("Topoison", "To Poison") spells.append({"name": spell_name}) return cl
def class_pass(struct): struct['type'] = 'class' align = find_section(struct, name="Alignment", section_type='section') if align: remove_section(struct, align) soup = BeautifulSoup(align['text']) struct['alignment'] = ''.join(soup.findAll(text=True)) hd = find_section(struct, name="Hit Die", section_type='section') if hd: remove_section(struct, hd) soup = BeautifulSoup(hd['text']) hit = ''.join(soup.findAll(text=True)) if hit.endswith("."): hit = hit[:-1] struct['hit_dice'] = hit return struct
def spell_list_pass(cl): field_dict = { "Alchemist": "Alchemist Formulae", "Inquisitor": "Inquisitor Spells", "Witch": "Witch Spells", "Summoner": "Summoner Spells", "Magus": "Magus Spell List", } if cl["name"] in field_dict.keys(): name = field_dict[cl["name"]] sl = find_section(cl, name=name, section_type="section") sections = sl["sections"] for section in sections: section["type"] = "spell_list" section["class"] = cl["name"] m = re.search("(\d)", section["name"]) section["level"] = int(m.group(0)) soup = BeautifulSoup(section["text"]) text = "".join(soup.findAll(text=True)) text = text.replace("—", "") text = text.replace("*", "") text = text.replace(".", "") del section["text"] spells = [] section["spells"] = spells for spell_name in text.split(", "): spell_name = spell_name.strip() spell_name = cap_words(spell_name) spell_name = spell_name.replace(" (Mass)", ", Mass") spell_name = spell_name.replace(" (Greater)", ", Greater") spell_name = spell_name.replace(" (Lesser)", ", Lesser") spell_name = spell_name.replace("Topoison", "To Poison") spells.append({"name": spell_name}) return cl
def domain_pass(struct): d = find_section(struct, name="Domains", section_type="section") if d: domains = find_all_sections(struct, name=re.compile("^.*Domain$"), section_type="section") for domain in domains: remove_section(struct, domain) domain["subtype"] = "cleric_domain" add_section(d, domain) return struct
def class_pass(struct): struct["type"] = "class" align = find_section(struct, name="Alignment", section_type="section") if align: remove_section(struct, align) soup = BeautifulSoup(align["text"]) struct["alignment"] = "".join(soup.findAll(text=True)) hd = find_section(struct, name="Hit Die", section_type="section") if not hd: hd = find_section(struct, name="Hit Dice", section_type="section") if hd: remove_section(struct, hd) soup = BeautifulSoup(hd["text"]) hit = "".join(soup.findAll(text=True)) if hit.endswith("."): hit = hit[:-1] struct["hit_dice"] = hit return struct
def domain_pass(struct): d = find_section(struct, name="Domains", section_type='section') if d: domains = find_all_sections(struct, name=re.compile('^.*Domain$'), section_type='section') for domain in domains: remove_section(struct, domain) domain['subtype'] = 'cleric_domain' add_section(d, domain) return struct
def class_pass(struct): struct['type'] = 'class' align = find_section(struct, name="Alignment", section_type='section') if align: remove_section(struct, align) soup = BeautifulSoup(align['text']) struct['alignment'] = ''.join(soup.findAll(text=True)) hd = find_section(struct, name="Hit Die", section_type='section') if not hd: hd = find_section(struct, name="Hit Dice", section_type='section') if hd: remove_section(struct, hd) soup = BeautifulSoup(hd['text']) hit = ''.join(soup.findAll(text=True)) if hit.endswith("."): hit = hit[:-1] struct['hit_dice'] = hit return struct
def advanced_players_guide_structure_pass(rules, basename): if basename == 'advancedRaces.html': newsections = [] racesections = [] currparent = None isnew = True for section in rules['sections']: if section['name'] in ['Dwarves', 'Elves', 'Gnomes', 'Half-Elves', 'Half-Orcs', 'Halflings', 'Humans']: isnew = False currparent = section newsections.append(section) racesections = currparent.setdefault('sections', []) elif isnew: newsections.append(section) else: if section['name'] == 'Alternate Racial Traits': for trait in section['sections']: trait['type'] = 'racial_trait' trait['subtype'] = currparent['name'].lower() racesections.append(section) rules['sections'] = newsections elif basename == 'ranger.html': cl = rules['sections'][0] weap = find_section(rules, name='New Combat Styles') remove_section(rules, weap) newsec = [] for section in weap['sections']: section['subtype'] = 'ranger_combat_style' last = weap['sections'][len(weap['sections']) -1] soup = BeautifulSoup(last['text']) last['text'] = unicode(soup.contents[0]) newtext = ''.join([unicode(c) for c in soup.contents[1:]]) newsec = {'type': 'section', 'source': rules['source'], 'text': newtext} weap['sections'].append(newsec) cl.setdefault('sections', []).append(weap) elif basename == 'cleric.html': subdomains = rules['sections'][1] for section in subdomains['sections']: if section['type'] == 'section': section['subtype'] = 'cleric_subdomain' elif basename == 'sorcerer.html': newsections = [] cl = rules['sections'].pop(0) newsections.append(cl) arch = {'type': 'section', 'source': rules['source'], 'name': 'Sorcerer Bloodlines', 'sections': rules['sections']} for section in arch['sections']: section['subtype'] = 'sorcerer_bloodline' newsections.append(arch) rules['sections'] = newsections elif basename == 'wizard.html': rules = mark_subtype_pass(rules, "Elemental Arcane Schools", "elemental_arcane_school") rules = mark_subtype_pass(rules, "Focused Arcane Schools", "focused_arcane_school") if basename in ['barbarian.html', 'bard.html', 'druid.html', 'fighter.html', 'monk.html', 'paladin.html', 'ranger.html', 'rogue.html']: return ap_archetype_pass(rules) return rules
def prerequisite_pass(feat): p = find_section(feat, name="Prerequisites", section_type='section') if p != None: prereq = p['description'] if prereq.endswith("."): prereq = prereq[:-1] if prereq.find(";") > -1: parts = prereq.split(";") else: parts = prereq.strip().split(", ") feat['prerequisites'] = [part.strip() for part in parts]
def core_rulebook_structure_pass(rules, basename): if basename == 'glossary.html': c = find_section(rules, name="Conditions", section_type='section') for cond in c['sections']: cond['subtype'] = 'condition' elif basename == 'rods.html': newsections = [] for section in rules['sections']: if section.__class__ == StatBlockHeading: newsections.append(parse_section(section, rules['source'])) else: newsections.append(section) rules['sections'] = newsections return rules
def adjust_ultimate_combat_pass(struct): first = 3 second = 6 table = struct['sections'][2]['sections'][0] fdesc = struct['sections'][first] fdesc['sections'].insert(second - 1, table) del struct['sections'][2] feats = fdesc['sections'][second:] del fdesc['sections'][second:] sections = struct['sections'] struct = sections.pop(0) struct['sections'] = sections p = find_section(struct, name="Prerequisites", section_type='section') p['name'] = 'Prerequisite' return struct, feats
def bloodline_pass(struct): s = find_section(struct, name="Sorcerer Bloodlines", section_type='section') if s: collect = False bloodlines = [] for section in struct['sections']: if collect: bloodlines.append(section) elif s == section: collect = True for bloodline in bloodlines: bloodline['subtype'] = 'sorcerer_bloodline' remove_section(struct, bloodline) add_section(s, bloodline) return struct
def adjust_ultimate_combat_pass(struct): first = 3 second = 6 table = struct["sections"][2]["sections"][0] fdesc = struct["sections"][first] fdesc["sections"].insert(second - 1, table) del struct["sections"][2] feats = fdesc["sections"][second:] del fdesc["sections"][second:] sections = struct["sections"] struct = sections.pop(0) struct["sections"] = sections p = find_section(struct, name="Prerequisites", section_type="section") p["name"] = "Prerequisite" return struct, feats
def ranger_pass(cl): if cl["name"] == "Ranger": cs = find_section(cl, name="Combat Style Feat", section_type="ability") sectionlist = cs.setdefault("sections", []) soup = BeautifulSoup(cs["text"]) cs["text"] = unicode(soup.contents[0]) archery = {"type": "section", "subtype": "ranger_combat_style", "source": cl["source"]} twc = archery.copy() archery["name"] = "Archery" archery["text"] = unicode(soup.contents[1]) sectionlist.append(archery) twc["name"] = "Two-Weapon" twc["text"] = unicode(soup.contents[2]) sectionlist.append(twc) sectionlist.append({"type": "section", "source": cl["source"], "text": unicode(soup.contents[3])}) return cl
def ranger_pass(cl): if cl['name'] == 'Ranger': cs = find_section(cl, name='Combat Style Feat', section_type='ability') sectionlist = cs.setdefault('sections', []) soup = BeautifulSoup(cs['text']) cs['text'] = unicode(soup.contents[0]) archery = {'type': 'section', 'subtype': 'ranger_combat_style', 'source': cl['source']} twc = archery.copy() archery['name'] = 'Archery' archery['text'] = unicode(soup.contents[1]) sectionlist.append(archery) twc['name'] = 'Two-Weapon' twc['text'] = unicode(soup.contents[2]) sectionlist.append(twc) sectionlist.append({'type': 'section', 'source': cl['source'], 'text': unicode(soup.contents[3])}) return cl
def arcane_school_pass(struct): s = find_section(struct, name="Arcane Schools", section_type="section") if s: collect = False schools = [] for section in struct["sections"]: if section.get("name") == "Familiars": collect = False elif collect: schools.append(section) elif s == section: collect = True for school in schools: school["subtype"] = "arcane_school" remove_section(struct, school) add_section(s, school) return struct
def arcane_school_pass(struct): s = find_section(struct, name="Arcane Schools", section_type='section') if s: collect = False schools = [] for section in struct['sections']: if section.get('name') == 'Familiars': collect = False elif collect: schools.append(section) elif s == section: collect = True for school in schools: school['subtype'] = 'arcane_school' remove_section(struct, school) add_section(s, school) return struct
def ranger_pass(cl): if cl['name'] == 'Ranger': cs = find_section(cl, name='Combat Style Feat', section_type='ability') sectionlist = cs.setdefault('sections', []) soup = BeautifulSoup(cs['text']) cs['text'] = unicode(soup.contents[0]) archery = { 'type': 'section', 'subtype': 'ranger_combat_style', 'source': cl['source'] } twc = archery.copy() archery['name'] = 'Archery' archery['text'] = unicode(soup.contents[1]) sectionlist.append(archery) twc['name'] = 'Two-Weapon' twc['text'] = unicode(soup.contents[2]) sectionlist.append(twc) sectionlist.append({ 'type': 'section', 'source': cl['source'], 'text': unicode(soup.contents[3]) }) return cl
def advanced_players_guide_structure_pass(rules, basename): if basename == 'advancedRaces.html': newsections = [] racesections = [] currparent = None isnew = True for section in rules['sections']: if section['name'] in [ 'Dwarves', 'Elves', 'Gnomes', 'Half-Elves', 'Half-Orcs', 'Halflings', 'Humans' ]: isnew = False currparent = section newsections.append(section) racesections = currparent.setdefault('sections', []) elif isnew: newsections.append(section) else: if section['name'] == 'Alternate Racial Traits': for trait in section['sections']: trait['type'] = 'racial_trait' trait['subtype'] = currparent['name'].lower() racesections.append(section) rules['sections'] = newsections elif basename == 'ranger.html': cl = rules['sections'][0] weap = find_section(rules, name='New Combat Styles') remove_section(rules, weap) newsec = [] for section in weap['sections']: section['subtype'] = 'ranger_combat_style' last = weap['sections'][len(weap['sections']) - 1] soup = BeautifulSoup(last['text']) last['text'] = unicode(soup.contents[0]) newtext = ''.join([unicode(c) for c in soup.contents[1:]]) newsec = { 'type': 'section', 'source': rules['source'], 'text': newtext } weap['sections'].append(newsec) cl.setdefault('sections', []).append(weap) elif basename == 'cleric.html': subdomains = rules['sections'][1] for section in subdomains['sections']: if section['type'] == 'section': section['subtype'] = 'cleric_subdomain' elif basename == 'sorcerer.html': newsections = [] cl = rules['sections'].pop(0) newsections.append(cl) arch = { 'type': 'section', 'source': rules['source'], 'name': 'Sorcerer Bloodlines', 'sections': rules['sections'] } for section in arch['sections']: section['subtype'] = 'sorcerer_bloodline' newsections.append(arch) rules['sections'] = newsections elif basename == 'wizard.html': rules = mark_subtype_pass(rules, "Elemental Arcane Schools", "elemental_arcane_school") rules = mark_subtype_pass(rules, "Focused Arcane Schools", "focused_arcane_school") if basename in [ 'barbarian.html', 'bard.html', 'druid.html', 'fighter.html', 'monk.html', 'paladin.html', 'ranger.html', 'rogue.html' ]: return ap_archetype_pass(rules) return rules
def mark_subtype_pass(struct, name, subtype): s = find_section(struct, name=name) if s: for section in s['sections']: section['subtype'] = subtype return struct
def mark_subtype_pass(struct, name, section_type, subtype): s = find_section(struct, name=name, section_type=section_type) if s: for section in s.get("sections", []): section["subtype"] = subtype return struct
def mark_subtype_pass(struct, name, section_type, subtype): s = find_section(struct, name=name, section_type=section_type) if s: for section in s.get('sections', []): section['subtype'] = subtype return struct