See also ebooksgratis.com: no banners, no cookies, totally FREE.

CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
Privacy Policy Cookie Policy Terms and Conditions

See also ebooksgratis.com: no banners, no cookies, totally FREE.

CLASSICISTRANIERI HOME PAGE - YOUTUBE CHANNEL
Privacy Policy Cookie Policy Terms and Conditions
సభ్యులు:Mpradeepbot/mpc.mandalTemplates.py - వికీపీడియా

సభ్యులు:Mpradeepbot/mpc.mandalTemplates.py

వికీపీడియా నుండి

ఈ ప్రోగ్రాముకు సహాయకారిగా ఈ ఫైలును ఉపయోగించండి.

import wikipedia, time, catlib, codecs, config

####################################################################################################
# This function returns the list of articles as a list object
# in given category.  Please give only the Category Name,
# namespace will be addd automatically.
# --function requires both 'wikipedia' and 'catlib' to be imported
def getArticleList(catTitle):
    cat = catlib.Category(wikipedia.getSite(), u'Category:'+catTitle)
    listOfArticles = cat.articles()
    return listOfArticles
####################################################################################################

####################################################################################################
# Get the data from the given page name
def getData(pageTitle):
  page = wikipedia.Page(wikipedia.getSite(), pageTitle)
  try:
    # Load the page's text from the wiki
    action = 'normal'
    title = pageTitle
    pageData = page.get(get_redirect=True)
    if page.isRedirectPage() :
      action = 'redirected'
      title = page.getRedirectTarget()
      page = wikipedia.Page(wikipedia.getSite(), title)
      pageData = page.get()
  except wikipedia.NoPage:
    action = 'nopage'
    title = pageTitle
    pageData = u''
  return pageData, action, title
####################################################################################################

####################################################################################################
# Replace the contents in the page 'pageTitle' with data 'pageData' 
# and add the comment 'comment'
def writeData(pageTitle, pageData, comment):
  page = wikipedia.Page(wikipedia.getSite(), pageTitle)
  try:
    page.put(pageData, comment = comment)
  except wikipedia.EditConflict:
    wikipedia.output(u'Skipping %s because of edit conflict' % (page.title()))
  except wikipedia.SpamfilterError, url:
    wikipedia.output(u'Cannot change %s because of blacklist entry %s' % (page.title(), url))
####################################################################################################


##############################################################################################
datafile = open('mpc.mandalTemplates.txt', 'rb' )
logfile = codecs.open('mpc.mandalTemplates.log', encoding='utf-8', mode='wb')

#omit 3 characters if it is UTF-8
datafile.read(3)

#first line is the name of text to be appended at the end of each article
line = unicode(datafile.readline(), 'utf8')
line = line.replace(u'\n', u'')
comment = line.replace(u'\r', u'')

line = unicode(datafile.readline(), 'utf8')
line = line.replace(u'\n', u'')
vargaM = line.replace(u'\r', u'')

line = unicode(datafile.readline(), 'utf8')
line = line.replace(u'\n', u'')
kalapaMDi = line.replace(u'\r', u'')

line = unicode(datafile.readline(), 'utf8')
line = line.replace(u'\n', u'')
noinclude = line.replace(u'\r', u'')

line = unicode(datafile.readline(), 'utf8')
line = line.replace(u'\n', u'')
templateComment = line.replace(u'\r', u'')

line = unicode(datafile.readline(), 'utf8')
line = line.replace(u'\n', u'')
disambigText = line.replace(u'\r', u'')

templateList = getArticleList(kalapaMDi)

