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:Take cats from enwiki.py

From Botwiki
Jump to: navigation, search
#!/usr/bin/python
# -*- coding: utf-8  -*-
"""
Simple bot for DarkAppo it.wiki, I want to use it also to teach something ;-)
"""
#
# (C) Filnik, 2007
#
# Distributed under the terms of the MIT license.
#
__version__ = '$Id: $'
#
import wikipedia, catlib
 
def main():
    # Load the english site
    site_en = wikipedia.getSite('en', 'wikipedia')
    # Load the italian site
    site_it = wikipedia.getSite('it', 'wikipedia')
    # Define the category to take
    name_cat = "Category:Japanese_manga magazines"
    # Define the cat giving informations about what's the site and what's his name
    cat = catlib.Category(site_en, name_cat)
    # Define the first part of the text to add (the title)
    newtext = '== %s ==\n\n' % name_cat # Es: == Category: Rock ==
    # We have x pages in the category, in every page of the category, do that:
    for page in cat.articles():
        # Advise that you're working on the page (same as print, but it use the right encoding)
        wikipedia.output("Working on %s..." % page.title())
        # the page variable is a "class", page.title() function returns the name of the page
        ita_tl = page.title()
        en_tl = '[[:en:%s|en]]' % ita_tl
        # Es: * [[Page]] ([[:en:Page|en]])\n
        modello = '* [[%s]] (%s)\n' % (ita_tl, en_tl)
        # Add the model define to the text that we'll add
        newtext += modello
    # Define the report_page giving the italian site and it's name
    report_page = wikipedia.Page(site_it, 'Utente:DarkAp89/Sandbox/Filbot')
    # Put the data using the function put
    report_page.put(newtext, 'Bot: aggiunto testo chiesto da DarkAppo')
 
if __name__ == "__main__":
    try:
        main()
    finally:
        wikipedia.stopme()
Personal tools
Share