User:Reza1615/code01

 import wikipedia,pagegenerators,codecs wikipedia.config.put_throttle = 0 wikipedia.put_throttle.setDelay
 * 1) !/usr/bin/python
 * 2) -*- coding: utf-8  -*-
 * 3) Reza(User:reza1615), 2013
 * 4) Distributed under the terms of the CC-BY-SA 3.0.
 * 5) -*- coding: utf-8 -*-
 * 1) Distributed under the terms of the CC-BY-SA 3.0.
 * 2) -*- coding: utf-8 -*-

def main: site = wikipedia.getSite('translatewiki',fam='i18n') gen=None preloadingGen=False PageTitles = [] genFactory = pagegenerators.GeneratorFactory for arg in wikipedia.handleArgs: if arg.startswith ('-new'): arg=arg.replace(':','') if len(arg) == 4: genfa = pagegenerators.NewpagesPageGenerator(200, False, site,0) else: genfa = pagegenerators.NewpagesPageGenerator(int(arg[4:]), False, site,0) preloadingGen = pagegenerators.PreloadingGenerator( genfa,60) break elif arg.startswith('-page'): if len( arg ) == 5: PageTitles.append( wikipedia.input( u'Which page do you want to chage?' ) ) else: PageTitles.append( arg[6:] ) break elif arg.startswith( '-namespace:' ): namespaces.append( int( arg[11:] ) ) else: generator = genFactory.handleArg( arg ) if generator: gen = generator if not gen: wikipedia.stopme if PageTitles: pages = [wikipedia.Page( site,PageTitle ) for PageTitle in PageTitles] gen = iter( pages ) if not preloadingGen: preloadingGen = pagegenerators.PreloadingGenerator( gen,pageNumber = 60) text,text_nofa=u'\n',u'\n' for pages in preloadingGen: if pages.title[-3:]=='/en': wikipedia.output(u''+pages.title+u'---') entext=pages.get entitle=pages.title fapage=wikipedia.Page(site,pages.title.replace(u'/en',u'/fa')) if fapage.exists: fatext=fapage.get ourtext=u"@@@\n"+entitle+u"\nenlink="+entext+u"\nfalink="+fatext+"\n@@@\n" text+=ourtext wikipedia.output(ourtext) with codecs.open(u'zz_translate_list_'+entitle.split(u':')[0]+'.txt' ,mode = 'w',encoding = 'utf8' ) as f:                               f.write(text.strip) else: ourtext=u"@@@\n"+entitle+u"\nenlink="+entext+u"\nfalink=\n@@@\n" text_nofa+=ourtext wikipedia.output(ourtext) with codecs.open(u'zz_translate_nofa_list_'+entitle.split(u':')[0]+'.txt' ,mode = 'w',encoding = 'utf8' ) as f:                               f.write(text_nofa.strip) if __name__ == "__main__": main