for template in templateList:
  pageData, action, title = getData(template.title())
  templateName = template.title()[4:]
  templateData = pageData

  pageData = pageData[pageData.find('|list1= '):]
  pageData = pageData[pageData.find('[[')+2:]

  logfile.write(u'* processing ' + templateName + u'\r\n')
  while pageData.find(']]{{') != -1:
    index = pageData.find(']]{{')
    villageName = pageData[0:index]
    pageData = pageData[index+9:]
    index = villageName.find('|')
    if index!=-1:
      villageName = villageName[0:index]

    villageData, action, title = getData(villageName)
    if action == 'redirected' and title != villageName:
      logfile.write(u'** [[' + villageName + ']] is redirected to [[' + title + ']]\r\n')
      villageName = title
    if villageData.find(disambigText) != -1:
      logfile.write(u'** [[' + villageName + ']] is a disambiguation page.\r\n')
      villageData = u'';


    if villageData.find('{{' + templateName + '}}') == -1:
      villageData = villageData.replace(vargaM, '\n{{' + templateName + '}}\n\n'+vargaM, 1)
      writeData(villageName, villageData, comment)
#      logfile.write(u'** Adding {{tl|'+templateName + u'}} to [['+ villageName +']] \r\n')
    else:
      logfile.write(u'** Skipping [['+ villageName +']] because {{tl|'+templateName + u'}} already exist in that page\r\n')


  index = pageData.find(']]')
  villageName = pageData[0:index]
  pageData = pageData[index+9:]
  index = villageName.find('|')
  if index!=-1:
    villageName = villageName[0:index]

  villageData, action, title = getData(villageName)
  if action == 'redirected' and title != villageName:
    logfile.write(u'** [[' + villageName + ']] is redirected to [[' + title + ']]\r\n')
    villageName = title

  if villageData.find('{{' + templateName + '}}') == -1:
    villageData = villageData.replace(vargaM, '\n{{' + templateName + '}}\n\n'+vargaM, 1)
    writeData(villageName, villageData, comment)
#    logfile.write(u'** Adding {{tl|'+templateName + u'}} to [['+ villageName +']] \r\n')
  else:
    logfile.write(u'** Skipping [['+ villageName +']] because {{tl|'+templateName + u'}} already exist in that page\r\n')

  # update the template page by removing the 'kalapaMDi' category
  templateData = templateData.replace(noinclude, '')
  writeData(template.title(), templateData, templateComment)

  logfile.write(u'\r\n\r\n')

logfile.close()
datafile.close()


aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -


aa - ab - af - ak - als - am - an - ang - ar - arc - as - ast - av - ay - az - ba - bar - bat_smg - bcl - be - be_x_old - bg - bh - bi - bm - bn - bo - bpy - br - bs - bug - bxr - ca - cbk_zam - cdo - ce - ceb - ch - cho - chr - chy - co - cr - crh - cs - csb - cu - cv - cy - da - de - diq - dsb - dv - dz - ee - el - eml - en - eo - es - et - eu - ext - fa - ff - fi - fiu_vro - fj - fo - fr - frp - fur - fy - ga - gan - gd - gl - glk - gn - got - gu - gv - ha - hak - haw - he - hi - hif - ho - hr - hsb - ht - hu - hy - hz - ia - id - ie - ig - ii - ik - ilo - io - is - it - iu - ja - jbo - jv - ka - kaa - kab - kg - ki - kj - kk - kl - km - kn - ko - kr - ks - ksh - ku - kv - kw - ky - la - lad - lb - lbe - lg - li - lij - lmo - ln - lo - lt - lv - map_bms - mdf - mg - mh - mi - mk - ml - mn - mo - mr - mt - mus - my - myv - mzn - na - nah - nap - nds - nds_nl - ne - new - ng - nl - nn - no - nov - nrm - nv - ny - oc - om - or - os - pa - pag - pam - pap - pdc - pi - pih - pl - pms - ps - pt - qu - quality - rm - rmy - rn - ro - roa_rup - roa_tara - ru - rw - sa - sah - sc - scn - sco - sd - se - sg - sh - si - simple - sk - sl - sm - sn - so - sr - srn - ss - st - stq - su - sv - sw - szl - ta - te - tet - tg - th - ti - tk - tl - tlh - tn - to - tpi - tr - ts - tt - tum - tw - ty - udm - ug - uk - ur - uz - ve - vec - vi - vls - vo - wa - war - wo - wuu - xal - xh - yi - yo - za - zea - zh - zh_classical - zh_min_nan - zh_yue - zu -