User:SoxBot/source

This code was taken from Botwiki, modified to allow for emergency shutoff. Thanks to valhallasw for fixing the disambig page. This is current as of 4/13/2008

This code was taken from Botwiki, modified to allow for emergency shutoff. Thanks to valhallasw for fixing the disambig page. This is current as of 4/13/2008

#!/usr/bin/python
# -*- coding: utf-8 -*-
 
#
# (C) Pietrodn, it.wiki 2006-2007
# (C) Filnik, it.wiki 2007
#
# Distributed under the terms of the MIT license.
#
__version__ = '$Id:$'
#
 
import wikipedia
import re
import time
 
from pagegenerators import AllpagesPageGenerator
 
commento = {
           'en':u'Bot: Orphan page, add template',
           'it':u'Bot: Voce orfana, aggiungo template {{O}}',
           }

commenttodisambig = {
           'en':u'Bot: This page is a disambig',
           'it':u'Bot: Voce orfana, aggiungo template {{O}}',
           }
 
Template = {
            'en':u'{{Orphan|date={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}<!-- Automatically added by User:SoxBot. If this is an error, please contact User:Soxred93 -->}}',
            'it':u'{{O||mese={{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}}}',
            }
 
def main():
    while 1 == 1:
        global commento; global Template
     
        args = wikipedia.handleArgs()
        for arg in wikipedia.handleArgs():
            if arg == '-all':
                allfunction = True
        wikiSite = wikipedia.getSite()  
        comment = wikipedia.translate(wikiSite, commento)
        commentdisambig = wikipedia.translate(wikiSite, commenttodisambig)
        template = wikipedia.translate(wikiSite, Template)
        allfunction = False
        wikipediasite = wikipedia.getSite('en', 'wikipedia')
        enable = wikipedia.Page(wikipediasite, 'User:SoxBot/Run')
        getenable = enable.get()
        disambigpage = wikipedia.Page(wikipediasite, 'User:SoxBot/disambig')
        disambigtext = disambigpage.get()
        if getenable != 'enable':
            wikipedia.output('The bot is disabled')
            wikipedia.stopme()
        else:
            for i in wikiSite.lonelypages(number = 1000, repeat = False):
                #if i.title()[0] in ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L']:
                    #continue
                if i.isRedirectPage():
                    continue
                refs = i.getReferences()
                refsList = list()
                for j in refs:
                    if j == None:
                        continue
                    refsList.append(j)
                if getenable != 'enable':
                    wikipedia.output('The bot is disabled')
                    wikipedia.stopme()
                elif refsList != []:
                    continue
                elif refsList == None:
                    continue # FIXME: ????
                else:
                    try:
                        oldtxt = i.get()
                    except wikipedia.NoPage:
                        wikipedia.output("%s doesn't exist! Skip.." % i.title())
                        continue
                    except wikipedia.IsRedirectPage:
                        wikipedia.output("%s is a redirect! Skip..." % i.title())
                    if getenable != 'enable':
                        wikipedia.output('The bot is disabled')
                        wikipedia.stopme()
                    elif '{{orphan}}' in oldtxt.lower() or '{{orphan|' in oldtxt.lower() or '{{wi|' in oldtxt.lower() or '{{soft redirect|' in oldtxt.lower() or '{{wi}}' in oldtxt.lower():
                        wikipedia.output('This page already has the template or a wiktionary redirect, skipping')
                        continue
                    elif i.isDisambig():
                        wikipedia.output('Disambig page...')
                        disambigtext = disambigtext + ' [[' + i.title() + ']]'
                        disambigpage.put(disambigtext, commentdisambig)
                        continue
                    else:
                        newtxt = template + '\n' + oldtxt
                        wikipedia.output("\t\t>>> %s <<<" % i.title())
                        wikipedia.showDiff(oldtxt, newtxt)
                        choice = 'y'
                        try:
                            i.put(newtxt, comment)      
                        except wikipedia.EditConflict:
                            wikipedia.output('Edit Conflict! Skip...')
                        except wikipedia.ServerError:
                            wikipedia.output('Server error')


if __name__ == '__main__':
    try:
        main()
    finally:
        wikipedia.stopme()

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.