ویکی‌پدیا:درخواست‌های ربات/فهرست مقالات دارای الگو به انگلیسی فاقد میان ویکی

از ویکی‌پدیا، دانشنامهٔ آزاد

کوئری[ویرایش]

SELECT page_title FROM page JOIN templatelinks ON tl_from=page_id WHERE page_namespace = 0 AND page_is_redirect = 0 AND  tl_title = 'به_انگلیسی' AND tl_namespace = 10 AND page_id NOT IN (SELECT ll_from FROM langlinks WHERE ll_lang="en") ORDER BY page_title;
#!/usr/bin/python
# -*- coding: utf-8 -*-
# BY: رضا (User:reza1615 on fa.wikipedia)
# Distributed under the terms of the CC-BY-SA 3.0 .

__version__ = '$Id: $'

import wikipedia
import pagegenerators
import re, os, codecs, catlib
wikipedia.config.put_throttle = 0
wikipedia.put_throttle.setDelay()
faSite = wikipedia.getSite('fa')
enSite = wikipedia.getSite('en')
txtTmp=' '

msg = u'ربات: ویرایشگر %s'
def run(page):
            try:
                text_fa = page.get()#------------------------------geting pages content
            except wikipedia.IsRedirectPage:#----------------------geting pages redirects contents
                 page = page.getRedirectTarget()
                 text_fa = page.get()
                 wikipedia.output( u'Page %s was Redirect but edited!' %  page.title() )                
            except:
                return  False,False
            return text_fa,page
def main():
    summary_commandline,template,gen = None,None,None
    exceptions,PageTitles,namespaces = [],[],[]
    autoText,autoTitle = False,False
    genFactory = pagegenerators.GeneratorFactory()
    wikipedia.setAction( msg )
    arg=True#------if you dont want to work with arguments leave it False if you want change it to True---
    if arg==True:
        for arg in wikipedia.handleArgs():
            if arg == '-autotitle':
                autoTitle = True
            elif arg == '-autotext':
                autoText = True
            elif arg.startswith( '-page:' ):
                if len(arg) == 6:
                    PageTitles.append(wikipedia.input( u'Which page do you want to chage?' ))
                else:
                    PageTitles.append(arg[6:])
            elif arg.startswith( '-cat:' ):
                if len(arg) == 5:
                    PageTitles.append(wikipedia.input( u'Which Category do you want to chage?' ))
                else:
                    PageTitles.append('Category:'+arg[5:])
            elif arg.startswith( '-template:' ):
                if len(arg) == 10:
                    PageTitles.append(wikipedia.input( u'Which Template do you want to chage?' ))
                else:
                    PageTitles.append('Template:'+arg[10:])
            elif arg.startswith('-except:'):
                exceptions.append(arg[8:])
            elif arg.startswith( '-namespace:' ):
                namespaces.append( int( arg[11:] ) )
            elif arg.startswith( '-ns:' ):
                namespaces.append( int( arg[4:] ) )
            elif arg.startswith( '-summary:' ):
                wikipedia.setAction( arg[9:] )
                summary_commandline = True
            else:
                generator = genFactory.handleArg(arg)
                if generator:
                    gen = generator
    else:
        PageTitles = [raw_input(u'Page:> ').decode('utf-8')]
        
    if PageTitles:
        pages = [wikipedia.Page(faSite,PageTitle) for PageTitle in PageTitles]
        gen = iter( pages )
    if not gen:
        wikipedia.stopme()
        
    if namespaces != []:
        gen = pagegenerators.NamespaceFilterPageGenerator( gen,namespaces )
    preloadingGen = pagegenerators.PreloadingGenerator( gen,pageNumber = 60 )#---number of pages that you want load at same time
    textout=u'\n'
    for page in generator:

        page=page.title()
        text_fa,pagefa=run(wikipedia.Page(faSite,page))
        #wikipedia.output(text_fa)
        if text_fa:
            try:
               template=text_fa.split(u'{{انگلیسی|')[1].split(u'}}')[0].strip()
               wikipedia.output(template)
            except:
                try:
                    template=text_fa.split(u'{{به انگلیسی|')[1].split(u'}}')[0].strip()
                    wikipedia.output(template)
                except:
                    continue
            if template.find('#')!=-1:
                continue
            try:                    
                ennew_text,pageen=run(wikipedia.Page(enSite,template))
                if ennew_text :    
                    if pageen.title().find('#')==-1:
                        textout+=u'#[['+page+u']]=[['+template+u']]\n'
            except:
                continue
    reza=wikipedia.Page(faSite,u'user:Reza1615/test14')    
    reza.put(textout)
if __name__ == "__main__":
    try:
        main()
    finally:
        wikipedia.stopme()