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)
# !/usr/bin/python import requests from bs4 import BeautifulSoup import mavri xx = mavri.login('tr.wikipedia', 'Mavrikant') trwiki = 'https://tr.wikipedia.org' nextpage = '/w/index.php?title=%C3%96zel:BekleyenDe%C4%9Fi%C5%9Fiklikler&limit=100&namespace=&level=-1&size=0' while nextpage != 'DONE': soup = BeautifulSoup(requests.get(trwiki + nextpage).text, 'html.parser') try: nextpage = soup.findAll("a", {"class": "mw-nextlink"})[0].get('href') except: nextpage = 'DONE' for line in soup.find("div", {"id": "mw-content-text"}).ul.find_all('li'): title = line.find_all('a')[2].get('title') link = line.find_all('a')[2].get('href') #print title FARK = requests.get(trwiki + link, cookies=xx.cookies).text if FARK.find('<div class="mw-diff-empty">(Fark yok)</div>') != -1: diff = FARK.split('<input id="mw-fr-input-oldid" type="hidden" value="')[1].split('" name="oldid" />')[0] RAPOR = '[[Special:Diff/' + str(diff) + ' | ' + title + ']]' mavri.review_diff('tr.wikipedia', diff, xx) mavri.appendtext_on_page('tr.wikipedia', 'Kullanıcı:Mavrikant/Log/FarkYok', '\n# '+RAPOR, RAPOR, xx) exit(0)
# -*- coding: utf-8 -*- # !/usr/bin/python import mavri xx = mavri.login('tr.wikipedia', 'Mavrikant Bot') print xx.text print mavri.appendtext_on_page('tr.wikipedia', 'Vikipedi:Deneme tahtası', 'test', 'test', xx).text exit(0)
import mavri wiki = 'tr.wikipedia' xx = mavri.login(wiki, 'Mavrikant') content = requests.get('https://tr.wikipedia.org/wiki/%C3%96zel:BozukY%C3%B6nlendirmeler').text soup = BeautifulSoup(content, 'html.parser') for line in soup.find("div", {"id": "mw-content-text"}).ol.find_all('li'): page = line.find_all('a')[0].get('title') print page pagetext = mavri.content_of_page(wiki, page) print pagetext if pagetext != '': sil = re.findall('\{\{\s?[Ss]il[^\}]*\}\}', pagetext) print sil redirect = re.findall('\[\[\s?([^\]]*)\s?\]\]', pagetext) print redirect if redirect: redirectpagetext = mavri.content_of_page(wiki, redirect[0]) print redirectpagetext if redirectpagetext == '' and not sil: HS = '{{Sil | Y1. Var olmayan sayfalara olan yönlendirmeler silinebilir. --~~~~}}\n\n' mavri.change_page('tr.wikipedia', page, HS + pagetext, '+ Hızlı sil, var olmayan sayfaya yönlendirme', xx) mavri.appendtext_on_page('tr.wikipedia', 'Kullanıcı:Mavrikant/Log/BrokenRedirects', '\n* [[' + page + ']] -> [[' + redirect[0] + ']]', '[[' + page + ']] -> [[' + redirect[0] + ']]', xx) exit(0)
regex = r"\d{2}\.\d{2}\,\s\d{1,2}\s\w+\s\d{4}\s\(UTC\)" matches = re.finditer(regex, content2.decode('UTF-8'), re.MULTILINE) signatureTimes = [] for matchNum, match in enumerate(matches, start=1): date_time_obj = datetime.strptime(str(match.group()), '%H.%M, %d %B %Y (%Z)') signatureTimes.append(date_time_obj) youngest = max(dt for dt in signatureTimes if dt < now) youngestDiff = now - youngest if diff.total_seconds( ) > 60 * 60 * 24 * 15 and youngestDiff.total_seconds( ) > 60 * 60 * 24: if pinned == False: summary = 'Üzerinden 15 gün geçen talep arşivleniyor - ' + summary_ek archiveSummary = 'Sonuçlandırılan talep arşivleniyor - ' + summary_ek mavri.appendtext_on_page(wiki, archivePage, "\n" + content, archiveSummary, xx) mavri.section_clear(wiki, title, section, summary, xx) else: print('Tartışma sabitlenmiş, arşivlenmiyor.') else: print('Gerekli süre geçmemiş, arşivlenmiyor.') section += 1 else: section = 1 time.sleep(120)
signatureTimes.append(date_time_obj) youngest = max(dt for dt in signatureTimes if dt < now) youngestDiff = now - youngest archiveContent = mavri.content_of_page( wiki, archivePage.decode('UTF-8')) preArchiveContent = mavri.content_of_page( wiki, preArchivePage.decode('UTF-8')) hasBeenPreArchived = '{{Vikipedi:Silinmeye aday sayfalar/' + page + '}}' in preArchiveContent hasBeenArchived = '{{Vikipedi:Silinmeye aday sayfalar/' + page + '}}' in archiveContent if hasBeenArchived == False and hasBeenPreArchived == False: append = '\n' + '{{Vikipedi:Silinmeye aday sayfalar/' + page + '}}' archiveSummary = 'Arşiv sayfalarında bulunmayan [[Vikipedi:Silinmeye_aday_sayfalar/' + page + '|SAS alt sayfası]] arşivlere ekleniyor - ' + summary_ek mavri.appendtext_on_page(wiki, archivePage.decode('UTF-8'), append, archiveSummary, xx) print(page + ' arşiv sayfasına eklendi.') if pinned == False: if resolved and youngestDiff.total_seconds() >= 3600: summary = '[[Vikipedi:Silinmeye_aday_sayfalar/' + page + '|Sonuçlandırılan SAS]] arşivleniyor - ' + summary_ek print(page + " SAS sayfasından kaldırılıyor.") newContent = content.replace( "{{Vikipedi:Silinmeye aday sayfalar/" + page + "}}", "") newContent = re.sub(r"^[ \t]*$\r?\n", "", newContent, flags=re.MULTILINE) mavri.change_page(wiki, title, newContent, summary, xx) else:
trwiki = 'https://tr.wikipedia.org' nextpage = '/w/index.php?title=%C3%96zel:BekleyenDe%C4%9Fi%C5%9Fiklikler&limit=100' while nextpage != 'DONE': soup = BeautifulSoup(requests.get(trwiki + nextpage, cookies=xx.cookies).text, 'html.parser') try: nextpage = soup.findAll("a", {"class": "mw-nextlink"})[0].get('href') except: nextpage = 'DONE' for line in soup.find("div", {"id": "mw-content-text"}).ul.find_all('li'): incele = line.find_all('a')[2].get('href') title = line.find_all('a')[0].get('title') incele_text = requests.get(trwiki + incele, cookies=xx.cookies).text if incele_text.find('diff-multi') == -1: diff = incele_text.split('<input id="mw-fr-input-oldid" type="hidden" value="')[1].split('"')[0] damaging = \ requests.get('http://ores.wmflabs.org/scores/trwiki/damaging/' + str(diff)).json()[str(diff)][ 'probability'][ 'true'] * 100 reverted = \ requests.get('http://ores.wmflabs.org/scores/trwiki/reverted/' + str(diff)).json()[str(diff)][ 'probability'][ 'true'] * 100 if damaging < 25 and reverted < 25: mavri.review_diff('tr.wikipedia', diff, xx) text = '[[Special:Diff/' + str(diff) + ' | ' + title + ']] - damaging= %.2f - reverted= %.2f' %(damaging, reverted) mavri.appendtext_on_page('tr.wikipedia', 'Kullanıcı:Mavrikant/ORES/Reviewed', '\n# ' + text, text, xx) exit(0)
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)
# mavri kütüphanesi yükle import mavri # json kütüphanesi yükle import json wiki = 'tr.wikipedia' username = '******' # Kullanıcı girişi yap xx = mavri.login(wiki, username) # Giriş denemesini sonucunu ekrana JSON ile düzenleyerek yazdır print json.dumps(json.loads(xx.text), sort_keys=True, indent=4) # 2 bölümü birbirinden ayır print "\n-------------------------------------------------------------------------\n" # Deneme sayfasına mesaj ekle. sonuc = mavri.appendtext_on_page( 'tr.wikipedia', 'Vikipedi:Deneme tahtası', '\n== mavribot test ==\nDeneme deneme 123 --~~~~', 'mavribot ile test yapıldı.', xx) # Sonucu ekrana JSON ile düzenleyerek yazdır print json.dumps(json.loads(sonuc.text), sort_keys=True, indent=4) # Programı kapat exit(0)