Fixed placement of {{audio}} to respect entry layout
This commit is contained in:
parent
fb24d6fcbb
commit
36e2703533
@ -90,6 +90,9 @@ class PageEditStatus(Enum):
|
|||||||
NOTHING_TO_ADD = 1
|
NOTHING_TO_ADD = 1
|
||||||
CANNOT_ADD = 2
|
CANNOT_ADD = 2
|
||||||
|
|
||||||
|
def is_bg_ipa(node) -> bool:
|
||||||
|
return isinstance(node, mwparserfromhell.wikicode.Template) and node.name == "bg-IPA"
|
||||||
|
|
||||||
def visit_page(page_name: str, audio_file_name: str) -> bool:
|
def visit_page(page_name: str, audio_file_name: str) -> bool:
|
||||||
p = pywikibot.Page(SITE, page_name)
|
p = pywikibot.Page(SITE, page_name)
|
||||||
parsed = mwparserfromhell.parse(p.text)
|
parsed = mwparserfromhell.parse(p.text)
|
||||||
@ -166,14 +169,21 @@ def visit_page(page_name: str, audio_file_name: str) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
return PageEditStatus.SUCCESS
|
return PageEditStatus.SUCCESS
|
||||||
|
|
||||||
# pyperclip.copy(get_audio_template_from_file_name(audio_file_name))
|
# pyperclip.copy(get_audio_template_from_file_name(audio_file_name))
|
||||||
# webbrowser.open_new_tab(get_wikitonary_edit_url(page_name, sections))
|
# webbrowser.open_new_tab(get_wikitonary_edit_url(page_name, sections))
|
||||||
edit_status = should_edit()
|
edit_status = should_edit()
|
||||||
if edit_status is PageEditStatus.SUCCESS:
|
if edit_status is PageEditStatus.SUCCESS:
|
||||||
|
i = 0
|
||||||
|
pron_section: mwparserfromhell.wikicode.Wikicode = pronunciation_subsections[0]
|
||||||
|
|
||||||
|
templates: list[mwparserfromhell.wikicode.Template] = pron_section.filter_templates()
|
||||||
|
TO_INSERT = "\n" + get_audio_template_from_file_name(audio_file_name)
|
||||||
|
|
||||||
pronunciation_subsections[0].nodes[-1] = pronunciation_subsections[0].nodes[-1].replace("\n\n", "\n")
|
if is_bg_ipa(templates[0]):
|
||||||
pronunciation_subsections[0].append(get_audio_template_from_file_name(audio_file_name) + "\n\n")
|
pron_section.insert_after(templates[0], TO_INSERT)
|
||||||
|
else:
|
||||||
|
pron_section.insert(1, TO_INSERT)
|
||||||
|
|
||||||
p.text = str(parsed)
|
p.text = str(parsed)
|
||||||
edit_summary += ("A" if edit_summary == "" else "a") + "dd audio from User:Kiril kovachev"
|
edit_summary += ("A" if edit_summary == "" else "a") + "dd audio from User:Kiril kovachev"
|
||||||
|
Loading…
Reference in New Issue
Block a user