Skip to content

Instantly share code, notes, and snippets.

@putnik putnik/
Last active Jul 24, 2018

What would you like to do?
# coding: utf8
# Copyright (c) 2016 Sergey Leschina (putnik) <>
# This work is free. You can redistribute it and/or modify it under the
# terms of the Do What The Fuck You Want To Public License, Version 2,
# as published by Sam Hocevar. See for more details.
import pywikibot
from pywikibot import pagegenerators
site = pywikibot.Site('ru', 'wikipedia')
repo = site.data_repository()
def process_bagde(element_id, ru_name, en_name):
summary = 'Add ' + en_name + ' badge for ruwiki'
category = pywikibot.Category(site, 'Категория:Википедия:' + ru_name + ' без отметки статуса в Викиданных')
generator = pagegenerators.CategorizedPageGenerator(category)
for page in generator:
title = page.title()
print('[%s] %s' % (en_name, title))
sitelink = {'site': 'ruwiki', 'title': title, 'badges': [ element_id ]}
item = pywikibot.ItemPage.fromPage(page, True)
if item.exists():
item.setSitelink(sitelink=sitelink, summary=summary)
item = pywikibot.ItemPage(repo)
data = {
'sitelinks': { sitelink
'labels': { {
'value': title
item.editEntity(data, summary=summary)
process_bagde('Q17559452', 'Добротные статьи', 'QA')
process_bagde('Q17580674', 'Избранные порталы', 'FP')
process_bagde('Q17506997', 'Избранные списки', 'FL')
process_bagde('Q17437796', 'Избранные статьи', 'FA')
process_bagde('Q17437798', 'Хорошие статьи', 'GA')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.