Created
January 4, 2017 16:00
-
-
Save halfak/57de7bc6709de574a6bfe7051370fea9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
HOST_EXCEPTIONS = { | |
'mediawikiwiki': "mediawiki.org", | |
'wikidatawiki': "wikidata.org", | |
'commonswiki': "commons.wikimedia.org", | |
'metawiki': "meta.wikimedia.org", | |
'specieswiki': "species.wikimedia.org", | |
'wikisourcewiki': "wikisource.org", | |
'incubatorwiki': "incubator.wikimedia.org", | |
'labswiki': "wikitech.wikimedia.org", | |
'foundationwiki': "wikimediafoundation.org" | |
} | |
HOST_RULES = ( | |
(re.compile(r'(.*)wiki$'), | |
lambda match: match.group(1) + ".wikipedia.org"), | |
(re.compile(r'(.*)wiktionary$'), | |
lambda match: match.group(1) + ".wiktionary.org"), | |
(re.compile(r'(.*)wikinews$'), | |
lambda match: match.group(1) + ".wikinews.org"), | |
(re.compile(r'(.*)wikiquote$'), | |
lambda match: match.group(1) + ".wikiquote.org"), | |
(re.compile(r'(.*)wikibooks$'), | |
lambda match: match.group(1) + ".wikibooks.org"), | |
(re.compile(r'(.*)wikiversity$'), | |
lambda match: match.group(1) + ".wikiversity.org"), | |
(re.compile(r'(.*)wikivoyage$'), | |
lambda match: match.group(1) + ".wikivoyage.org") | |
) | |
def host_from_dbname(dbname): | |
if dbname in HOST_EXCEPTIONS: | |
return HOST_EXCEPTIONS[dbname] | |
else: | |
for regex, apply_rule in HOST_RULES: | |
match = regex.match(dbname) | |
if match is not None: | |
return apply_rule(match) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment