Esempio n. 1
0
def do(month):
    if debug:
        page='Robottest'

    for day in range(1,31+1):
        print day
        page="%d %s"%(day,month)
        cappage="%d_%s"%(day,month.capitalize())

        do=1
        
        # Only if the page exists
        try:        
            text=wikipedia.getPage(mylang,page)
        except wikipedia.NoPage:
            print "Page does not exist"
            do=0
        
        # Only if the redir-page does not exist
        try:        
            text=wikipedia.getPage(mylang,cappage)
        except wikipedia.NoPage:
            pass
        else:
            print "Redirect exists"
            do=0

        if do==0:
            continue

        text="#redirect [[%s]]"%page

        status,reason,data=wikipedia.putPage(mylang,cappage,text)
        print status,reason
Esempio n. 2
0
#
# Distribute under the terms of the PSF license
#
__version__='$Id: test.py,v 1.11 2004/01/04 20:12:14 hooft Exp $'
#
import re,sys,wikipedia

if 0:
    pl=wikipedia.PageLink('af','1832')
    print pl.get()
elif 0:
    wikipedia.langs={'test':'test.wikipedia.org'}

    text=wikipedia.getPage('test','Robottest')
    text=text+'\nrobot was here\n'
    status,reason,data=wikipedia.putPage('test','Robottest',text)
    print status,reason
elif 1:
    for arg in sys.argv[1:]:
        if wikipedia.argHandler(arg):
            pass
        else:
            print "Unknown argument",arg
            sys.exit(1)
    if wikipedia.checkLogin():
        print "Logged in ("+wikipedia.mylang+".wikipedia.org)"
    else:
        print "Not logged in ("+wikipedia.mylang+".wikipedia.org)"
elif 0:
    x1='\xb1\xb3\xbf'
    import codecs
Esempio n. 3
0
def do(year):
    page=ystr(year)
    if debug:
        page='Robottest'

    try:        
        text=wikipedia.getPage(mylang,page)
    except wikipedia.NoPage:
	return

    orgtext=text
    
    # Replace all of these by the standardized formulae

    text=R4.sub("\r\n",text)
    text=R5.sub("\r\n\r\n",text)
    text=R10.sub("\r\n",text)
    text=R10.sub("\r\n",text)
    text=R10.sub("\r\n",text)
    text=R11.sub("\r\n",text)
    text=R12.sub("\r\n",text)
    #if R6.search(text):
        #m=R6.search(text).group(0)
        #print "MATCH:", len(m),repr(m)
    text=R6.sub("\r\n",text)
    text=R7.sub("\r\n",text)
    text=R8.sub("\r\n",text)
    text=R9.sub("\r\n",text)
    # Must be last
    text=R3.sub("\r\n"+header(year)+"\r\n'''Gebeurtenissen''':\r\n",text)
    text=R1.sub("\r\n\r\n----\r\n'''Geboren''':\r\n",text)
    text=R2.sub("\r\n\r\n----\r\n'''Overleden''':\r\n",text)

    if debug:
        print text
    else:
        if orgtext==text or (orgtext[:-1]==text[:-2]):
            print "Identical, no change"
            return
        print "="*70
        if 0:
            f=open('/tmp/wik.in','w')
            f.write(orgtext)
            f.close()
            f=open('/tmp/wik.out','w')
            f.write(text)
            f.close()
            f=os.popen('diff -u /tmp/wik.in /tmp/wik.out','r')
            print f.read()
        else:
            print text
        print "="*70
        if ask:
            answer=raw_input('submit y/n ?')
        else:
            answer='y'
        if answer=='y':
            status,reason,data=wikipedia.putPage(mylang,page,text)
            print status,reason
        else:
            print "===Not changed==="