Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- #
- # Reza(User:reza1615), 2011
- #
- # Distributed under the terms of the CC-BY-SA 3.0 .
- # -*- coding: utf-8 -*-
- """
- -file - Work on all pages given in a local text file.
- Will read any [[wiki link]] and use these articles.
- Argument can also be given as "-file:filename".
- -cat - Work on all pages which are in a specific category.
- Argument can also be given as "-cat:categoryname".
- -encat - Finding the pages that uses the category in en.wikipedia and add categories to pages that they have interwiki in en wiki to home wiki
- -recentcat - Useful for automatic bots and it should add with -namespace:14 -recenchanges:N (N=Number of categories that you want to work on)
- -newcat - Adding article to new categories -newcat:N (N=Number of categories that you want to work on)
- -page - Only edit a specific page.
- Argument can also be given as "-page:pagetitle". You can give this
- parameter multiple times to edit multiple pages.
- -ref - Work on all pages that link to a certain page.
- Argument can also be given as "-ref:referredpagetitle".
- -filelinks - Works on all pages that link to a certain image.
- Argument can also be given as "-filelinks:ImageName".
- -links - Work on all pages that are linked to from a certain page.
- Argument can also be given as "-links:linkingpagetitle".
- -start - Work on all pages in the wiki, starting at a given page. Choose
- "-start:!" to start at the beginning.
- NOTE: You are advised to use -xml instead of this option; this is
- meant for cases where there is no recent XML dump.
- -except:XYZ - Ignore pages which contain XYZ. If the -regex argument is given,
- XYZ will be regarded as a regular expression.
- -summary:XYZ - Set the summary message text for the edit to XYZ, bypassing the
- predefined message texts with original and replacements inserted.
- -template:XYZ-
- -blog: -checking for blog sources. if it is in page it will sent page link to defined address
- -source - checking the articles sources . if it doesn't have . it will send page link to defined address
- -namespace:n - Number of namespace to process. The parameter can be used
- multiple times. It works in combination with all other
- parameters, except for the -start parameter. If you e.g. want to
- iterate over all user pages starting at User:M, use
- -start:User:M.
- -always - Don't prompt you for each replacement
- other: -
- """
- import catlib,query
- import pagegenerators,re,sys#,fa_cosmetic_changes
- import wikipedia,codecs,string
- from xml.dom import minidom
- wikipedia.config.put_throttle = 0
- wikipedia.put_throttle.setDelay()
- #-----------------------------------------------version-----------------------------------------
- try:
- import MySQLdb
- except:
- wikipedia.output(u'\03{lightred}you should use this code only on toolserver\03{default}')
- wikipedia.stopme()
- sys.exit()
- versionpage = wikipedia.Page( wikipedia.getSite('ar'),u'مستخدم:Elph/التصانیف المعادلة/version' )
- lastversion=versionpage.get().strip()
- version=u'22'
- if lastversion!=version:
- wikipedia.output(u"\03{lightred}Your bot dosen't use the last verion please update me!\03{default}")
- wikipedia.stopme()
- sys.exit()
- #-----------------------------------------------------------------------------------------------
- langs = u'انگلیسی|آلمانی|اسپانیایی|فرانسوی|روسی|ایتالیایی|لاتین|اسکاتلندی|هلندی|هندی|اردو|پشتو|مصری|تاجیکستانی|قرقیزستانی|ازبکستانی|ترکی|یونانی|چینی|ژاپنی|کرهای|تایلندی|[فپ]ارسی'
- def namespacefinder( enlink ,firstsite):
- try:
- enlink=unicode(str(enlink),'UTF-8').replace(u'[[',u'').replace(u']]',u'').replace(u'en:',u'').replace(u'ur:',u'')
- except:
- enlink=enlink.replace(u'[[',u'').replace(u']]',u'').replace(u'en:',u'').replace(u'ur:',u'')
- enlink=enlink.replace(u' ',u'_')
- site = wikipedia.getSite(firstsite)
- params = {
- 'action': 'query',
- 'prop': 'langlinks',
- 'titles': enlink,
- 'redirects': 1,
- 'lllimit':500,
- }
- a=1
- if a:
- categoryname = query.GetData(params,site, encodeTitle = True)
- for item in categoryname[u'query'][u'pages']:
- fanamespace=categoryname[u'query'][u'pages'][item]['ns']
- return fanamespace
- else:
- return False
- def englishdictionry( enlink ,firstsite,secondsite):
- try:
- enlink=unicode(str(enlink),'UTF-8').replace(u'[[',u'').replace(u']]',u'').replace(u'en:',u'').replace(u'ur:',u'')
- except:
- enlink=enlink.replace(u'[[',u'').replace(u']]',u'').replace(u'en:',u'').replace(u'ur:',u'')
- if enlink.find('#')!=-1:
- return False
- if enlink==u'':
- return False
- enlink=enlink.replace(u' ',u'_')
- site = wikipedia.getSite(firstsite)
- sitesecond= wikipedia.getSite(secondsite)
- params = {
- 'action': 'query',
- 'prop': 'langlinks',
- 'titles': enlink,
- 'redirects': 1,
- 'lllimit':500,
- }
- try:
- categoryname = query.GetData(params,site, encodeTitle = True)
- for item in categoryname[u'query'][u'pages']:
- case=categoryname[u'query'][u'pages'][item][u'langlinks']
- for item in case:
- if item[u'lang']==secondsite:
- intersec=item[u'*']
- break
- result=intersec
- if result.find('#')!=-1:
- return False
- return result
- except:
- return False
- def catquery(enlink,firstsite,hidden):
- cats=[]
- try:
- enlink=unicode(str(enlink),'UTF-8').replace(u'[[',u'').replace(u']]',u'').replace(u'en:',u'').replace(u'ur:',u'')
- except:
- enlink=enlink.replace(u'[[',u'').replace(u']]',u'').replace(u'en:',u'').replace(u'ur:',u'')
- enlink=enlink.split(u'#')[0].strip()
- if enlink==u'':
- return False
- enlink=enlink.replace(u' ',u'_')
- site = wikipedia.getSite(firstsite)
- if hidden:
- params = {
- 'action': 'query',
- 'prop': 'categories',
- 'titles': enlink,
- 'redirects': 1,
- 'cllimit':500,
- }
- else:
- params = {
- 'action': 'query',
- 'prop': 'categories',
- 'titles': enlink,
- 'redirects': 1,
- 'clshow':'!hidden',
- 'cllimit':500,
- }
- try:
- categoryname = query.GetData(params,site, encodeTitle = True)
- for item in categoryname[u'query'][u'pages']:
- categoryha=categoryname[u'query'][u'pages'][item][u'categories']
- break
- for cat in categoryha:
- cats.append(cat[u'title'])
- return cats
- except:
- return False
- def templatequery(enlink,firstsite):
- temps=[]
- try:
- enlink=unicode(str(enlink),'UTF-8').replace(u'[[',u'').replace(u']]',u'').replace(u'en:',u'').replace(u'ur:',u'')
- except:
- enlink=enlink.replace(u'[[',u'').replace(u']]',u'').replace(u'en:',u'').replace(u'ur:',u'')
- enlink=enlink.split(u'#')[0].strip()
- if enlink==u'':
- return False
- enlink=enlink.replace(u' ',u'_')
- site = wikipedia.getSite(firstsite)
- params = {
- 'action': 'query',
- 'prop':'templates',
- 'titles': enlink,
- 'redirects': 1,
- 'tllimit':500,
- }
- try:
- categoryname = query.GetData(params,site, encodeTitle = True)
- for item in categoryname[u'query'][u'pages']:
- templateha=categoryname[u'query'][u'pages'][item][u'templates']
- break
- for temp in templateha:
- temps.append(temp[u'title'].replace(u'_',u' '))
- return temps
- except:
- return False
- def subcatquery(enlink,firstsite):
- cats=[]
- try:
- enlink=unicode(str(enlink),'UTF-8').replace(u'[[',u'').replace(u']]',u'').replace(u'en:',u'').replace(u'ur:',u'')
- except:
- enlink=enlink.replace(u'[[',u'').replace(u']]',u'').replace(u'en:',u'').replace(u'ur:',u'')
- enlink=enlink.split(u'#')[0].strip()
- if enlink==u'':
- return False
- enlink=enlink.replace(u' ',u'_')
- site = wikipedia.getSite(firstsite)
- params = {
- 'action': 'query',
- 'list': 'categorymembers',
- 'cmtitle': enlink,
- 'cmtype':'subcat',
- 'cmlimit': 500,
- }
- try:
- categoryname = query.GetData(params,site, encodeTitle = True)
- for item in categoryname[u'query'][u'categorymembers']:
- categoryha=item[u'title']
- wikipedia.output(categoryha)
- cats.append(categoryha)
- if cats!=[]:
- return cats
- except:
- return False
- def sitop(link,wiki):
- link=link.replace( u'[[',u'' ).replace( u']]',u'' ).strip()
- wikipedia.config.put_throttle = 0
- wikipedia.put_throttle.setDelay()
- site = wikipedia.getSite(wiki)
- try:
- page = wikipedia.Page( site,link )
- if wiki=='ur':
- cats=page.categories(api=True)
- else:
- cats=page.categories()
- return cats
- except wikipedia.IsRedirectPage:
- page = page.getRedirectTarget()
- try:
- cats=page.categories()
- return cats
- except:
- return False
- except:
- return False
- def category(PageTitle,koltuple):
- counters=0
- PageTitle=PageTitle.replace( u'[[',u'' ).replace( u']]',u'' ).strip()
- listacategory=[PageTitle]
- listacategory2=[]
- for catname in listacategory:
- counters+=1
- if counters>150:
- break
- gencat=subcatquery(catname,'ur')#---function
- if gencat:
- if len (gencat)>100:
- continue
- for subcat in gencat:
- subcat2=u'[[ur:'+subcat+u']]'
- if subcat in listacategory:
- continue
- else:
- listacategory.append(subcat)
- if subcat2 in koltuple:
- listacategory2.append(subcat2)
- listacategory2.append(' ')
- return listacategory2
- if listacategory==[]:
- return False
- else:
- return listacategory
- def pagefafinder(encatTitle):
- cats=[]
- try:
- item=unicode(str(encatTitle),'Ascii').replace('[[en:','').replace(']]','').replace(' ','_').replace('Category:','')
- except:
- item=str(encatTitle).replace('[[en:','').replace(']]','').replace(' ','_').replace('Category:','')
- for raw in results:
- cats.append(raw)
- if cats!=[]:
- return cats
- else:
- return False
- def duplic(catfa,radeh):
- catfa=catfa.replace(u'ur:',u'')
- radeht=u' '
- if len(radeh.strip())<1 :
- return False
- if len(catfa.replace(u',',u'').strip())<1 :
- return radeh
- for x in catfa.split(','):
- catfax=x.split('|')[0].split(']]')[0].replace('[[','').strip()
- for y in radeh.split(','):
- radehy=y.split('|')[0].split(']]')[0].replace('[[','').strip()
- if catfax==radehy:
- radeh= radeh.replace(y,'')
- break
- for rad in radeh.split(','):
- radeht+=rad+'\n'
- return radeht
- def pedar(catfa,radehi,link):
- link=link.replace( u'[[',u'' ).replace( u']]',u'' ).strip()
- hazflist=catfa
- if englishdictionry( link ,'ur','en')==False :
- return hazflist
- radehi=radehi.replace('\n\n','\n').replace('\n\n','\n').replace('\n\n','\n').replace('\n\n','\n').replace('\n\n','\n').strip()
- kol=catfa.strip()+radehi.replace('\n',',').strip()
- kol=kol.replace(',,',',').strip()
- radehtest=radehi.replace('\n',',').replace(',,',',').strip().split(',')
- koltuple=kol.split(',')
- for x in range(0,len(radehtest)):
- if radehtest[x].find(u'مقالات')!=-1:
- continue
- catslistx=category(radehtest[x],koltuple)#----------category function
- if catslistx==False :
- continue
- for y in range(0,len(koltuple)):
- if radehi.find(radehtest[x])==-1:
- break
- for catlis in catslistx:
- try:
- catlis=unicode(str(catlis),'UTF-8').strip()
- except:
- catlis=catlis.strip()
- if koltuple[y].strip() == catlis:
- if radehi.find(radehtest[x])!=-1:
- hazfi=radehtest[x].replace(u'[[',u'').replace(u']]',u'').replace(u'زمرہ:',u'').replace(u'Category:',u'').strip()
- try:
- hazfi = re.search(u'\[\[ *(?:[Cc]ategory|زمرہ) *:*%s*(?:\|.*?|)\]\]'% hazfi, radehi).group(0)
- radehi=radehi.replace(hazfi,'')
- except:
- radehi=radehi.replace(u'(',u' اااا ').replace(u')',u' بببب ')
- hazfi=hazfi.replace(u'(',u' اااا ').replace(u')',u' بببب ')
- hazfi = re.search(u'\[\[ *(?:[Cc]ategory|زمرہ) *:*%s*(?:\|.*?|)\]\]'% hazfi, radehi).group(0)
- radehi=radehi.replace(hazfi,'')
- radehi=radehi.replace(u' اااا ',u'(').replace(u' بببب ',u')')
- radehi=radehi.replace('\n\n','\n').strip()
- break
- radehi=radehi.replace(',','\n').strip()
- return radehi
- def run(gen):
- for pagework in gen:
- radehf,catsfas,maghalehen,radeh,finallRadeh=' ',' ',' ',' ',' '
- shod=False
- try:
- pagework=unicode(str(pagework),'UTF-8')
- except:
- pagework=pagework
- wikipedia.output(u'-----------------------------------------------')
- wikipedia.output(u'opening....'+pagework)
- catsfa=sitop(pagework,'ur')
- if catsfa==False :
- continue
- for tem in catsfa:
- if unicode(str(tem),'UTF-8').find(u'تصنيف:مقالات أنشئت بواسطة معالج إنشاء المقالات')!=-1:
- continue
- catsfas+=unicode(str(tem),'UTF-8')+','
- maghalehen=englishdictionry( pagework ,'ur','en')
- if not maghalehen:
- continue
- pageblacklist=[u'Sandbox']
- passing=True
- for item in pageblacklist:
- if maghalehen.find(item.lower())!=-1:
- passing=False
- break
- if not passing:
- continue
- if namespacefinder(maghalehen ,'en')!=namespacefinder(pagework ,'ur'):
- wikipedia.output(u"\03{lightred}Interwikis have'nt the same namespace\03{default}")
- continue
- catsen=catquery(maghalehen,'en',False)
- if not catsen:
- continue
- templateblacklist=[u'loanword',u'Wikipedia category',u'sockpuppet',u'Empty category',u'tracking category',u'container category',u'hiddencat',u'backlog subcategories',u'Stub category']
- nameblcklist=[u'Current events',u'Tracking',u'articles',u'Surnames',u'Loanword',u'Words and phrases',u'Given names',u'Human names',u'stubs',u'Nicknames',u'Living people']
- for cat in catsen:
- passport=True
- temples=str(templatequery(cat,'en')).replace( u'_',u' ' ).strip()
- cat=cat.replace( u'_',u' ' ).strip()
- for black in templateblacklist:
- if temples.lower().find(black.lower())!=-1:
- passport=False
- break
- for item in nameblcklist:
- if cat.lower().find(item.lower())!=-1:
- passport=False
- break
- if not passport:
- continue
- interwikifarsibase=englishdictionry( cat ,'en','ur')
- if interwikifarsibase:
- if interwikifarsibase.find(u',')!=-1:
- try:
- siteerror=wikipedia.getSite('ur')
- errorpage=wikipedia.Page(siteerror,u'user:Rezabot/CategoriesWithBadNames')
- texterror=errorpage.get()
- if texterror.find(interwikifarsibase)==-1:
- texterror+=u'\n#[[:'+interwikifarsibase+u']]'
- errorpage.put(texterror,u'روبہ: غلط نام کا اعلان')
- continue
- except:
- continue
- interwikifarsi=u'[['+interwikifarsibase+u']]'
- if cat ==englishdictionry( interwikifarsibase ,'ur','en'):
- radeh+=interwikifarsi+u','
- radehf=duplic(catsfas,radeh)
- if radehf==False:
- continue
- radehf=radehf.replace('\n\n','\n').replace('\n\n','\n').replace('\n\n','\n').replace('\n\n','\n').strip()
- if radehf=="":
- continue
- if catsfas.strip()!=u'':
- finallRadeh=pedar(catsfas,radehf,pagework)
- else:
- finallRadeh=radehf.replace(',','\n')
- if finallRadeh==False:
- continue
- if finallRadeh.replace('\n','').strip()=='':
- continue
- if finallRadeh:
- site = wikipedia.getSite('ur')
- link=pagework.replace( u'[[',u'' ).replace( u']]',u'' ).strip()
- page = wikipedia.Page( site,link )
- try:
- text=page.get()
- except wikipedia.IsRedirectPage:
- page = page.getRedirectTarget()
- text=page.get()
- except:
- wikipedia.output(u'\03{lightred}Could not open page\03{default}')
- continue
- namespaceblacklist=[1,2,3,5,7,8,9,11,13,15,101,103]
- if page.namespace() in namespaceblacklist:
- continue
- if text.find(u'{{مساوی زمرہ کے لیے نہیں}}')!=-1 or text.find(u'{{سانچہ:مساوی زمرہ کے لیے نہیں}}')!=-1 or text.find(u'{{مساوی زمرہ کے لیے نہیں}}')!=-1 or text.find(u'{{تصنيف بهتر')!=-1:
- wikipedia.output(u'\03{lightred}this page had {{مساوی زمرہ کے لیے نہیں}} so it is skipped!\03{default}' )
- continue
- #---------------------------------------remove repeative category-----------------
- for item in finallRadeh.split(u'\n'):
- item2=item.split(u'|')[0].replace(u'[[',u'').replace(u']]',u'').strip()
- radehbehtar=templatequery(item2,'ur')
- if radehbehtar:
- if (u'قالب:تحويل تصنيف' in radehbehtar) or (u'قالب:delete' in radehbehtar) or (u'قالب:حذف' in radehbehtar):
- wikipedia.output(u'\03{lightred}Category %s had {{تحويل تصنيف}} or {{delete}} so it is skipped! please edit en.wiki interwiki\03{default}' % item2)
- finallRadeh=finallRadeh.replace(item,u'').replace(u'\n\n',u'\n')
- continue
- textremove=text.replace(u' |',u'|').replace(u' |',u'|').replace(u' |',u'|').replace(u'| ',u'|').replace(u'| ',u'|')
- if textremove.find(u'{{لا للتصنيف الميلادي}}')!=-1 or textremove.find(u'{{لا للتصنيف الميلادي}}')!=-1:
- if item.find(u'(الميلادي)')!=-1 or item.find(u'(قبل الميلاد)')!=-1 or item.find(u'(قبل الميلاد)')!=-1:
- finallRadeh=finallRadeh.replace(item,u'').replace(u'\n\n',u'\n')
- if textremove.find(item2+u']]')!=-1 or textremove.find(item2+u'|')!=-1:
- finallRadeh=finallRadeh.replace(item,u'').replace(u'\n\n',u'\n')
- if finallRadeh.replace(u'\r',u'').replace(u'\n',u'').strip()==u'':
- continue
- finallRadeh=finallRadeh.replace(u'\r',u'').replace(u'\n\n\n\n',u'\n').replace(u'\n\n\n',u'\n').replace(u'\n\n',u'\n').replace(u'\n\n',u'\n').replace(u'\n\n',u'\n').replace(u'\n\n',u'\n').replace(u'\n\n',u'\n').replace(u'\n\n',u'\n') #---------------------------------------------------------------------------------
- if text.find(ur'تصنيف:')!=-1 and page.namespace()!=10:
- num=text.find(ur'[[تصنيف:')
- text=text[:num]+finallRadeh+'\n'+text[num:]
- else:
- m = re.search(ur'\[\[([a-z]{2,3}|[a-z]{2,3}\-[a-z\-]{2,}|simple):.*?\]\]', text)
- if m:
- if m.group(0)==u'[[en:Article]]':
- try:
- if string.count(text,u'[[en:Article]] --->')==1:
- finallRadeh=finallRadeh.replace(u'\r',u'').replace(u'\n\n\n\n',u'\n').replace(u'\n\n\n',u'\n').replace(u'\n\n',u'\n').replace(u'\n\n',u'\n').replace(u'\n\n',u'\n').replace(u'\n\n',u'\n').replace(u'\n\n',u'\n').replace(u'\n\n',u'\n').strip()
- text=text.split(u'[[en:Article]] --->')[0]+u'[[en:Article]] --->\n'+finallRadeh+text.split(u'[[en:Article]] --->')[1]
- else:
- if page.namespace()==10:
- continue
- text+='\n'+finallRadeh
- except:
- if page.namespace()==10:
- continue
- text+='\n'+finallRadeh
- else:
- num=text.find(m.group(0))
- text=text[:num]+finallRadeh+'\n'+text[num:]
- else:
- if page.namespace()==10:
- continue
- text+='\n'+finallRadeh
- wikipedia.output(u'\03{lightpurple} Added=='+finallRadeh+u"\03{default}")
- radehfmsg=finallRadeh.strip().replace(u'\n',u'+')
- if len(radehfmsg.split(u'+'))>4:
- numadd=str(len(radehfmsg.split(u'+')))#.replace(u'0',u'۰').replace(u'1',u'۱').replace(u'2',u'۲').replace(u'3',u'۳').replace(u'4',u'۴').replace(u'5',u'۵').replace(u'6',u'۶').replace(u'7',u'۷').replace(u'8',u'۸').replace(u'9',u'۹')
- radehfmsg=u' %s تصنيف'% numadd
- msg=u'روبہ [[صارف:محمد شعيب/زمرہ جات#'+version+u'|مساوي زمرہ جات ('+version+u')]]: + %s'
- text_new=text
- if page.namespace()==0: #----------------cleaning
- #text_new,cleaning_version,msg_clean=fa_cosmetic_changes.fa_cosmetic_changes(text,page)
- text_new,msg_clean=(text,page)
- else:
- msg_clean=u' '
- #msg=msg %(msg_clean,radehfmsg)
- msg=msg %(radehfmsg)
- msg=msg.replace(u' ',u' ').strip()
- page.put(text_new.strip(), msg)
- wikipedia.output(u'\03{lightpurple} Done=' + pagework+u"\03{default}")
- #except Exception as e:
- #wikipedia.output(u'\03{lightred}Could not open page\03{default}')
- #continue
- #------------------------------------------------------------encat part-------------------------------
- def categorydown(listacategory,one):
- listacategory=[listacategory]
- count=1
- for catname in listacategory:
- count+=1
- if count==200:
- break
- gencat = pagegenerators.SubCategoriesPageGenerator(catname, recurse=False)
- for subcat in gencat:
- try:
- wikipedia.output(str(subcat))
- except:
- wikipedia.output(subcat)
- if subcat in listacategory:
- continue
- else:
- listacategory.append(subcat)
- if one==True:
- break
- return listacategory
- def encatlist(encat,one):
- wikipedia.config.put_throttle = 0
- wikipedia.put_throttle.setDelay()
- count=0
- listenpageTitle=[]
- encat=encat.replace(u'[[',u'').replace(u']]',u'').replace(u'Category:',u'').replace(u'category:',u'').strip()
- language='en'
- encat = catlib.Category( wikipedia.getSite(language),encat )
- listacategory=categorydown(encat,one)
- for enpageTitle in listacategory:
- try:
- fapages=pagefafinder(enpageTitle)
- if fapages!=False:
- for pages in fapages:
- pages=unicode(pages[0],'UTF-8')
- wikipedia.output(u'\03{lightgreen}Adding '+pages+u' to fapage lists\03{default}')
- listenpageTitle.append(pages)
- except:
- try:
- enpageTitle=unicode(str(enpageTitle),'UTF-8').split(u'|')[0].split(u']]')[0].replace(u'[[',u'').strip()
- except:
- enpageTitle=enpageTitle.split(u'|')[0].split(u']]')[0].replace(u'[[',u'').strip()
- cat = catlib.Category( wikipedia.getSite(language),enpageTitle )
- gent = pagegenerators.CategorizedPageGenerator( cat )
- for pagework in gent:
- count+=1
- try:
- link=str(pagework).split(u'|')[0].split(u']]')[0].replace(u'[[',u'').strip()
- except:
- pagework=unicode(str(pagework),'UTF-8')
- link=pagework.split(u'|')[0].split(u']]')[0].replace(u'[[',u'').strip()
- wikipedia.output(link)
- fapagetitle=englishdictionry(link,'en','ur')
- if fapagetitle==False:
- continue
- else:
- wikipedia.output(u'\03{lightgreen}Adding '+fapagetitle+u' to fapage lists\03{default}')
- listenpageTitle.append(fapagetitle)
- if listenpageTitle==[]:
- return False,False
- return listenpageTitle,listacategory
- #-------------------------------------------------------------------encat part finish--------------------------
- def main():
- wikipedia.config.put_throttle = 0
- wikipedia.put_throttle.setDelay()
- summary_commandline,gen,template = None,None,None
- namespaces,PageTitles,exceptions = [],[],[]
- encat,newcatfile='',''
- autoText,autoTitle,down = False,False,False
- recentcat,newcat=False,False
- genFactory = pagegenerators.GeneratorFactory()
- for arg in wikipedia.handleArgs():
- if arg == '-autotitle':
- autoTitle = True
- elif arg == '-autotext':
- autoText = True
- 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( '-except:' ):
- exceptions.append( arg[8:] )
- elif arg.startswith( '-template:' ):
- template = arg[10:]
- elif arg.startswith( '-encat:' ):
- encat = arg[7:].replace(u'Category:',u'').replace(u'category:',u'').replace(u'زمرہ:',u'')
- break
- elif arg.startswith( '-newcatfile:' ):
- newcatfile = arg[12:]
- break
- elif arg == '-down':
- down = True
- break
- elif arg.startswith('-recentcat'):
- arg=arg.replace(':','')
- if len(arg) == 10:
- genfa = pagegenerators.RecentchangesPageGenerator()
- else:
- genfa = pagegenerators.RecentchangesPageGenerator(number = int(arg[10:]))
- genfa = pagegenerators.DuplicateFilterPageGenerator(genfa)
- genfa = pagegenerators.NamespaceFilterPageGenerator( genfa,[14] )
- preloadingGen = pagegenerators.PreloadingGenerator( genfa,60)
- recentcat=True
- break
- elif arg.startswith('-newcat'):
- arg=arg.replace(':','')
- if len(arg) == 7:
- genfa = pagegenerators.NewpagesPageGenerator(100, False, None,14)
- else:
- genfa = pagegenerators.NewpagesPageGenerator(int(arg[7:]), False, None,14)
- preloadingGen = pagegenerators.PreloadingGenerator( genfa,60)
- newcat=True
- break
- elif arg.startswith( '-namespace:' ):
- namespaces.append( int( arg[11:] ) )
- elif arg.startswith( '-summary:' ):
- wikipedia.setAction( arg[9:] )
- summary_commandline = True
- else:
- generator = genFactory.handleArg( arg )
- if generator:
- gen = generator
- if encat!='':
- if down:
- one=False
- else:
- one=True
- encatfalist,encatlists=encatlist(encat,one)
- if encatlists:
- for encat in encatlists:
- encat=englishdictionry(encat,u'en',u'ur')
- if encat:
- run([encat])
- if encatfalist!=False:
- run(encatfalist)
- if PageTitles:
- pages = [wikipedia.Page( wikipedia.getSite(),PageTitle ) for PageTitle in PageTitles]
- gen = iter( pages )
- if recentcat:
- for workpage in preloadingGen:
- workpage=workpage.title()
- cat = catlib.Category( wikipedia.getSite('ur'),workpage)
- gent = pagegenerators.CategorizedPageGenerator( cat )
- run( gent)
- wikipedia.stopme()
- sys.exit()
- if newcat:
- for workpage in preloadingGen:
- workpage=workpage.title()
- workpage=englishdictionry(workpage,'ur','en')
- if workpage!=False:
- one=True
- encatfalist,encatlists=encatlist(workpage,one)
- if encatlists:
- for encat in encatlists:
- encat=englishdictionry(encat,u'en',u'ur')
- if encat:
- run([encat])
- if encatfalist!=False:
- run(encatfalist)
- wikipedia.stopme()
- sys.exit()
- if newcatfile:
- text2 = codecs.open( newcatfile,'r' ,'utf8' )
- text = text2.read()
- linken = re.findall(ur'\[\[.*?\]\]',text, re.S)
- if linken:
- for workpage in linken:
- workpage=workpage.split(u'|')[0].replace(u'[[',u'').replace(u']]',u'').replace(u'Category:',u'').replace(u'category:',u'').replace(u'زمرہ:',u'').strip()
- workpage=englishdictionry(workpage,'ur','en')
- if workpage!=False:
- one=True
- encatfalist,encatlists=encatlist(workpage,one)
- if encatlists:
- run(encatlists)
- if encatfalist!=False:
- run(encatfalist)
- wikipedia.stopme()
- sys.exit()
- if not gen:
- wikipedia.stopme()
- sys.exit()
- if namespaces != []:
- gen = pagegenerators.NamespaceFilterPageGenerator( gen,namespaces )
- preloadingGen = pagegenerators.PreloadingGenerator( gen,pageNumber = 60 )
- run( preloadingGen)
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement