Benutzer:Morn/Modifikationen
< Benutzer:Morn
Version vom 18. Januar 2006, 13:11 Uhr von imported>Kobi (→families\memoryalpha_family.py: MediaWiki 1.5)
Auf dieser Seite werden Modifikationen des pyWikipediaBot-Frameworks aufgelistet:
families\memoryalpha_family.py
# -*- coding: utf-8 -*- import family # The Memory Alpha family, a set of StarTrek wikis. class Family(family.Family): def __init__(self): family.Family.__init__(self) self.name = 'memoryalpha' self.langs = { 'de': None, 'en': None, 'fr': None, 'nl': None, 'sv': None, } # Most namespaces are inherited from family.Family. self.namespaces[4] = { '_default': u'Memory Alpha', } self.namespaces[5] = { '_default': u'Memory Alpha talk', 'de': u'Memory Alpha Diskussion', 'fr': u'Discussion Memory Alpha', 'nl': u'Overleg Memory Alpha', 'sv': u'Memory Alphadiskussion', } # 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 wiki family. self.biglangs = ['en', 'de', 'nl', 'sv', 'fr'] # attop is a list of languages that prefer to have the interwiki # links at the top of the page. self.interwiki_attop = [] # on_one_line is a list of languages that want the interwiki links # one-after-another on a single line self.interwiki_on_one_line = [] # String used as separator between interwiki links and the text self.interwiki_text_separator = '' # Similar for category self.category_attop = [] # on_one_line is a list of languages that want the category links # one-after-another on a single line self.category_on_one_line = ['en', 'fr', 'de', 'nl', 'sv'] # String used as separator between category links and the text self.category_text_separator = '' def hostname(self,code): return 'www.memory-alpha.org' def path(self, code): return '/%s/index.php' % code def version(self, code): return "1.5"
yeargenerator.py
#coding: iso-8859-1 """ This script is based on Andre Engels' "pagefromfile.py" and reads a template saved in "yeartemplate.txt" or another file specified below. It is intented to set up the individual year entries in Memory Alpha. Currently the arguments given below are needed, there is no fallback procedure written yet: Specific arguments: -start:xxx Specify the year to start with -end:xxx Specify the year that not created anymore-utf The input file is UTF-8 Note the '-utf' option is necessary on older versions of Windows; whether it's necessary or useful on Windows XP and/or other operating systems is unclear. """ # # (C) Andre Engels, 2004 # formatted to match Memory Alpha (www.memory-alpha.org) # by Jan Hendrik "Kobi" Kobarg # # Distribute under the terms of the PSF license. # import wikipedia import re, sys msg={ 'en':u'Automated import of articles', 'nl':u'Geautomatiseerde import', 'pt':u'Importa�o autom�ica de artigo', 'de':u'Robot: Automatische Seitenerstellung' } # The following are the standard settings for an empty Memory Alpha language # first year is 1900, last year is 2379. # Template is stored in "yeartemplate.txt". startyear = int(1900) endyear = int(2380) filename = "yeartemplate.txt" include = False utf = False def putpage(t, year): try: year_before = str(year - 1) year_after = str(year + 1) if year % 100 == 0: century = str(year / 100) else: century = str(year / 100 + 1) decade = str(year / 10) page = t %(year_before, century, decade, year_after, str(year), str(year), str(year), str(year)) title = str(year) pl = wikipedia.Page(mysite,wikipedia.UnicodeToAsciiHtml(title)) print "\n==== Processing %s ====" %title if pl.exists(): print "Page %s already exists, not adding!"%title else: pl.put(page, comment = commenttext, minorEdit = False) except AttributeError: print "No title found - skipping a page." return def main(): text = [] if utf: f=codecs.open(filename,'rb',encoding='utf-8') else: f=open(filename,'r') for line in f.readlines(): text.append(line) text=''.join(text) for year in range(startyear, endyear): putpage(text, year) for arg in sys.argv[1:]: arg = wikipedia.argHandler(arg, 'pagefromfile') if arg: if arg.startswith("-start:"): startyear=int(arg[7:]) elif arg.startswith("-end:"): endyear=int(arg[5:]) elif arg.startswith("-file:"): filename=arg[6:] elif arg=="-include": include = True elif arg=="-utf": import codecs utf = True else: print "Disregarding unknown argument %s."%arg mysite = wikipedia.getSite() commenttext = wikipedia.translate(mysite,msg) try: main() except: wikipedia.stopme() raise else: wikipedia.stopme()
yeartemplate.txt
file needed to make yeargenerator work:
- German version
== Ereignisse == * ''keine bisher'' {| class="browser" |- | class="prev" | [[%s]] | class="topic" | [[%s. Jahrhundert]]<br/>[[%s0er]] | class="next" | [[%s]] |} [[Kategorie:Zeitlinie]] [[en:%s]] [[fr:%s]] [[nl:%s]] [[sv:%s]]