Utente:ItwikiBot/datiwikipedie.py: differenze tra le versioni
Vai alla navigazione
Vai alla ricerca
Contenuto cancellato Contenuto aggiunto
Nuova pagina |
rimossa mo.wikipedia.org |
||
Riga 26: | Riga 26: | ||
ws = WikiStats() |
ws = WikiStats() |
||
stats = ws.sorted('wikipedia', 'good') |
stats = ws.sorted('wikipedia', 'good') |
||
# rimuove mo.wikipedia.org redirect a ro.wikipedia.org |
|||
stats = [stat for stat in stats if stat['prefix'] != 'mo'] |
|||
now = datetime.datetime.now() |
now = datetime.datetime.now() |
||
text = '{{#switch:{{{1}}}\n' |
text = '{{#switch:{{{1}}}\n' |
Versione delle 17:33, 27 lug 2018
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# (C) https://it.wikipedia.org/wiki/Utente:Rotpunkt, 2018, under the MIT License
# Aggiorna le statistiche di https://it.wikipedia.org/wiki/Template:Dati_Wikipedie/dati
#
import datetime
from pywikibot import date
from pywikibot.data.wikistats import WikiStats
import pywikibot
def formatStat(args):
return '''| {prefix} = {{{{#switch:{{{{{{2}}}}}}
| NUMBEROFARTICLES | ARTICLES = {good}
| NUMBEROFFILES | FILES = {images}
| NUMBEROFPAGES | PAGES = {total}
| NUMBEROFUSERS | USERS = {users}
| NUMBEROFACTIVEUSERS | ACTIVEUSERS = {activeusers}
| NUMBEROFADMINS | ADMINS = {admins}
| NUMBEROFEDITS | EDITS = {edits}
| 0 }}}}\n'''.format(**args)
def main():
ws = WikiStats()
stats = ws.sorted('wikipedia', 'good')
# rimuove mo.wikipedia.org redirect a ro.wikipedia.org
stats = [stat for stat in stats if stat['prefix'] != 'mo']
now = datetime.datetime.now()
text = '{{#switch:{{{1}}}\n'
text += '| data = %d %s %d\n' % (now.day, date.formats['MonthName']['it'](now.month), now.year)
total = { 'good': 0, 'images': 0, 'total': 0, 'users': 0, 'activeusers': 0, 'admins': 0, 'edits': 0 }
for stat in stats:
text += formatStat(stat)
for key in total:
total[key] += int(stat[key])
total['prefix'] = 'total'
text += formatStat(total)
text += '| 0 }}\n'
pywikibot.handleArgs()
site = pywikibot.Site()
page = pywikibot.Page(site, 'Template:Dati Wikipedie/dati')
page.put(text, 'Bot: aggiornamento dati')
if __name__ == '__main__':
main()