#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
This is not a complete bot; rather, it is a template from which simple
bots can be made. You can rename it to mybot.py, then edit it in
whatever way you want.
The following parameters are supported:
¶ms;
-dry If given, doesn't do any real changes, but only shows
what would have been changed.
All other parameters will be regarded as part of the title of a single page,
and the bot will only work on that single page.
"""
#
# (C) Pywikipedia bot team, 2006-2010
#
# Distributed under the terms of the MIT license.
#
__version__ = '$Id: basic.py 8435 2010-08-23 07:10:44Z purodha $'
#
#Orijinal importlar
import wikipedia as pywikibot
import pagegenerators
#Welcome.py importlar
import wikipedia, config, query, userlib
import time, re, urllib, locale
import codecs
from datetime import timedelta
from random import choice
from string import capitalize
#Türkçe karakter
locale.setlocale(locale.LC_ALL,"")
locale.getlocale()
# This is required for the text that is shown when you run this script
# with the parameter -help.
docuReplacements = {
'¶ms;': pagegenerators.parameterHelp
}
class BasicBot:
# Edit summary message that should be used.
# NOTE: Put a good description here, and add translations, if possible!
msg = {
'tr': u'Bot: Antivandalizm sistemi ...',
}
def __init__(self, generator, dry):
"""
Constructor. Parameters:
* generator - The page generator that determines on which pages
to work on.
* dry - If True, doesn't do any real changes, but only shows
what would have been changed.
"""
self.generator = generator
self.dry = dry
# Set the edit summary message
self.summary = pywikibot.translate(pywikibot.getSite(), self.msg)
def run(self):
for page in self.generator:
self.treat(page)
def treat(self, page, onlyLastDiff = True):
"""
Loads the given page, does some changes, and saves it.
"""
text = self.load(page)
if not text:
return
################################################################
# NOTE: Here you can modify the text in whatever way you want. #
################################################################
# If you find out that you do not want to edit this page, just return.
# Example: This puts the text 'Test' at the beginning of the page.
######### 100 karakterden kısa olan yeni sayfaların Kısa Madde Hızlı Sil ile etiketlenmesi
if len(text) < 100:
text = '''100 karakterden kisa sayfa testi calisiyor <br />''' + text
########## Badwords listesiyle eldeki text'in karşılaştırması, eşleşme varsa maddeye uyarı eklenmesi
sozluk = ['am+c[ıiu][kqgğ]', 'aq', 'am+[ıiu]+n+[iau]', 'aptal', 'aş+k+[ıi]', 'a[gğ]z[ıi]n[iıa]', 'aptal', 'amele', 'anan+[ıi]', 'allah[iı]n', 'akp', 'apo', 'asala', 'bilmiyo', 'b[ıi]z[ıi]r', 'bok', 'berbat', 'benim', 'ben', 'b[oö]l[uü]c[uü]', '[cç]ocu(ğu|kları)', 'çük', 'ç+oo+k+', 'deneme', 'dingil', 'dandik', 'ebeni', 'ebesini', 'embesil', 'enayi', 'evlad[ıi]', 'feth?ullah', 'fahi[sş]e', 'feto', 'fa[sş]ist', 'fa[sş]o', 'g[oö]t[uü]n', 'g[oö]t deli', 'g[oö]to', 'g[oö]tver', 'g[oö]te', 'gerizekal[ıi]', 'geri zekal[ıi]', 'gerzek', 'g[ıi]c[ıi]k', 'gey', 'gay', 'hoca', 'herif', 'hah', 'heh', 'hotmail', 'homo', 'hack', 'hepiniz', 'herkes', 'h[ıi]rs[ıi]z|', 'ııı', 'i[bp]i?ne', 'i[gğ]renç', 'kafal[ıi]', 'katil', 'kahpe', 'klitoris', 'kokuyo', 'ku[sş] beyin', 'köpek', 'kom[iuü]nist', 'k[üu]f[üu]?r', 'kür[td]', 'keriz', 'karpuz', 'kıç', 'lavuk', 'lezbiyen', 'libo[sş]', 'len', 'lan', 'me?rh?a?ba?', 'mongol', 'manyak', 'moron', 'memeler', 'nrd', 'na?be?r+', 'nas[iı]ls[iı]n', 'nazi', 'or+o?spu+', 'o[gğ]?lum', 'o[gğ]lu', '[oö]calan', '[oö]zenti', 'pezo', 'peze[vw]enk', 'pu[sş]t', 'pi[çc]', 'pkk', 'rte', 'sala[kq]', 's[ıi][cç][aritd]', '[sş]+er+efsiz', 'sik(er|ey|iy|ii|sin|ece|ice|il|iş|is|ti|me|im|in)', 'sok(ar|tu|du|uy|ay|ac)', 'se?la?m', 'se(ks|x)', 'soyk[ıi]r[ıi]m', 'seviyo', 'topa[cç]', '[td]a[sş]+ak', 'topu[dn]', 'toptu', 'tayyip', 'ter[oö]r', 'uyuz', 'yal(a|ıy|iy)', 'y+a+r+a*[kq]+', 'yrk', 'yavru', 'yaw', 'ya[vw][sş]a[kq]', 'yalan', 'yamu', 'yaa+', 'zuhah', 'zilli', 'kalın yazı', 'İtalik yazı', 'http://www.example.com adres açıklaması', 'Başlık yazısı', 'Dosya:Örnek.jpg', 'Medya:Örnek.ogg', 'Matematiksel-ifadeyi-girin', 'Serbest format yazınızı buraya yazınız', 'eleman 1', 'eleman 2', 'eleman 3', 'eleman A', 'eleman B', 'eleman C', 'Resim:Sun in X-Ray.png', 'Resim:Mona Lisa.jpg', 'Resim:Truite arc-en-ciel.jpg', 'hedefin adı', 'Kategori:kategori', 'parantez', 'silinecek', 'sağa yatır', 'ortala', 'sub', 'kod']
# Regexleri yeni kelimede değil, her kelime içinde arıyor, regex'lere başlangıç eklemek lazım.
print len(sozluk)
i = 0
gerial = 0
while i < 150:
if re.search(sozluk[i], text): # Match
print i
text = '''Regex search calisiyor, %i yakaladi''' %i + text
gerial = gerial + 10
i = i + 1
if gerial >= 10:
text = "Puanlandirma ile geri alma sistemi calisiyor <br />" + text #buraya revert gelecek
if not self.save(text, page, self.summary):
pywikibot.output(u'Page %s not saved.' % page.aslink())
########## Badwords listesiyle eldeki text'in karşılaştırması, eşleşme varsa maddeye uyarı eklenmesi
# d= kısmı badwords sözlüğümüz oluyor, yandaki de puanlandırması. Örneğin "/suck/i" -5 puan.
############### Badwords kısmı sonu
def load(self, page):
"""
Loads the given page, does some changes, and saves it.
"""
try:
# Load the page
text = page.get()
except pywikibot.NoPage:
pywikibot.output(u"Page %s does not exist; skipping."
% page.aslink())
except pywikibot.IsRedirectPage:
pywikibot.output(u"Page %s is a redirect; skipping."
% page.aslink())
else:
return text
return None
def save(self, text, page, comment, minorEdit=True, botflag=True):
# only save if something was changed
if text != page.get():
# Show the title of the page we're working on.
# Highlight the title in purple.
pywikibot.output(u"\n\n>>> \03{lightpurple}%s\03{default} <<<"
% page.title())
# show what was changed
pywikibot.showDiff(page.get(), text)
pywikibot.output(u'Comment: %s' %comment)
if not self.dry:
choice = pywikibot.inputChoice(
u'Do you want to accept these changes?',
['Yes', 'No'], ['y', 'N'], 'N')
if choice == 'y':
try:
# Save the page
page.put(text, comment=comment,
minorEdit=minorEdit, botflag=botflag)
except pywikibot.LockedPage:
pywikibot.output(u"Page %s is locked; skipping."
% page.aslink())
except pywikibot.EditConflict:
pywikibot.output(
u'Skipping %s because of edit conflict'
% (page.title()))
except pywikibot.SpamfilterError, error:
pywikibot.output(
u'Cannot change %s because of spam blacklist entry %s'
% (page.title(), error.url))
else:
return True
return False
def main():
# This factory is responsible for processing command line arguments
# that are also used by other scripts and that determine on which pages
# to work on.
genFactory = pagegenerators.GeneratorFactory()
# The generator gives the pages that should be worked upon.
gen = None
# This temporary array is used to read the page title if one single
# page to work on is specified by the arguments.
pageTitleParts = []
# If dry is True, doesn't do any real changes, but only show
# what would have been changed.
dry = False
# Parse command line arguments
for arg in pywikibot.handleArgs():
if arg.startswith("-dry"):
dry = True
else:
# check if a standard argument like
# -start:XYZ or -ref:Asdf was given.
if not genFactory.handleArg(arg):
pageTitleParts.append(arg)
if pageTitleParts != []:
# We will only work on a single page.
pageTitle = ' '.join(pageTitleParts)
page = pywikibot.Page(pywikibot.getSite(), pageTitle)
gen = iter([page])
if not gen:
gen = genFactory.getCombinedGenerator()
if gen:
# The preloading generator is responsible for downloading multiple
# pages from the wiki simultaneously.
gen = pagegenerators.PreloadingGenerator(gen)
bot = BasicBot(gen, dry)
bot.run()
else:
pywikibot.showHelp()
if __name__ == "__main__":
try:
main()
finally:
pywikibot.stopme()