Permalink
Browse files

Fixed a logical error; updated for dev version of mwparserfromhell; s…

…tandardi[sz]e the page fotter if adding a new section; etc.
  • Loading branch information...
1 parent 8600350 commit f7df345876f607d47156f52f6e727de36b92f256 @HazardSJ committed Jun 7, 2013
Showing with 20 additions and 5 deletions.
  1. +20 −5 wikivoyage.py
View
25 wikivoyage.py
@@ -5,11 +5,17 @@
# under the terms of Creative Commons Attribution-ShareAlike 3.0 Unported (CC BY-SA 3.0)
# https://creativecommons.org/licenses/by-sa/3.0/
+from __future__ import unicode_literals
+
import mwparserfromhell
+import config
+from cosmetic_changes import CosmeticChangesToolkit
import pywikibot
import xmlreader
+config.usernames["wikipedia"]["en"] = "Hazard-Bot"
+
class WikivoyageBot(object):
def __init__(self):
self.wikipedia = pywikibot.Site("en", "wikipedia")
@@ -21,23 +27,27 @@ def __init__(self):
"wikivoyage": self.getAllTitles("Template:Wikivoyage")
}
self.templates["wikivoyage"].extend(self.getAllTitles("Template:Wikivoyage-inline"))
+ self.cosmeticChanges = CosmeticChangesToolkit(self.wikipedia)
def checkDoTaskPage(self):
try:
text = self.doTaskPage.get(force = True)
except pywikibot.IsRedirectPage:
raise Warning(
- "The 'do-task page' (%s) is a redirect." % self.doTaskPage.title(asLink = True)
+ "The 'do-task page' (%s) is a redirect."
+ % self.doTaskPage.title(asLink = True)
)
except pywikibot.NoPage:
raise Warning(
- "The 'do-task page' (%s) does not exist." % self.doTaskPage.title(asLink = True)
+ "The 'do-task page' (%s) does not exist."
+ % self.doTaskPage.title(asLink = True)
)
else:
if text.strip().lower() == "true":
return True
else:
- raise Exception("The task has been disabled from the 'do-task page' (%s)."
+ raise Exception(
+ "The task has been disabled from the 'do-task page' (%s)."
% self.doTaskPage.title(asLink = True)
)
@@ -59,7 +69,7 @@ def parseDump(self):
continue
voyTitle = page.title
code = mwparserfromhell.parse(page.text)
- links = code.filter_links()
+ links = code.filter_wikilinks()
for link in links:
if not link.title.lower().strip().startswith("wikipedia"):
continue
@@ -112,7 +122,7 @@ def run(self):
lastSectionText = None
for node in code.nodes:
if isinstance(node, mwparserfromhell.nodes.heading.Heading):
- if "external" or "links" in node.lower():
+ if ("external" in node.lower()) or ("links" in node.lower()):
externalLinksHeading = node
break
if isinstance(node, mwparserfromhell.nodes.text.Text):
@@ -124,6 +134,11 @@ def run(self):
lastSectionText,
"\n== External links ==%s\n" % voyTemplate
)
+ code = mwparserfromhell.parse(
+ self.cosmeticChanges.standardizePageFooter(
+ unicode(code)
+ )
+ )
else:
print "Skipping: Could not insert template"
wpPageCats = [category.title() for category in wpPage.categories(api = True)]

0 comments on commit f7df345

Please sign in to comment.