Обговорення користувача:ReferencerBot

Матеріал з Вікіджерел
Перейти до навігації Перейти до пошуку

Завдання та code snippets щоб не загубилося[ред.]

Використовується Pywikibot.

Створення категорій Робіт та Індексів за роками[ред.]

#!/usr/bin/env python
# -*- coding: utf-8 -*- 

import pywikibot

def create_body_year(template, century, decade, year):
	return (u'{{%s\n |століття = %s\n |десятиліття = %s\n |рік = %s\n}}'
		% (template, century, decade, year))

def create_path_year(template, year):
	return u'Категорія:%s %s-ого' % (template, year)

def create_body_decade(template, century, decade):
	return (u'{{%s\n |століття = %s\n |десятиліття = %s\n |рік = \n}}'
		% (template, century, decade))

def create_path_decade(template, year):
	return u'Категорія:%s %s-их' % (template, year)

site = pywikibot.Site()

'''
summary = u'Створення категорії робіт за роками'
'''

'''
for i in range(1600,2017):
	century = i / 100
	decade = (i % 100) / 10
	year = i % 10
	path = create_path_year(u'Роботи', i)
	page = pywikibot.Page(site, path)
	if not page.exists():
		print 'Create page %s' % i
		content = create_body_year(u'Роботи за датою', century, decade, year)
		page.put(content, summary)
	else:
		print 'Page %s is existing' % i
'''

'''
for i in range(160,202):
	century = i / 10
	decade = i % 10
	year = i * 10
	path = create_path_decade(u'Роботи', year)
	page = pywikibot.Page(site, path)
	if not page.exists():
		print 'Create page %s' % i
		content = create_body_decade(u'Роботи за датою', century, decade)
		page.put(content, summary)
	else:
		print 'Page %s is existing' % i
'''

'''
summary = u'Створення категорії індексів за роками'
'''

'''
for i in range(1600,2017):
	century = i / 100
	decade = (i % 100) / 10
	year = i % 10
	path = create_path_year(u'Індекси', i)
	page = pywikibot.Page(site, path)
	if not page.exists():
		print 'Create page %s' % i
		content = create_body_year(u'Індекси за датою', century, decade, year)
		page.put(content, summary)
	else:
		print 'Page %s is existing' % i
'''

'''
for i in range(160,202):
	century = i / 10
	decade = i % 10
	year = i * 10
	path = create_path_decade(u'Індекси', year)
	page = pywikibot.Page(site, path)
	if not page.exists():
		print 'Create page %s' % i
		content = create_body_decade(u'Індекси за датою', century, decade)
		page.put(content, summary)
	else:
		print 'Page %s is existing' % i
'''

TODO[ред.]

  • Доробити таки категорії за роками з врахуванням WIkidata й виправленням правопису
  • Видалити, там де вони непотрібні, прямі включення категорій по типу Категорія:Автори-А, оскільки вони проставляються шаблоном {{Автор}}