Mailto.py

From MythTV

Jump to: navigation, search

Note: The correct title of this article is mailto.py. It appears incorrectly here due to technical restrictions.


This is a pywikipedia script, developed to support maintenance of this site.

Several user pages have email links on them. Mediawiki supports the mailto: type designator. However, many of the entries, due to MoinMoin's style, have spaces in them. This script cleans up the mail links, and make them operable again.

Source code

Image:PythonIcon.png mailto.py

import re
from pywikipedia import wikipedia

site = wikipedia.getSite()

for page in site.allpages():
        if not page.isRedirectPage():
                wikitext = page.get()

                try:
                        mailtoR = re.compile("mailto:\((.*)\)")
                        results = mailtoR.search(wikitext)
                        before, after = results.span()
                        final = wikitext[0:before] + re.compile("\(|\)").sub("", re.compile(" ").sub("_", results.group())) + wikitext[after:]
                        if wikitext <> final:
                                page.put(newtext = final, comment='[[pywikipedia]] assisted cleanup ([[mailto.py]])-> fixing legacy email references', minorEdit=True)
                except:
                        pass

How to run it

To run the script, it needs no arguments.

% python mailto.py

It will search all pages, and where it sees: mailto:(foo at bar), it will replace it with mailto:foo_at_bar.

Personal tools