User:JackBot

From Wikisource
Jump to: navigation, search

Python.svg Code Crystal Clear mimetype source py.png[edit]

Wikisource-logo.svg
Soft Redirect
This page can be found at wikt:fr:User:JackBot.
Wikisource-logo.svg
Soft Redirect
This page can be found at w:fr:User:JackBot.


#!/usr/bin/env python
# This script creates some categories from a template
 
# Modules importation
import catlib, pagegenerators, os, codecs, urllib
from wikipedia import *
 
# Declaration
language = "en"
family = "wikisource"
mynick = "JackBot"
site = getSite(language,family)
summary = u'[[Wikisource:Bot requests|Categories creations]]'
 
# Wiki modification
def modification(PageHS):
	page = Page(site,PageHS)
	if not page.exists():
		PageEnd = u'__HIDDENCAT__\n[[Category:Volumes of the United States Reports|U0' + PageHS[len(PageHS)-3:len(PageHS)] + u']]'
		#print (PageEnd.encode(config.console_encoding, 'replace'))
		#raw_input("end")
		page.put(PageEnd, summary)
 
 
def lecture(source):
    PagesHS = open(source, 'r')
    while 1:
		PageHS = PagesHS.readline()
		fin = PageHS.find("\t")
		PageHS = PageHS[0:fin]
		if PageHS == '': break
		modification(u'Category:' + PageHS)
    PagesHS.close()
 
 
def crawlerCat(category):
	cat = catlib.Category(site, category)
	pages = cat.articlesList(False)
	for Page in pagegenerators.PreloadingGenerator(pages,100):
		if Page.namespace() == 0: modification(Page.title())
	subcat = cat.subcategories(recurse = True)
	for subcategory in subcat:
		pages = subcategory.articlesList(False)
		for Page in pagegenerators.PreloadingGenerator(pages,100):
			if Page.namespace() == 0: modification(Page.title())
 
def crawlerLink(pagename):
	#pagename = unicode(arg[len('-links:'):], 'utf-8')
	page = wikipedia.Page(site, pagename)
	gen = pagegenerators.ReferringPageGenerator(page)
	#gen =  pagegenerators.NamespaceFilterPageGenerator(gen, namespaces)
	for Page in pagegenerators.PreloadingGenerator(gen,100):
		if Page.namespace() == 1: modification(Page.title())
		elif Page.namespace() == 0: modification(Page.title())
 
def crawlerSearch(pagename):
	gen = pagegenerators.SearchPageGenerator(pagename, namespaces = "1")
	for Page in pagegenerators.PreloadingGenerator(gen,100):
		modification(Page.title())
 
def crawlerRC():
	gen = pagegenerators.RecentchangesPageGenerator()
	for Page in pagegenerators.PreloadingGenerator(gen,100):
		modification(Page.title())
 
def crawlerUser(username):
	gen = pagegenerators.UserContributionsGenerator(username)
	for Page in pagegenerators.PreloadingGenerator(gen,100):
		modification(Page.title())
 
# Launching
TreatmentFile = lecture('articles_list.txt')
'''
TreatmentPage = modification()
TreatmentCategory = crawlerCat(u'')
TreatmentLinks = crawlerLink(u'')
TreatmentSearch = crawlerSearch(u'')
TreatmentRC = crawlerRC(u'')
TreatmentUser = crawlerUser(u'')
'''