def run(self): adq_wp = [] adq_base = [] res = BeBot.charger_bdd(self.conn, self.nom_base, ordre='"titre" ASC') for r in res: adq_base.append(pywikibot.Page(self.site, r['titre'])) for cat in self.cats: labels = pywikibot.Category(self.site, cat) for a in labels.articles(): adq_wp.append(a) # Différences nouveaux = list(set(adq_wp) - set(adq_base)) dechus = list(set(adq_base) - set(adq_wp)) for a in nouveaux: self.ajouteralabdd(a) for a in dechus: self.supprimerdelabdd(a) if len(dechus) > 0: pywikibot.output("Articles déchus de leur status : {0}".format(dechus)) # Génération du flux res = BeBot.charger_bdd(self.conn, self.nom_base, lim=50, ordre='"date" DESC') for r in res: p = pywikibot.Page(self.site, r['titre']) date = datetime.datetime.strptime(r['date'], '%Y-%m-%d %H:%M:%S') categorie = r['label'] self.ajouterauflux(p, date, categorie) if not self.debug: #self.feed.write(self.fp, 'utf-8') self.fp.write(self.feed.to_string()) pywikibot.output("Nombre de modifications sur la base : {0}".format(self.conn.total_changes)) self.fp.close()
def lycos(self, nom_base, conditions=None, limite=None): """ Récupère les articles labellisés de la base correspondants à certaines conditions """ rep = {} champs = [ 'page', 'taille', 'traduction', 'label' ] articles = BeBot.charger_bdd(self.db, nom_base, \ champs=", ".join(champs), cond=conditions) #articles = sorted(articles.items()) i = 0 for a in articles: if limite is not None and i >= limite: break i += 1 page = {} nom_page = unicode(a[0], 'UTF-8') page[champs[1]] = int(a[1]) if a[2] is not None: page[champs[2]] = unicode(a[2], 'UTF-8') else: page[champs[2]] = None page[champs[3]] = unicode(a[3], 'UTF-8') page['avancement'] = BeBot.info_wikiprojet( \ pywikibot.Page(self.site_fr, nom_page), \ self.avancementER, 'avancement', \ self.retrait_avancement) rep[nom_page] = page return rep
def run(self): NB_AJOUTS = 0 RETRAITS = True connus = BeBot.charger_bdd(self.db, self.nom_base, champs=u'page') connus = map(self.normaliser_page, connus) self.total_avant = len(connus) ordre_cats = [ u'AdQ', u'BA', u'?' ] for cat in self.cat_qualite: categorie = pywikibot.Category(self.site, cat) cpg = pagegenerators.CategorizedPageGenerator(categorie, recurse=False) try: i = self.categories_de_qualite[self.langue].index(cat) except: i = 2 cattoa = ordre_cats[i] for p in pagegenerators.DuplicateFilterPageGenerator(cpg): if NB_AJOUTS < 2000: if p.namespace() == 0: page = p elif p.namespace() == 1: # Pour EN:GA et IT:FA page = p.toggleTalkPage() else: continue if page.isRedirectPage(): page = page.getRedirectTarget() title = page.title() if title not in connus: #Comparaison avec le contenu de la bdd infos = self.get_infos(page, cattoa) NB_AJOUTS += 1 if infos is not None: self.nouveau.append(infos) else: connus.remove(title) self.connaitdeja.append( \ { 'page': title, \ 'label': cattoa } ) # Ils ne seront pas ajoutés else: pywikibot.output("Limite d'ajouts atteinte avec "+p.title()) RETRAITS = False break # On retire ceux qui ont disparus if RETRAITS: pywikibot.output('Retraits : '+str(connus)) for c in connus: self.req_bdd(c, 'delete') self.connus = len(connus) pywikibot.log( u"Total: %i ajouts ; %i déjà connus ; %i retraits." \ % (len(self.nouveau), len(self.connaitdeja), len(connus)) )
def run(self): # Dénombrement l = {} cat = pywikibot.Category(self.site, u"Catégorie:Article par importance") for c in cat.subcategories(recurse=False): nom = c.title().split(' ')[-1] l[nom] = 0 for d in c.subcategories(): pages = self.site.categoryinfo(d)['pages'] l[nom] += pages total = 0 for a in l.values(): total += a # Sauvegarde curseur = self.conn.cursor() req = 'INSERT INTO %s' % self.nom_base \ + '(date, maximum, élevée, moyenne, faible, inconnue, total) ' \ + 'VALUES ("%s", %d, %d, %d, %d, %d, %d)' \ % (self.date.strftime("%Y-%m-%d"), l['maximum'], l['élevée'], \ l['moyenne'], l['faible'], l['inconnue'], total) try: curseur.execute(req) except sqlite3.Error as e: pywikibot.error(u"Erreur lors de l'INSERT :\n%s" % (e.args[0])) self.conn.commit() # Dessin largeur = 600 #largeur du graphique maxi = 0 #valeur max en hauteur nb_bande = 6 #nombre max de colonnes #on suppose ici un enregistrement par mois res = BeBot.charger_bdd(self.conn, self.nom_base, lim=nb_bande, ordre='"date" DESC') width = math.ceil(largeur/nb_bande) #largeur d'une bande # Liste des mois à traiter mois = [] for j in range(0, nb_bande): d = self.date + relativedelta(months=-j) mois.append(d.strftime(u"%Y-%m")) # Récupération et tri des valeurs vals = [] ri = 0 # ressource index : index sur les enregistrements utilisés for m in mois: val = {} if m != res[ri]['date'][0:7]: for k in res[ri].keys(): val[k] = 0 val['date'] = m + u"-02" else: for k in res[ri].keys(): val[k] = res[ri][k] if maxi < val['total']: maxi = val['total'] # point le plus haut ri = ri + 1 vals.append(val) vals.reverse() #Majoration du maximum t = maxi rang = 0 while t > 1: t = math.ceil(t/10) rang +=1 graduation = pow(10, rang-2) maxi = maxi + math.floor(graduation/2) maxi = int(math.floor(maxi*pow(10,3-rang))*pow(10,rang-3)) # 3 premiers chiffre significatifs self.msg = dedent(u""" <timeline> Colors= id:lightgrey value:gray(0.9) id:darkgrey value:gray(0.7) id:sfondo value:rgb(1,1,1) id:barra value:rgb(0.7,0.9,0.7) legend:Total id:rouge value:rgb(1,0,0) legend:Max+Élevée id:gris value:rgb(0.95,0.95,0.95) ImageSize = width:%d height:300 Define $width = %d PlotArea = left:60 bottom:20 top:20 right:10 DateFormat = x.y Period = from:0 till:%d TimeAxis = orientation:vertical AlignBars = justify ScaleMajor = gridcolor:darkgrey increment:%d start:0 ScaleMinor = gridcolor:lightgrey increment:%d start:0 BackgroundColors = canvas:sfondo Legend = left:70 top:295"""[1:] % (largeur, width, maxi, graduation, graduation/2) ) #Nom des bars self.msg += '\nBarData=\n' for r in range(0, nb_bande): p = '' if r % 2 == 1: spl = vals[r]['date'].split('-') p = spl[1] + '/' + spl[0][2:] self.msg += ' bar:%d text:%s\n' % (r+1, p) #Valeurs : total self.msg += '\nPlotData=\n color:barra width:$width align:left\n\n' for r in range(0, nb_bande): p = vals[r]['total'] self.msg += ' bar:%d from:0 till: %d\n' % (r+1, p) #Valeurs : importants self.msg += '\nPlotData=\n color:rouge width:$width align:left\n\n' for r in range(0, nb_bande): p = vals[r]['maximum'] + vals[r]['élevée'] self.msg += ' bar:%d from:0 till: %d\n' % (r+1, p) #Labels self.msg += '\nPlotData=\n' for r in range(0, nb_bande): if r % 2 == 1: p = vals[r]['total'] s = self.nombreverschaine(p) self.msg += ' bar:%d at: %d fontsize:S text:"%s" shift:(-20,5)\n' % (r+1, p, s) q = vals[r]['maximum'] + vals[r]['élevée'] s = self.nombreverschaine(q) self.msg += ' bar:%d at: %d fontsize:S text:"%s" shift:(-20,5)\n' % (r+1, q, s) self.msg += '</timeline>' # Publication page = pywikibot.Page(self.site, 'Projet:Évaluation/Évolution') page.text = BeBot.ER_BotSection.sub(self.BotSectionEdit, page.text) BeBot.save(page, commentaire=self.resume, debug=False)