వాడుకరి:Mpradeepbot/mpc.allWikiStats.py

వికీపీడియా నుండి
Jump to navigation Jump to search
"""
ఈ ప్రోగ్రామును ఒకేసారి అన్ని వికీపీడియాలపై నడపాలి.  అందుకుగాను పైవికీపీడియా ఫోల్డరును భాషకొకటి చప్పున సృష్టించుకోవాలి.
అలా సృష్టించుకున్న తరువాత ప్రతీ భాష ఫోల్డరులో ఆ భాష వికీపీడియాకు తగినట్లుగా user-config.py ఫైలును నిర్మించండి.
ఉదాహరణకు బాటును బెంగాలీ భాషపై నడపాలనుకుంటున్నప్పుడు మీ user-config.py ఫైలు ఈ క్రింది విధముగా ఉండాలి:

mylang='bn'
family='wikipedia'
usernames['wikipedia']['bn'] = u'Mpradeep'

ఈ ప్రోగ్రాము వికీపీడియాలో ఎటువంటి మార్పులు-చేర్పులు చేయదు కాబట్టి దీనిని నడిపుటకు బాటు హోదా అవసరం లేదు...
బాటు తయారు చేసిన గణాంకాలన్నీ "mpc.allWikiStats.log" అనే ఫైలులో చేరతాయి...
"""


import wikipedia, pagegenerators, catlib, config, codecs

firstPageTitle = u'!'

logfile = codecs.open('mpc.allWikiStats.log', encoding='utf-8', mode='wb')

namespace = wikipedia.Page(wikipedia.getSite(), firstPageTitle).namespace()
firstPageTitle = wikipedia.Page(wikipedia.getSite(), firstPageTitle).titleWithoutNamespace()
gen = pagegenerators.AllpagesPageGenerator(firstPageTitle, namespace)

preloadingGen = pagegenerators.PreloadingGenerator(gen, pageNumber = 500)

redirct = 0
locked  = 0
lt2     = 0
gt2lt5  = 0
gt5lt10 = 0
gt10    = 0
total   = 0
eng     = 0

for page in preloadingGen:
    try:
      # Load the page's text from the wiki
      pageData = page.get()
      if not page.canBeEdited():
         wikipedia.output(u'Skipping locked page %s' % page.title())
         locked = locked + 1
         continue
    except wikipedia.NoPage:
       wikipedia.output(u'Page %s not found' % page.title())
       continue
    except wikipedia.IsRedirectPage:
       wikipedia.output(u'Page %s is redirect page' % page.title())
       redirct = redirct + 1
       continue

    total = total + len(pageData)
    for line in pageData:
      for c in line:
        if c.islower() or c.isupper():
          eng = eng + 1

    # Do the accessment of the pages
    if len(pageData) <= 2048:
        # less than 5KB but greater than 2KB
        print u'less than 2KB'
        lt2 = lt2 +1
    elif len(pageData) <= 5120 and len(pageData) > 2048:
        # less than 5KB but greater than 2KB
        print u'less than 5KB but greater than 2KB'
        gt2lt5 = gt2lt5 +1
    elif len(pageData) <= 10240 and len(pageData) > 5120:
        # less than 10KB but greater than 5KB
        print u'less than 10KB but greater than 5KB'
        gt5lt10 = gt5lt10 + 1
    elif len(pageData) > 10240:
        # less than 5KB but greater than 2KB
        print u'less than 10KB but greater than 5KB'
        gt10 = gt10 + 1

# write the results to a file
print u'locked pages = ' + str(locked)
logfile.write(u'locked pages = ' + str(locked) + u'\r\n')
print u'redirect pages = ' + str(redirct)
logfile.write(u'redirect pages = ' + str(redirct) + u'\r\n')

print u'less than 2KB = ' + str(lt2)
logfile.write(u'less than 2KB = ' + str(lt2) + u'\r\n')
print u'less than 5KB = ' + str(gt2lt5)
logfile.write(u'less than 5KB = ' + str(gt2lt5) + u'\r\n')
print u'less than 10KB = ' + str(gt5lt10)
logfile.write(u'less than 10KB = ' + str(gt5lt10) + u'\r\n')
print u'more than 10KB = ' + str(gt10)
logfile.write(u'more than 10KB = ' + str(gt10) + u'\r\n')
print u'total articles = ' + str(lt2+gt2lt5+gt5lt10+gt10)
logfile.write(u'total good articles = ' + str(lt2+gt2lt5+gt5lt10+gt10) + u'\r\n')

print u'english percent = ' + str(eng) + u'/' + str(total) + u'=' + str(((eng*1.0)/total)*100.0)
logfile.write(u'english percent = ' + str(eng) + u'/' + str(total) + u'=' + str(((eng*1.0)/total)*100.0) + u'\r\n')

# close all the open handles
logfile.close()