Dinika amin'ny Wikipedia:Takelaka

Avy amin'i Wikipedia
Aller à la navigation Aller à la recherche

Aligôritma mametraka santiônan-dahatsoratra[hanova ny fango]

Misy aligôritma python noforonona ho an'ny fametrahana votoatiny hiseho eo amin'ny pejy Fandraisana, noforonoko :

# -*- coding: utf-8  -*-
"""
Famoroanna ny pejy fikojakojana eo amin'ny Fandraisana, Wikipedia
"""
import wikipedia, pagegenerators, wikipedia as pywikibot

wiki = wikipedia.getSite('mg','wikipedia')
wiki2 = wikipedia.Site('mg','wikipedia')
volana = ['','Janoary','Febroary','Martsa','Aprily','Mey','Jiona',
          'Jolay','Aogositra','Septambra','Oktobra','Novambra','Desambra']




class Fandraisana:
    import re, sys, catlib
    def __init__(self):
        self.taona = 2011
        self.Pejy = "Fandraisana"
        self.PejyTakelakaVolana = u"Wikipedia:Takelaka/" # N°volana N°taona
        self.Efemeride = u"Wikipedia:Efemerida/" # andro anarambolana
        self.Miarahamiasa = u"Wikipedia:Miaraha miasa/" #taona
        self.List = open("goodlist.txt","r")
        self.goodlist = []
        for n in self.List.readlines():
            self.goodlist.append(n)

    def _cleanuppage(self, content, page):
        findIB = content.find(u"Infobox ")
        findEndIB = content.find(u"}}\n\n", findIB)+4
        
        if ((findIB > -1) and findEndIB > -1):
            clean_content = content[findEndIB:findEndIB+1000]                        
        else: 
            clean_content = content[0:findEndIB+1000]

        content = clean_content
        lastdot = content.rfind('.')
        
        clean_content = content[0:lastdot+1]
        reffindinc1 = clean_content.find('<ref')
        reffindinc2 = clean_content.find('</ref>', reffindinc1)
        ref = clean_content[reffindinc1+4:reffincinc2]
        
        clean_content = clean_content.replace(ref,'')
      
        return (clean_content + ' {{tohiny|%s}}' %(page))
        
        
    def amboaryPejyTakelakaVolana(self):
        import random
        """Mamoaka pejy iray ao amin'ny fizarana 'Takelak'ity volana ity'"""
        # Mijery an'ireo pejy izay efa namorona
        for Ntaona in range(self.taona,self.taona+2):
            for Nvolana in range(1,13):
                pgen = str(self.PejyTakelakaVolana + u"%s %s" %(Nvolana, Ntaona))
                
                print pgen
                page_volana = wikipedia.Page(wiki, pgen)
                
                if page_volana.exists() is False:
                    randompage = self.goodlist[random.randint(0,len(self.goodlist)-1)].replace('\n','') # maka lahatsoratra tsara ao amin'ny lisitra
                    Wpgen = (wikipedia.Page(wiki, randompage).get())
                    page_volana.put(self._cleanuppage(Wpgen, randompage), 'Famoronana ny lahatsoratra')
                    print (" Voaforona soa amantsara ny ambangovangon'ny lahatsoratra %s hiseho eo amin'ny pejy fandraisana\n"
                           " Vangio ny pejy %s ho an'ny fanitsiana." %(randompage, randompage))
                else:
                    print " Volana %s ny taona %s efa manana lahatsoratra." %(volana[Nvolana], Ntaona)
                    continue
            

    def amboaryEfemeride(self):
        """Mamoaka efemerida iray ao amin'ny fizarana 'Efemerida'"""
        pass # Mbola am-panamboarana      
        

    def amboaryMiarahamiasa(self):
        """Mamoaka pejy eo amin'ny fiarana 'Miarahamiasa'"""
        pass #Mbola am-pamamboarana

def main():
    Fandraisana().amboaryPejyTakelakaVolana()


if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        wikipedia.stopme()
    finally:
        wikipedia.stopme()

--grr... | 9 Oktobra 2011 à 17:15 (UTC)