ویکیپدیا:درخواستهای ربات/WP cat generator.py
ظاهر
#!/usr/bin/python
# -*- coding: utf-8 -*-
__version__ = '$Id: WP_cat_generator.py$'
from BeautifulSoup import UnicodeDammit
import sys, re, urllib2, httplib, socket, codecs, ftplib
import wikipedia, catlib, pagegenerators, noreferences, category
import subprocess, tempfile, os ,config
WPDic = {u'فیزیک': u'Physics',
u'', u''}
clssDic = {u'ابتدایی': u'Start-Class',
u'خرد': u'Stub-Class',
u'ضعیف': u'C-Class',
u'متوسط': u'B-Blass',
u'خوب': u'GA-Class',
u'عالی': u'A-Class',
u'برگزیده': u'FA-Class',
u'فهرست برگزیده': u'FL-Class',
u'تغییرمسیر': u'Redirect-Class',
u'فهرست': u'List-Class',
u'ابهامزدایی': u'Disambig-Class',
u'رده': u'Category-Class',
u'الگو': u'Template-Class',
u'ارزیابینشده': u'Unassessed'}
f = codecs.open(u'WPCats', 'a', 'utf-8')
def generate(name, cats, iw, faText):
comment = u'ربات: ایجاد ردههای ویکیپروژهها'
fullName = u'رده:' + re.sub(u'(.+?)(?:\|.+?|)$', ur'\1', name)
# Add categories
for cat in cats:
faText += u' \n' % cat
# Add interwiki
enPage = wikipedia.Page(wikipedia.getSite('en'), u'Category:'+iw)
if enPage.exists() is True:
faText += u'\n[[en:Category:%s]]\n' % iw
enText = enPage.get()
enPage.put(enText + '\n[[fa:%s]]\n' % fullName, u'+[[fa:%s]]' % fullName)
else:
comment += u'. احتمالاً ردهٔ معادلی در ویکی انگلیسی وجود ندارد — این رده بدون میانویکیاست.'
# Submit
page = wikipedia.Page(wikipedia.getSite('fa'), fullName)
if page.exists() is False:
page.put(faText, comment)
f.write(u'\n[[:'+page.title()+u']]')
def main():
for WP in WPDic:
enWP = WPDic[WP]
name = u'ویکیپروژه ' + WP
iw = u'WikiProject ' + enWP
cats = (u'ویکیپروژهها|' + WP)
txt = u'{{رده پنهان}}\n\n'
generate(name, cats, iw, txt)
name = u'کاربران عضو ویکیپروژه ' + WP
iw = u'WikiProject %s members' % enWP
cats = (u'ویکیپدیاییها بر پایه ویکیپروژه|' + WP, u'ویکیپروژه ' + WP)
txt = u'کاربران عضو [[ویکیپدیا:ویکیپروژه %s|ویکیپروژهٔ %s]].\n\nالگوی مربوطه: {{الگو|کاربر ویکیپروژه %s}}\n{{کاربر ویکیپروژه %s}}\n\n' % (WP, WP, WP, WP)
generate(name, cats, iw, txt)
name = u'الگوهای ' + WP
iw = u'%s templates' % enWP
cats = (u'الگوها بر پایه موضوع|' + WP, u'ویکیپروژه ' + WP)
txt = u'{{رده الگو}}\n\n'
generate(name, cats, iw, txt)
name = u'الگوهای جعبه اطلاعات ' + WP
iw = u'%s infobox templates' % enWP
cats = (u'الگوهای اطلاعاتی جعبهای|' + WP, u'الگوهای ' + WP)
txt = u'{{رده الگو|type=infobox}}\n\n'
generate(name, cats, iw, txt)
name = u'مقالههای ویکیپروژه ' + WP
iw = u'WikiProject %s articles' % enWP
cats = (u'مقالهها بر پایه ویکیپروژه|' + WP, u'ویکیپروژه ' + WP)
txt = u'{{رده پنهان}}\n\n'
generate(name, cats, iw, txt)
name = u'مقالههای نیازمند توجه ' + WP
iw = u'%s articles needing attention' % enWP
cats = (u'مقالههای نیازمند توجه بر پایه ویکیپروژه|' + WP, u'مقالههای ویکیپروژه ' + WP)
txt = u'{{رده پنهان}}\n\n'
generate(name, cats, iw, txt)
name = u'مقالههای نیازمند توجه متخصص ' + WP
iw = u'%s articles needing expert attention' % enWP
cats = (u'مقالههای نیازمند توجه متخصص بر پایه ویکیپروژه|' + WP, u'مقالههای نیازمند توجه ' + WP)
txt = u'{{رده پنهان}}\n\n'
generate(name, cats, iw, txt)
name = u'مقالههای نیازمند جعبه اطلاعات ' + WP
iw = u'%s articles needing infoboxes' % enWP
cats = (u'مقالههای نیازمند جعبه اطلاعات بر پایه ویکیپروژه|' + WP, u'مقالههای ویکیپروژه ' + WP)
txt = u'{{رده پنهان}}\n\n'
generate(name, cats, iw, txt)
name = u'مقالههای ارزیابینشده ' + WP
iw = u'Automatically assessed %s articles' % enWP.lower()
cats = (u'مقالههای ارزیابینشده بر پایه ویکیپروژه|' + WP, u'مقالههای ویکیپروژه ' + WP)
txt = u'{{رده پنهان}}\n\n'
generate(name, cats, iw, txt)
name = u'مقالههای به طور خودکار ارزیابیشده ' + WP
iw = u'Automatically assessed %s articles' % enWP.lower()
cats = (u'مقالههای به طور خودکار ارزیابیشده بر پایه ویکیپروژه|' + WP, u'مقالههای ویکیپروژه ' + WP)
txt = u'{{رده پنهان}}\n\n'
generate(name, cats, iw, txt)
name = u'مقالههای %s بر پایه کیفیت' % WP
iw = u'%s articles by quality' % enWP
cats = (u'مقالهها بر پایه ویکیپروژه و کیفیت', u'مقالههای ویکیپروژه ' + WP)
txt = u'{{رده پنهان}}\n{{ReleaseVersionParameters |hidden=yes |homepage=ویکیپدیا:ویکیپروژه %s}}\n{{جدول درجهبندی}}\n{{Cat class}}\n\n' % WP
generate(name, cats, iw, txt)
for clss in clssDic:
name = u'مقالههای %s %s' % (clss, WP)
iw = u'%s %s articles' % (clssDic[clss], enWP.lower())
cats = (u'مقالههای %s بر پایه کیفیت' % WP, u'مقالههای %s بر پایه ویکیپروژه|%s' % (clss, WP))
txt = u'{{رده پنهان}}\n{{Cat class|topic=%s|sort=%s|class=%s}}\n\n' % (WP, WP, clss)
generate(name, cats, iw, txt)
try:
main()
f.close()
except KeyboardInterrupt:
pywikibot.stopme()