refcheck.py :  » Network » Python-Wikipedia-Robot-Framework » pywikipedia » archive » 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 » archive » refcheck.py
#!/usr/bin/python
"""
##################################################
This script with all its function has been merged
to templatecount.py. please use:

  templatecount.py -count

xqt 2009-10-30
##################################################
This script checks references to see if they are properly formatted.  Right now
it just counts the total number of transclusions of any number of given templates.

NOTE: This script is not capable of handling the <ref></ref> syntax. It just
handles the {{ref}} syntax, which is still used, but DEPRECATED on the English
Wikipedia.

Syntax: python refcheck.py command [arguments]

Command line options:

-count        Counts the number of times each template (passed in as an argument)
              is transcluded.
-namespace:   Filters the search to a given namespace.  If this is specified
              multiple times it will search all given namespaces

Examples:

Counts how many time {{ref}} and {{note}} are transcluded in articles.

     python refcheck.py -count ref note -namespace:0

"""
__version__ = '$Id: refcheck.py 7574 2009-10-30 09:51:24Z xqt $'

import wikipedia, config
import replace, pagegenerators
import re, sys, string

templates = ['ref', 'note', 'ref label', 'note label', 'reflist']

class ReferencesRobot:
    #def __init__(self):
        #Nothing
    def countRefs(self, templates, namespaces):
        mysite = wikipedia.getSite()
        mytpl  = mysite.template_namespace()+':'
        finalText = [u'Number of transclusions per template',u'------------------------------------']
        for template in templates:
            gen = pagegenerators.ReferringPageGenerator(wikipedia.Page(mysite, mytpl + template), onlyTemplateInclusion = True)
            if namespaces:
                gen = pagegenerators.NamespaceFilterPageGenerator(gen, namespaces)
            count = 0
            for page in gen:
                count += 1
            finalText.append(u'%s: %d' % (template, count))
        for line in finalText:
            wikipedia.output(line)

def main():
    doCount = False
    argsList = []
    namespaces = []
    for arg in wikipedia.handleArgs():
        if arg == '-count':
            doCount = True
        elif arg.startswith('-namespace:'):
            try:
                namespaces.append(int(arg[len('-namespace:'):]))
            except ValueError:
                namespaces.append(arg[len('-namespace:'):])
        else:
            argsList.append(arg)

    if doCount:
        robot = ReferencesRobot()
        if not argsList:
           argsList = templates
        choice = ''
        if 'reflist' in argsList:
            wikipedia.output(u'NOTE: it will take a long time to count "reflist".')
            choice = wikipedia.inputChoice(u'Proceed anyway?', ['yes', 'no', 'skip'], ['y', 'n', 's'], 'y')
            if choice == 's':
                argsList.remove('reflist')
        if choice <> 'n':
            robot.countRefs(argsList, namespaces)
    else:
        wikipedia.showHelp('refcheck')

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.