User:AkkakkBot/code/06-update-code
< User:AkkakkBot | code
python code:
site = pywikibot.Site("wikidata", "wikidata")
repo = site.data_repository()
files = ["01-terminator-taxon.py", "02-terminator-descriptions.py", "03-update-db-reports.py", "04-brackets-de.py", "05-links-to-labels.py", "06-update-code.py", "07-fix-language-mappings.py", "08-remove-redundant-aliases.py"]
print("iterate files")
for i, file in enumerate(files):
print("updating '"+file+"'"),
result_text = u"python code:<syntaxhighlight lang=python>\n"
with open ("bot-"+file, "r") as file_handler:
file_text=file_handler.read()
end = file_text.find("#akkakkbot:"+" publish till here")
start = file_text.find("#akkakkbot:"+" publish from here")
if(start == -1 or end == -1):
print("- no match")
else:
start += len("#akkakkbot:"+" publish from here")
file_part = file_text[start:end]
result_text += file_part.decode('utf8') #file_text[start:end]
result_text += "</syntax"+"highlight>\n"
pageobj = pywikibot.Page(site, u"User:AkkakkBot/code/"+file.replace(".py",""))
text_cur = pageobj.get(get_redirect = True)
if(text_cur != result_text):
print("- sending new text...")
pageobj.put(result_text, u"update (task 6)", minorEdit = False)
else:
print("- text not changed")
print("end of updates")