v0.1.4 - overwrite correctly
This commit is contained in:
parent
578d889395
commit
dace014779
3 changed files with 31 additions and 18 deletions
|
@ -1,3 +1,7 @@
|
|||
# 0.1.3
|
||||
|
||||
- Add overwrite option to append_text in wiki interface
|
||||
|
||||
# 0.1.4
|
||||
|
||||
- Like 0.1.3 but actually doing it right
|
|
@ -1,6 +1,6 @@
|
|||
[tool.poetry]
|
||||
name = "wiki-postbot"
|
||||
version = "0.1.3"
|
||||
version = "0.1.4"
|
||||
description = "Add posts to the wiki!"
|
||||
authors = ["sneakers-the-rat <JLSaunders987@gmail.com>"]
|
||||
license = "GPL-3.0"
|
||||
|
|
|
@ -87,10 +87,6 @@ class Wiki:
|
|||
return WikiPage.from_source(title=content['parse']['title'], source=content['parse']['wikitext'])
|
||||
|
||||
def insert_text(self, page, section, text, overwrite:bool=False):
|
||||
if overwrite:
|
||||
operation_key = 'text'
|
||||
else:
|
||||
operation_key = 'appendtext'
|
||||
|
||||
# TODO: Move finding section IDs into the page class!
|
||||
page_text = self.get_page(page)
|
||||
|
@ -117,17 +113,30 @@ class Wiki:
|
|||
|
||||
if matching_section >= 0:
|
||||
print(f'found matching section {matching_section}')
|
||||
result = self.sess.post(
|
||||
self.api_url,
|
||||
data={
|
||||
"action":"edit",
|
||||
"title":page,
|
||||
"section":str(matching_section),
|
||||
operation_key:text,
|
||||
"format":"json",
|
||||
"token":token
|
||||
}
|
||||
)
|
||||
if overwrite:
|
||||
page_text.content.sections[matching_section].contents = text
|
||||
result = self.sess.post(
|
||||
self.api_url,
|
||||
data={
|
||||
"action":"edit",
|
||||
"title":page,
|
||||
"text": page_text.content.string,
|
||||
"format":"json",
|
||||
"token":token
|
||||
}
|
||||
)
|
||||
else:
|
||||
result = self.sess.post(
|
||||
self.api_url,
|
||||
data={
|
||||
"action":"edit",
|
||||
"title":page,
|
||||
"section":str(matching_section),
|
||||
"appendtext":text,
|
||||
"format":"json",
|
||||
"token":token
|
||||
}
|
||||
)
|
||||
else:
|
||||
self.logger.debug('making new section')
|
||||
result = self.sess.post(
|
||||
|
@ -137,7 +146,7 @@ class Wiki:
|
|||
"title":page,
|
||||
"section":"new",
|
||||
"sectiontitle":section,
|
||||
operation_key:text,
|
||||
"appendtext":text,
|
||||
"format":"json",
|
||||
"token":token
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue