Last active
January 12, 2022 03:37
-
-
Save putnik/f61e62c1a0eb6ae27d7ec18fd302804e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf8 | |
# | |
# Copyright (c) 2016 Sergey Leschina (putnik) <[email protected]> | |
# | |
# 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 http://www.wtfpl.net/ 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) | |
else: | |
item = pywikibot.ItemPage(repo) | |
data = { | |
'sitelinks': { | |
page.site.dbName(): sitelink | |
}, | |
'labels': { | |
page.site.lang: { | |
'language': page.site.lang, | |
'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