def add_category(page): if mavri.content_of_page(wiki, page): ENpage = mavri.wbgetlanglink(mavri.wikibase_item(wiki, page), 'enwiki') if ENpage: print ENpage ENcat = mavri.categories_on_enwiki(ENpage) print ENcat cat_to_add = [] for cat in ENcat: ncat = mavri.wbgetlanglink(mavri.wikibase_item('en.wikipedia', 'Category:' + cat), wikiS) if ncat != '': cat_to_add.insert(0, ncat) print cat_to_add content = mavri.content_of_page(wiki, page) appendtext = '' for cat in cat_to_add: if re.findall(r'\[\[\s?' + cat + '\s?\|?[^\[\]]*\]\]', content) == []: appendtext += '\n[[' + cat + ']]' if appendtext: content += appendtext content = re.sub(r'\{\{\s?[Kk]ategorisiz[^\}]*\}\}\s?\n?', '', content) content = re.sub(r'\{\{\s?[Uu]ncategorized[^\}]*\}\}\s?\n?', '', content) diff = mavri.change_page(wiki, page, content, '++' + catNS, xx).json()['edit']['newrevid'] mavri.appendtext_on_page(wiki, 'Kullanıcı:Mavrikant_Bot/Log/Kategorisiz', '\n# [[Special:Diff/' + str(diff) + '|' + page + ']]', '[[Special:Diff/' + str(diff) + '|' + page + ']]', xx)
def add_category(page): print page content = mavri.content_of_page(wiki, page) if content: if re.findall(r'\[\[\s?' + catNS + '[^\]]*\]\]', content) != []: content = re.sub(r'\{\{\s?[Kk]ategorisiz[^\}]*\}\}\s?\n?', '', content) content = re.sub(r'\{\{\s?[Uu]ncategorized[^\}]*\}\}\s?\n?', '', content) return mavri.change_page(wiki, page, content, '- Kategorisiz Şablonu', xx) entity = mavri.wikibase_item(wiki, page) langs = mavri.wbgetlangsofentity(entity) langs = re.findall(r'\'([a-z]{2,3})wiki\'', str(langs)) if 'tr' in langs: langs.remove('tr') print langs if langs: lang = random.choice(langs) Swiki = lang + '.wikipedia' Slang = lang + 'wiki' print Swiki print Slang Spage = mavri.wbgetlanglink(entity, Slang) print Spage Scat = mavri.categories_on_page(Swiki, Spage) print Scat ScatNS = requests.get( 'https://' + Swiki + '.org/w/api.php?format=json&utf8=&action=query&meta=siteinfo&siprop=namespaces' ).json()['query']['namespaces']['14']['*'] cat_to_add = [] for cat in Scat: ncat = mavri.wbgetlanglink( mavri.wikibase_item(Swiki, ScatNS + ':' + cat), 'trwiki') print cat + ' -> ' + ncat if ncat != '': cat_to_add.insert(0, ncat) print cat_to_add content = mavri.content_of_page(wiki, page) appendtext = '' for cat in cat_to_add: if re.findall(r'\[\[\s?' + cat + '\s?\|?[^\[\]]*\]\]', content) == []: appendtext += '\n[[' + cat + ']]' NUM = str(len(cat_to_add)) if appendtext: content += appendtext content = re.sub(r'\{\{\s?[Kk]ategorisiz[^\}]*\}\}\s?\n?', '', content) content = re.sub(r'\{\{\s?[Uu]ncategorized[^\}]*\}\}\s?\n?', '', content) diff = \ mavri.change_page(wiki, page, content, '+ ' + NUM + catNS + ', Kaynak=' + Slang, xx).json()['edit'][ 'newrevid'] mavri.appendtext_on_page( wiki, 'Kullanıcı:Mavrikant_Bot/Log/Kategorisiz', '\n# [[Special:Diff/' + str(diff) + '|' + page + ']] (+ ' + NUM + catNS + ', Kaynak=' + Slang + ')', '[[Special:Diff/' + str(diff) + '|' + page + ']] (+ ' + NUM + catNS + ', Kaynak=' + Slang + ')', xx) else: content = mavri.content_of_page(wiki, page) if re.findall(r'\[\[\s?' + catNS + '[^\]]*\]\]', content) == [] and re.findall( r'\{\{\s?[Kk]ategorisiz[^\}]*\}\}', content) == []: content = re.sub(r'\{\{\s?[Kk]ategorisiz[^\}]*\}\}\s?\n?', '', content) content = re.sub( r'\{\{\s?[Uu]ncategorized[^\}]*\}\}\s?\n?', '', content) diff = mavri.change_page( wiki, page, content + '\n\n{{Kategorisiz|{{kopyala:CURRENTMONTHNAME}} {{kopyala:CURRENTYEAR}}}} ', '+ Kategorisiz Şablonu', xx).json()['edit']['newrevid'] mavri.appendtext_on_page( wiki, 'Kullanıcı:Mavrikant_Bot/Log/Kategorisiz', '\n# [[Special:Diff/' + str(diff) + '|' + page + ']] (Kategorisiz)', '[[Special:Diff/' + str(diff) + '|' + page + ']] (Kategorisiz)', xx) else: content = mavri.content_of_page(wiki, page) if re.findall(r'\[\[\s?' + catNS + '[^\]]*\]\]', content) == [] and re.findall( r'\{\{\s?[Kk]ategorisiz[^\}]*\}\}', content) == []: content = re.sub(r'\{\{\s?[Kk]ategorisiz[^\}]*\}\}\s?\n?', '', content) content = re.sub(r'\{\{\s?[Uu]ncategorized[^\}]*\}\}\s?\n?', '', content) diff = mavri.change_page( wiki, page, content + '\n\n{{Kategorisiz|{{kopyala:CURRENTMONTHNAME}} {{kopyala:CURRENTYEAR}}}} ', '+ Kategorisiz Şablonu', xx).json()['edit']['newrevid'] mavri.appendtext_on_page( wiki, 'Kullanıcı:Mavrikant_Bot/Log/Kategorisiz', '\n# [[Special:Diff/' + str(diff) + '|' + page + ']] (Kategorisiz)', '[[Special:Diff/' + str(diff) + '|' + page + ']] (Kategorisiz)', xx)
from bs4 import BeautifulSoup import requests import mavri import re xx= mavri.login('www.wikidata','Mavrikant') wiki='https://tr.wikipedia.org' template='Şablon:TFF futbolcu' value= r'\{\{TFF futbolcu\|(\d*)\}\}' property= 'P2448' ticontinue = '' while ticontinue != 'DONE': allpages= requests.get(wiki+'/w/api.php?action=query&utf8&format=json&tiprop=title&titles='+template+'&prop=transcludedin&tilimit=500&ticontinue='+str(ticontinue)) try: ticontinue =allpages.json()['continue']['ticontinue'] except: ticontinue = 'DONE' for page in allpages.json()['query']['pages'].itervalues().next()['transcludedin']: title = page['title'] content = mavri.content_of_page('tr.wikipedia',title) id = re.findall(value, content)[0] entity= mavri.wikibase_item('tr.wikipedia',title) if mavri.wbgetclaims(entity, property).text == '{"claims":{}}': mavri.wbcreateclaim(entity,property,'value', str(id), xx) exit(0)