Hauptmenü öffnen

Memory Alpha Nova β

Benutzer:Morn/Modifikationen

< Benutzer:Morn

Auf dieser Seite werden Modifikationen des pyWikipediaBot-Frameworks aufgelistet:


yeargenerator.pyBearbeiten

#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.txtBearbeiten

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]]