Revision: 5808 Author: wikipedian Date: 2008-08-18 12:24:49 +0000 (Mon, 18 Aug 2008)
Log Message: ----------- Moved filename generation code from interwiki_graph to new method wikipedia.Page.titleForFilename().
Used that method for solve_disambiguation.py -primary. This improves the behaviour when running the script on a page that contains slashes etc.
Modified Paths: -------------- trunk/pywikipedia/interwiki_graph.py trunk/pywikipedia/solve_disambiguation.py trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/interwiki_graph.py =================================================================== --- trunk/pywikipedia/interwiki_graph.py 2008-08-18 11:53:24 UTC (rev 5807) +++ trunk/pywikipedia/interwiki_graph.py 2008-08-18 12:24:49 UTC (rev 5808) @@ -1,4 +1,4 @@ -""" Module with the graphviz drawing calls """ +""" Module with the graphviz drawing calls """ __version__ = '$Id$' import threading pydotfound = True @@ -208,13 +208,11 @@
def getFilename(page, extension = None): - filename = '%s-%s-%s' % (page.site().family.name, page.site().language(), page.title()) + filename = '%s-%s-%s' % (page.site().family.name, + page.site().language(), + page.titleForFilename()) if extension: filename += '.%s' % extension - # Replace characters that are not possible in file names on some systems. - # Spaces are possible on most systems, but are bad for URLs. - for forbiddenChar in ':*?/\ ': - filename = filename.replace(forbiddenChar, '_') return filename
if __name__ == "__main__":
Modified: trunk/pywikipedia/solve_disambiguation.py =================================================================== --- trunk/pywikipedia/solve_disambiguation.py 2008-08-18 11:53:24 UTC (rev 5807) +++ trunk/pywikipedia/solve_disambiguation.py 2008-08-18 12:24:49 UTC (rev 5808) @@ -474,7 +474,7 @@
self.ignorelist = [] filename = wikipedia.config.datafilepath('disambiguations', - self.disambPage.urlname() + '.txt') + self.disambPage.titleForFilename() + '.txt') try: # The file is stored in the disambiguation/ subdir. Create if necessary. f = codecs.open(filename, 'r', 'utf-8')
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2008-08-18 11:53:24 UTC (rev 5807) +++ trunk/pywikipedia/wikipedia.py 2008-08-18 12:24:49 UTC (rev 5808) @@ -505,6 +505,19 @@ else: return self.sectionFreeTitle(underscore=underscore).split(':', 1)[1]
+ def titleForFilename(self): + """ + Return the title of the page in a form suitable for a filename on + the user's file system. + """ + result = self.title() + # Replace characters that are not possible in file names on some + # systems. + # Spaces are possible on most systems, but are bad for URLs. + for forbiddenChar in ':*?/\ ': + result = result.replace(forbiddenChar, '_') + return result + def section(self, underscore = False, decode=False): """Return the name of the section this Page refers to.
pywikipedia-l@lists.wikimedia.org