پرش به محتوا

ویکی‌پدیا:درخواست‌های ربات/ربات مترجم بر اساس میان‌ویکی/ویرایش ۱.۱

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

برای توضیحات، اطلاعات فنی و کاربردها، ویرایش ۱ این ربات را ببینید.

توضیح:
این نسخه صرفا نام مقاله در ویکی‌پدیای انگلیسی را در فارسی پیوند نمی‌کند و به جای آن یک پیوند به خود ویکی‌پدیای انگلیسی می‌دهد و نیز پیوند به نام انگلیسی مقاله را در صفحه ایجاد می‌کند تا کاربر آن را ترجمه کند.
مانند [[62 Andromedae]]<sup>([[:en:62 Andromedae|en]])</sup>
که می‌شود: 62 Andromedae(en)
و بعد از ترجمه توسط کاربر: ۶۲ زن برزنجیر(en)

<syntaxhighlight lang="python">

  1. !/usr/bin/python
  2. -*- coding: utf-8 -*-
  3. Reza(User:reza1615), 2011 & Slightly modified by Leyth@fawiki.
  4. Distributed under the terms of the CC-BY-SA 3.0 .

__version__='$Id: InterwikiFinder.py 1.1 2011-06-18 01:11 UTC $'

  1. NOTE: This version has some problems with redirected pages.

import catlib ,pprint ,pagegenerators import wikipedia,add_text import codecs,time,string,re

site = wikipedia.getSite( 'en' ) #(1) Wiki that you want to import the article or template from it. for example 'fa' for wikiFa

  1. cat = catlib.Category( site,u'Category:Roads in Iran' )#(5)---category
  2. gen = pagegenerators.CategorizedPageGenerator( cat )

bpage = wikipedia.Page( site,u'PAGENAME' )#(2) address that is located in source wiki for example 'List of stadiums in England'. DON'T USE THE DEFAULT LINK! pagework = u'List'

text = bpage.get()

def englishdictionry( enlink ):

   site = wikipedia.getSite( 'en' )#(3)------------change to source wiki name------
   apage = wikipedia.Page( site,enlink )
   enlinkfinall = '' + enlink + '$' + '(en)' # enlink + superscripted en
   NOPAGE = False
   try:
       atext = apage.get()
   except wikipedia.IsRedirectPage:
       apage = apage.getRedirectTarget()
       try:
               atext = apage.get()
       except:
               return enlinkfinall
   except:
       return enlinkfinall
   if not NOPAGE == True:
      if atext.find( '[[fa:' ) != -1: #(4)------------change to finall wiki name------
           falink = atext.split( '[[fa:' )[1]
           falink = falink.split( ']]' )[0]
           falink = '' + falink + '$'# $ because of Bot doesn't repeat one link two times
           return falink
      else:
           return enlinkfinall
   else:
       return enlinkfinall

def farsiwriter( text ):

   with codecs.open( 'FinallResult.txt',mode = 'a',encoding = 'utf8' ) as f:# (6)-----Name of Text file that it will save as translation
               f.write( text )
   f.close()

newtext = ' ' count = 0 pagework = str( pagework ) pprint.pprint( pagework ) for link in text.split( '[[' ):

           count = count + 1
           link = link.split( ']]' )[0]
           linkeng = '' + link + ''
           link = link.split( '|' )[0].strip()
           if link == :
               continue
           if link.find( '{' ) != -1:
               continue
           if link.find( 'file:' ) != -1:
               continue
           if link.find( '#' ) != -1:
               continue
           if link.find( 'File:' ) != -1:
               continue
           if link.find( 'Image:' ) != -1:
               continue
           if link.find( 'image:' ) != -1:
               continue
           if link.find( '$' ) != -1:
               continue
           falink = englishdictionry( link )
           first = text.split( '[[' )[0:count - 1]
           newtext = newtext + falink
           text = text.replace( linkeng,falink )
           pprint.pprint( linkeng )
           pprint.pprint( 'InterWiki Tranlation==> ' + falink )

text = text.replace( '$', ) pprint.pprint( text ) pagework = str( pagework ) pagework = pagework.replace( '[[', ) pagework = pagework.replace( ']]', ).strip() pagework = englishdictionry( pagework ) pagework = pagework.replace( '[[', ) pagework = pagework.replace( '$', ) pagework = pagework.replace( ']]', ).strip() textresult = u'xxx\nXXX%sXXX\n%s\nxxx\n' % ( pagework,text ) farsiwriter( textresult )