unusedfiles.py :  » Network » Python-Wikipedia-Robot-Framework » pywikipedia » 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 » unusedfiles.py
#!/usr/bin/python
# -*- coding: utf-8  -*-
"""
This bot appends some text to all unused images and other text to the respective uploaders.

Parameters:

-always     Don't be asked every time.

"""

#
# (C) Leonardo Gregianin, 2007
# (C) Filnik, 2008
#
# Distributed under the terms of the MIT license.
#
__version__ = '$Id: unusedfiles.py 5612 2008-06-23 03:06:44Z leogregianin $'
#

import wikipedia
import pagegenerators
import sys

#***** SETTINGS *******#
#                      #
#   - EDIT BELOW -     #
#                      #
#**********************#

comment = {
    'ar': u' ',
    'en': u'images for elimination',
    'he': u' ',
    'it': u'Bot: segnalo immagine orfana da eliminare',
    'pt': u'Bot: marcao de imagens para eliminao',
    }

template_to_the_image = {
    'en': u'\n\n{{subst:No-use2}}',
    'it': u'\n\n{{immagine orfana}}',
    }
template_to_the_user = {
    'en': u'\n\n{{img-sem-uso|%s}}',
    'it': u'\n\n{{Utente:Filbot/Immagine orfana}}',
    }
except_text = {
    'en': u'<table id="mw_metadata" class="mw_metadata">',
    'it': u'<table id="mw_metadata" class="mw_metadata">',
    }

#***** SETTINGS *******#
#                      #
#   - EDIT ABOVE -     #
#                      #
#**********************#

def appendtext(page, apptext, always):
    try:
        text = page.get()
    except wikipedia.IsRedirectPage:
        return
    # Here go edit text in whatever way you want. If you find you do not  (he meant "Here you can go editing...")
    # want to edit this page, just return
    text += apptext;
    if text != page.get():
        wikipedia.showDiff(page.get(),text)
        choice = wikipedia.inputChoice(u'Do you want to accept these changes?', ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
        if choice == 'a':
            always = True
            choice = 'y'
        if choice == 'y':
            msg = wikipedia.translate(wikipedia.getSite(), comment)
            page.put(text, msg)

def main():
    always = False
    for arg in wikipedia.handleArgs():
        if arg == '-always':
            always = True

    mysite = wikipedia.getSite()
    # If anything needs to be prepared, you can do it here
    template_image = wikipedia.translate(wikipedia.getSite(), template_to_the_image)
    template_user = wikipedia.translate(wikipedia.getSite(), template_to_the_user)
    except_text_translated = wikipedia.translate(wikipedia.getSite(), except_text)
    basicgenerator = pagegenerators.UnusedFilesGenerator()
    generator = pagegenerators.PreloadingGenerator(basicgenerator)
    for page in generator:
        wikipedia.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"% page.title())
        if except_text_translated not in page.getImagePageHtml() and 'http://' not in page.get():
            wikipedia.output(u'\n' + page.title())
            appendtext(page, template_image, always)
            uploader = page.getFileVersionHistory().pop()[1]
            usertalkname = u'User Talk:%s' % uploader
            usertalkpage = wikipedia.Page(mysite,usertalkname)
            msg2uploader = template_user % page.title()
            appendtext(usertalkpage,msg2uploader, always)

if __name__ == "__main__":
    try:
        main()
    finally:
        wikipedia.stopme()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.