Purple exclamation mark.svg Planning the future of Botwiki! - Help us bring Botwiki up to date, contribute to our strategy discussion, add bot scripts, and contribute manuals, guides, and tutorials! Almost anything related to bots, particularly those used to edit mediawiki, is welcome.

Red exclamation mark.svg UNABLE TO EDIT? - We've experienced attacks by spambots lately and now require you to confirm your e-mail before you can edit (go to your preferences, enter an e-mail address, and request a confirmation e-mail, then go to your e-mail and click on the confirmation link). We also require new accounts to make a few edits and wait a few minutes before before you can create a page; however, if this is a problem contact us in #botwiki and we can manually confirm your account. Sorry for the inconvenience.

Python:Count.py

From Botwiki
Jump to: navigation, search
                            python count.py Pagename
Example:
                            python count.py Chile
# -*- coding: utf-8  -*-
#
# GPL 
# Xexito
#
 
import wikipedia
import os, sys
import re
 
def main():
    singlePageTitleParts = []
    for arg in wikipedia.handleArgs():
        singlePageTitleParts.append(arg)
 
    pageTitle = " ".join(singlePageTitleParts)
    page = wikipedia.Page(wikipedia.getSite(), pageTitle) 
    print page
    try:
        text = page.get()
        count = len(re.findall('\[\[(.*?)\]\]',text,re.I)) 
        countimages = len(re.compile('\[\[Image', re.IGNORECASE).findall(text, re.I)) 
        newestnumber = count - countimages 
        print newestnumber
    except wikipedia.Error():
        wikipedia.output(u"Error, skipping")
 
if __name__ == '__main__':
    try:
        main()
    except:
        wikipedia.stopme()
        raise
    else:
        wikipedia.stopme()
Personal tools
Share