wikitravel_family.py :  » Network » Python-Wikipedia-Robot-Framework » pywikipedia » families » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » Python Wikipedia Robot Framework 
Python Wikipedia Robot Framework » pywikipedia » families » wikitravel_family.py
# -*- coding: utf-8  -*-
import family, config

# The wikitravel family

# Translation used on all wikitravels for the 'article' text.
# A language not mentioned here is not known by the robot

__version__ = '$Id: wikitravel_family.py 7551 2009-10-27 21:12:35Z alexsh $'

class Family(family.Family):
    def __init__(self):
        family.Family.__init__(self)
        self.name = 'wikitravel'
        self.langs = {
            'ar':'ar',
            'ca':'ca',
            'de':'de',
            'en':'en',
            'eo':'eo',
            'es':'es',
            'fi':'fi',
            'fr':'fr',
            'he':'he',
            'hi':'hi',
            'hu':'hu',
            'it':'it',
            'ja':'ja',
            'ko':'ko',
            'nl':'nl',
            'pl':'pl',
            'pt':'pt',
            'ro':'ro',
            'ru':'ru',
            'sv':'sv',
            'zh':'zh',
            'wts':'wts',
        }
        self.namespaces[-2] = {
            '_default': u'Media',
            'ar': u'',
            'he': u'',
            'hu': u'Mdia',
            'ru': u'',
        }
        self.namespaces[-1] = {
            '_default': u'Special',
            'ar': u'',
            'ca': u'Especial',
            'de': u'Spezial',
            'eo': u'Speciala',
            'es': u'Especial',
            'fi': u'Toiminnot',
            'he': u'',
            'hi': u'',
            'hu': u'Specilis',
            'it': u'Speciale',
            'ja': u'',
            'ko': u'',
            'nl': u'Speciaal',
            'pl': u'Specjalna',
            'pt': u'Especial',
            'ru': u'',
        }
        self.namespaces[1] = {
            '_default': u'Talk',
            'ar': u'',
            'ca': u'Discussi',
            'de': u'Diskussion',
            'eo': u'Diskuto',
            'es': u'Discusin',
            'fi': u'Keskustelu',
            'fr': u'Discuter',
            'he': u'',
            'hi': u'',
            'hu': u'Vita',
            'it': u'Discussione',
            'ja': u'',
            'ko': u'',
            'nl': u'Overleg',
            'pl': u'Dyskusja',
            'pt': u'Discusso',
            'ro': u'Discuie',
            'ru': u'',
            'sv': u'Diskussion',
        }
        self.namespaces[2] = {
            '_default': u'User',
            'ar': u'',
            'ca': u'Usuari',
            'de': u'Benutzer',
            'eo': u'Vikipediisto',
            'es': u'Usuario',
            'fi': u'Kyttj',
            'fr': u'Utilisateur',
            'he': u'',
            'hi': u'',
            'it': u'Utente',
            'ja': u'',
            'ko': u'',
            'nl': u'Gebruiker',
            'pl': u'Uytkownik',
            'pt': u'Usurio',
            'ro': u'Utilizator',
            'ru': u'',
            'sv': u'Anvndare',
        }
        self.namespaces[3] = {
            '_default': u'User talk',
            'ar': u' ',
            'ca': u'Usuari Discussi',
            'de': u'Benutzer Diskussion',
            'eo': u'Vikipediista diskuto',
            'es': u'Usuario Discusin',
            'fi': u'Keskustelu kyttjst',
            'fr': u'Discussion Utilisateur',
            'he': u' ',
            'hi': u' ',
            'hu': u'User vita',
            'it': u'Discussioni utente',
            'ja': u'',
            'ko': u'',
            'nl': u'Overleg gebruiker',
            'pl': u'Dyskusja uytkownika',
            'pt': u'Usurio Discusso',
            'ro': u'Discuie Utilizator',
            'ru': u' ',
            'sv': u'Anvndardiskussion',
        }
        self.namespaces[4] = {
            '_default': u'Wikitravel',
            'he': u'',
            'hi': u'',
            'wts': u'Wikitravel Shared',
        }
        self.namespaces[5] = {
            '_default': u'Wikitravel talk',
            'ar': u' Wikitravel',
            'ca': u'Wikitravel Discussi',
            'de': u'Wikitravel Diskussion',
            'eo': u'Wikitravel diskuto',
            'es': u'Wikitravel Discusin',
            'fi': u'Keskustelu Wikitravelista',
            'fr': u'Discussion Wikitravel',
            'he': u' ',
            'hi': u' ',
            'hu': u'Wikitravel vita',
            'it': u'Discussioni Wikitravel',
            'ja': u'Wikitravel',
            'ko': u'Wikitravel',
            'nl': u'Overleg Wikitravel',
            'pl': u'Dyskusja Wikitravel',
            'pt': u'Wikitravel Discusso',
            'ro': u'Discuie Wikitravel',
            'ru': u' Wikitravel',
            'sv': u'Wikitraveldiskussion',
            'wts': u'Wikitravel Shared talk',
        }
        self.namespaces[6] = {
            '_default': u'Image',
            'ar': u'',
            'ca': u'Imatge',
            'de': u'Bild',
            'eo': u'Dosiero',
            'es': u'Imagen',
            'fi': u'Kuva',
            'he': u'',
            'hi': u'',
            'hu': u'Kp',
            'it': u'Immagine',
            'ja': u'',
            'ko': u'',
            'nl': u'Afbeelding',
            'pl': u'Grafika',
            'pt': u'Imagem',
            'ro': u'Imagine',
            'ru': u'',
            'sv': u'Bild',
        }
        self.namespaces[7] = {
            '_default': u'Image talk',
            'ar': u' ',
            'ca': u'Imatge Discussi',
            'de': u'Bild Diskussion',
            'eo': u'Dosiera diskuto',
            'es': u'Imagen Discusin',
            'fi': u'Keskustelu kuvasta',
            'fr': u'Discussion Image',
            'he': u' ',
            'hi': u' ',
            'hu': u'Kp vita',
            'it': u'Discussioni immagine',
            'ja': u'',
            'ko': u'',
            'nl': u'Overleg afbeelding',
            'pl': u'Dyskusja grafiki',
            'pt': u'Imagem Discusso',
            'ro': u'Discuie Imagine',
            'ru': u' ',
            'sv': u'Bilddiskussion',
        }
        self.namespaces[8] = {
            '_default': u'MediaWiki',
            'ar': u'',
            'fi': u'Jrjestelmviesti',
            'he': u' ',
        }
        self.namespaces[9] = {
            '_default': u'MediaWiki talk',
            'ar': u' ',
            'ca': u'MediaWiki Discussi',
            'de': u'MediaWiki Diskussion',
            'eo': u'MediaWiki diskuto',
            'es': u'MediaWiki Discusin',
            'fi': u'Keskustelu jrjestelmviestist',
            'fr': u'Discussion MediaWiki',
            'he': u'  ',
            'hu': u'MediaWiki vita',
            'it': u'Discussioni MediaWiki',
            'ja': u'MediaWiki',
            'ko': u'MediaWiki',
            'nl': u'Overleg MediaWiki',
            'pl': u'Dyskusja MediaWiki',
            'pt': u'MediaWiki Discusso',
            'ro': u'Discuie MediaWiki',
            'ru': u' MediaWiki',
            'sv': u'MediaWiki-diskussion',
        }
        self.namespaces[10] = {
            '_default': u'Template',
            'ar': u'',
            'ca': u'Plantilla',
            'de': u'Vorlage',
            'eo': u'ablono',
            'es': u'Plantilla',
            'fi': u'Malline',
            'fr': u'Modle',
            'he': u'',
            'hi': u'',
            'hu': u'Sablon',
            'ko': u'',
            'nl': u'Sjabloon',
            'pl': u'Szablon',
            'pt': u'Predefinio',
            'ro': u'Format',
            'ru': u'',
            'sv': u'Mall',
        }
        self.namespaces[11] = {
            '_default': u'Template talk',
            'ar': u' ',
            'ca': u'Plantilla Discussi',
            'de': u'Vorlage Diskussion',
            'eo': u'ablona diskuto',
            'es': u'Plantilla Discusin',
            'fi': u'Keskustelu mallineesta',
            'fr': u'Discussion Modle',
            'he': u' ',
            'hi': u' ',
            'hu': u'Sablon vita',
            'it': u'Discussioni template',
            'ja': u'Template',
            'ko': u'',
            'nl': u'Overleg sjabloon',
            'pl': u'Dyskusja szablonu',
            'pt': u'Predefinio Discusso',
            'ro': u'Discuie Format',
            'ru': u' ',
            'sv': u'Malldiskussion',
        }
        self.namespaces[12] = {
            '_default': u'Help',
            'ar': u'',
            'ca': u'Ajuda',
            'de': u'Hilfe',
            'eo': u'Helpo',
            'es': u'Ayuda',
            'fi': u'Ohje',
            'fr': u'Aide',
            'he': u'',
            'hu': u'Segtsg',
            'it': u'Aiuto',
            'ko': u'',
            'pl': u'Pomoc',
            'pt': u'Ajuda',
            'ro': u'Ajutor',
            'ru': u'',
            'sv': u'Hjlp',
        }
        self.namespaces[13] = {
            '_default': u'Help talk',
            'ar': u' ',
            'ca': u'Ajuda Discussi',
            'de': u'Hilfe Diskussion',
            'eo': u'Helpa diskuto',
            'es': u'Ayuda Discusin',
            'fi': u'Keskustelu ohjeesta',
            'fr': u'Discussion Aide',
            'he': u' ',
            'hu': u'Segtsg vita',
            'it': u'Discussioni aiuto',
            'ja': u'Help',
            'ko': u'',
            'nl': u'Overleg help',
            'pl': u'Dyskusja pomocy',
            'pt': u'Ajuda Discusso',
            'ro': u'Discuie Ajutor',
            'ru': u' ',
            'sv': u'Hjlpdiskussion',
        }
        self.namespaces[14] = {
            '_default': u'Category',
            'ar': u'',
            'ca': u'Categoria',
            'de': u'Kategorie',
            'eo': u'Kategorio',
            'es': u'Categora',
            'fi': u'Luokka',
            'fr': u'Catgorie',
            'he': u'',
            'hi': u'',
            'hu': u'Kategria',
            'it': u'Categoria',
            'ko': u'',
            'nl': u'Categorie',
            'pl': u'Kategoria',
            'pt': u'Categoria',
            'ro': u'Categorie',
            'ru': u'',
            'sv': u'Kategori',
        }
        self.namespaces[15] = {
            '_default': u'Category talk',
            'ar': u' ',
            'ca': u'Categoria Discussi',
            'de': u'Kategorie Diskussion',
            'eo': u'Kategoria diskuto',
            'es': u'Categora Discusin',
            'fi': u'Keskustelu luokasta',
            'fr': u'Discussion Catgorie',
            'he': u' ',
            'hi': u' ',
            'hu': u'Kategria vita',
            'it': u'Discussioni categoria',
            'ja': u'Category',
            'ko': u'',
            'nl': u'Overleg categorie',
            'pl': u'Dyskusja kategorii',
            'pt': u'Categoria Discusso',
            'ro': u'Discuie Categorie',
            'ru': u' ',
            'sv': u'Kategoridiskussion',
        }
        # Do not add '_default' key into this name space.
        # It cause weird error; Bot says "Please create a file user-config.py, and ...".
        self.namespaces[200] = {
            'wts': u'Tech',
        }
        # Do not add '_default' key into this name space.
        # It cause weird error; Bot says "Please create a file user-config.py, and ...".
        self.namespaces[201] = {
            'wts': u'Tech talk',
        }

        # A few selected big languages for things that we do not want to loop over
        # all languages. This is only needed by the titletranslate.py module, so
        # if you carefully avoid the options, you could get away without these
        # for another wikimedia family.
        self.languages_by_size = ['en','fr','ro']

        # for Wikitravel's /Run subpages check.
        self.wt_script_policy = {
            '_default': u'Script policy',
            'ar': u'Bot',
            'ca': u'Bots',
            'de': u'Regeln fr Skripte',
            'en': u'Script policy',
            'eo': u'Roboto',
            'es': u'Bots',
            'fi': u'Botit',
            'fr': u'Rgles concernant les scripts',
            'he': u'Bot',
            'hi': u'',
            'hu': u'Botok',
            'it': u'Politica script',
            'ja': u'',
            'ko': u' ',
            'nl': u'Richtlijnen scripting',
            'pl': u'Boty',
            'pt': u'Robs',
            'ro': u'Bot',
            'ru': u'',
            'sv': u'Robotar',
            'zh': u'',
            'wts': u'Script policy',
        }

        # String used as separator between interwiki links and the text
        self.interwiki_text_separator = '\r\n'

        # Interwiki sorting order for Wikitravel Shared (wts:)
        self.alphabetic = [
            'ar', 'ca', 'de', 'en', 'eo', 'es', 'fi', 'fr', 'he', 'hi',
            'hu', 'it', 'ja', 'ko', 'nl', 'pl', 'pt', 'ro', 'ru', 'sv',
            'zh', 'wts'
        ]

        # for Wikitravel Shared (wts:)
            # Which languages have a special order for putting interlanguage links,
            # and what order is it? If a language is not in interwiki_putfirst,
            # alphabetical order on language code is used. For languages that are in
            # interwiki_putfirst, interwiki_putfirst is checked first, and
            # languages are put in the order given there. All other languages are put
            # after those, in code-alphabetical order.
        self.interwiki_putfirst = {
            'ar': self.alphabetic,
            'ca': self.alphabetic,
            'de': self.alphabetic,
            'en': self.alphabetic,
            'eo': self.alphabetic,
            'es': self.alphabetic,
            'fi': self.alphabetic,
            'fr': self.alphabetic,
            'he': self.alphabetic,
            'hi': self.alphabetic,
            'hu': self.alphabetic,
            'it': self.alphabetic,
            'ja': self.alphabetic,
            'ko': self.alphabetic,
            'nl': self.alphabetic,
            'pl': self.alphabetic,
            'pt': self.alphabetic,
            'ro': self.alphabetic,
            'ru': self.alphabetic,
            'sv': self.alphabetic,
            'zh': self.alphabetic,
        }

        # for Wikitravel Shared (wts:), Previous DOTM, etc.
            # Allows crossnamespace interwiki linking.
            # Lists the possible crossnamespaces combinations
            # keys are originating NS
            # values are dicts where:
            #   keys are the originating langcode, or _default
            #   values are dicts where:
            #       keys are the languages that can be linked to from the lang+ns, or _default
            #       values are a list of namespace numbers
        self.crossnamespace[0] = {
            '_default': {
                '_default': [4],
                'wts': [4, 14],
            },
        }
        self.crossnamespace[4] = {
            '_default': {
                '_default': [0],
            },
        }
        self.crossnamespace[14] = {
            'wts': {
                '_default': [0], 
            },
        }

    # Wikitravel's bot control by checking /Run subpages.
    def bot_control(self,site):
        import urllib
        from wikipedia import Error,Page
        wt_username = urllib.quote(config.usernames[self.name][site.lang].encode('utf-8'))
        wt_namespace = urllib.quote(self.namespaces[2][site.lang].encode('utf-8'))
        wt_user_run = unicode(wt_namespace) + u':' + unicode(wt_username) + u'/Run'
        wt_page = Page(site, wt_user_run)
        wt_user_run_text = wt_page.get(get_redirect = True)
        wt_namespace = urllib.quote(self.namespaces[4][site.lang].encode('utf-8'))
        wt_script_policy = urllib.quote(self.wt_script_policy[site.lang].encode('utf-8'))
        wt_system_run = unicode(wt_namespace) + u':' + unicode(wt_script_policy) + u'/Run'
        wt_page = Page(site, wt_system_run)
        wt_system_run_text = wt_page.get(get_redirect = True)
        if 'yes' not in wt_user_run_text or 'yes' not in wt_system_run_text:
            raise Error('Bot stopped by /Run page on %s -- %s = %s , %s = %s'
                     % (site.lang, wt_user_run, wt_user_run_text, wt_system_run, wt_system_run_text))
        return True

    def hostname(self,code):
        return 'wikitravel.org'

    # fix for Wikitravel's mediawiki message setting
    def mediawiki_message(self,site):
        # (eo:)
        if site.lang == 'eo':
            site._mediawiki_messages['readonly_lag'] = u'The database has been automatically locked while the slave database servers catch up to the master'
        # (hi:)
        if site.lang == 'hi':
            site._mediawiki_messages['readonly'] = u'Database locked'
            site._mediawiki_messages['readonly_lag'] = u'The database has been automatically locked while the slave database servers catch up to the master'
        return site

    def scriptpath(self, code):
        # for Wikitravel Shared (wts:)
        if code == 'wts':
            return '/wiki/shared'
        else:
            return '/wiki/%s' % code

    def shared_image_repository(self, code):
        return ('wikitravel_shared', 'wikitravel_shared')

    # fix for Wikitravel's user page link.
    def user_page_link(self,site,index):
        site._isLoggedIn[index] = True
        site._userName[index] = config.usernames[self.name][site.lang].encode('utf-8')
        return site

    def version(self, code):
        return "1.11.2"

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.