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
|
# 0.1.3
|
||||||
|
|
||||||
- Add overwrite option to append_text in wiki interface
|
- 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]
|
[tool.poetry]
|
||||||
name = "wiki-postbot"
|
name = "wiki-postbot"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
description = "Add posts to the wiki!"
|
description = "Add posts to the wiki!"
|
||||||
authors = ["sneakers-the-rat <JLSaunders987@gmail.com>"]
|
authors = ["sneakers-the-rat <JLSaunders987@gmail.com>"]
|
||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
|
|
|
@ -87,10 +87,6 @@ class Wiki:
|
||||||
return WikiPage.from_source(title=content['parse']['title'], source=content['parse']['wikitext'])
|
return WikiPage.from_source(title=content['parse']['title'], source=content['parse']['wikitext'])
|
||||||
|
|
||||||
def insert_text(self, page, section, text, overwrite:bool=False):
|
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!
|
# TODO: Move finding section IDs into the page class!
|
||||||
page_text = self.get_page(page)
|
page_text = self.get_page(page)
|
||||||
|
@ -117,17 +113,30 @@ class Wiki:
|
||||||
|
|
||||||
if matching_section >= 0:
|
if matching_section >= 0:
|
||||||
print(f'found matching section {matching_section}')
|
print(f'found matching section {matching_section}')
|
||||||
result = self.sess.post(
|
if overwrite:
|
||||||
self.api_url,
|
page_text.content.sections[matching_section].contents = text
|
||||||
data={
|
result = self.sess.post(
|
||||||
"action":"edit",
|
self.api_url,
|
||||||
"title":page,
|
data={
|
||||||
"section":str(matching_section),
|
"action":"edit",
|
||||||
operation_key:text,
|
"title":page,
|
||||||
"format":"json",
|
"text": page_text.content.string,
|
||||||
"token":token
|
"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:
|
else:
|
||||||
self.logger.debug('making new section')
|
self.logger.debug('making new section')
|
||||||
result = self.sess.post(
|
result = self.sess.post(
|
||||||
|
@ -137,7 +146,7 @@ class Wiki:
|
||||||
"title":page,
|
"title":page,
|
||||||
"section":"new",
|
"section":"new",
|
||||||
"sectiontitle":section,
|
"sectiontitle":section,
|
||||||
operation_key:text,
|
"appendtext":text,
|
||||||
"format":"json",
|
"format":"json",
|
||||||
"token":token
|
"token":token
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue