Utente:IncolaBot/Script e Utente:Ricordisamoa/createbar.py: differenze tra le pagine
(Differenze fra le pagine)
Contenuto cancellato Contenuto aggiunto
aggiorno |
pywikibot.Category() |
||
Riga 1: | Riga 1: | ||
== createbar.py == |
|||
<source lang="python"> |
<source lang="python"> |
||
#!/usr/bin/python |
#!/usr/bin/python |
||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||
## |
## |
||
# 23.00 UTC -> 0.00 CET |
# 23.00 UTC -> 0.00 CET |
||
# 22.00 UTC -> 0.00 CEST |
# 22.00 UTC -> 0.00 CEST |
||
## |
## |
||
import os |
import os |
||
import time |
import time |
||
import |
import pywikibot |
||
os.environ['TZ'] = 'Europe/Rome' |
os.environ['TZ'] = 'Europe/Rome' |
||
monthConv = { |
monthConv = { |
||
1: 'gennaio', |
|||
2: 'febbraio', |
|||
3: 'marzo', |
|||
4: 'aprile', |
|||
5: 'maggio', |
|||
6: 'giugno', |
|||
7: 'luglio', |
|||
8: 'agosto', |
|||
9: 'settembre', |
|||
10: 'ottobre', |
|||
11: 'novembre', |
|||
12: 'dicembre', |
|||
} |
} |
||
args = |
args = pywikibot.handleArgs() |
||
site = pywikibot.Site('it', 'wikipedia') |
|||
curYear = time.strftime("%Y") |
curYear = time.strftime("%Y") |
||
curMonth = time.strftime("%m") |
curMonth = time.strftime("%m") |
||
curDay = str(int(time.strftime("%d"))) |
curDay = str(int(time.strftime("%d"))) |
||
def create_only(page, text, summary): |
|||
pageBarTitle = wikipedia.Page(wikipedia.getSite('it', 'wikipedia'), "Wikipedia:Bar/" + curYear + '_' + curMonth + '_' + curDay) |
|||
⚫ | |||
pageBarText = "<noinclude>\n{{Bar4/light}}\n=" + curDay + ' ' + monthConv[int(curMonth)] + "=\n__TOC__\n[[Categoria:Wikipedia Bar - " + curDay + ' ' + monthConv[int(curMonth)] + ' ' + curYear + "]]\n[[Categoria:Archivio bar]]\n</noinclude>" |
|||
page.text = text |
|||
page.save(summary) |
|||
if not pageBarTitle.exists(): |
|||
⚫ | |||
pageBarTitle.put(pageBarText, u"Bot: Creo sottopagina del bar odierno") |
|||
⚫ | |||
⚫ | |||
wikipedia.output(str(pageBarTitle) + " already exists: skip.") |
|||
pageBarTitle = pywikibot.Page(site, "Wikipedia:Bar/{anno} {mese} {giorno}".format(anno=curYear, mese=curMonth, giorno=curDay)) |
|||
pageBarText = ("<noinclude>\n{{{{Bar4/light}}}}\n={giorno} {mese}=\n__TOC__\n[[Categoria:Wikipedia Bar - {giorno} {mese} {anno}]]\n" |
|||
⚫ | |||
"[[Categoria:Archivio bar]]\n</noinclude>" |
|||
⚫ | |||
).format(giorno=curDay, mese=monthConv[int(curMonth)], anno=curYear) |
|||
⚫ | |||
create_only(pageBarTitle, pageBarText, u"Bot: Creo sottopagina del bar odierno") |
|||
else: |
|||
dayCatTitle = pywikibot.Category(site, "Wikipedia Bar - {giorno} {mese} {anno}".format(anno=curYear, mese=monthConv[int(curMonth)], giorno=curDay)) |
|||
⚫ | |||
⚫ | |||
monthCatTitle = wikipedia.Page(wikipedia.getSite('it', 'wikipedia'), "Categoria:Wikipedia Bar - " + monthConv[int(curMonth)] + ' ' + curYear) |
|||
create_only(dayCatTitle, dayCatText, u"Bot: Creo categoria del bar odierno") |
|||
⚫ | |||
monthCatText = "[[Categoria:Wikipedia Bar - Archivi per mese " + curYear + "| " + curMonth + "]]" |
monthCatText = "[[Categoria:Wikipedia Bar - Archivi per mese " + curYear + "| " + curMonth + "]]" |
||
⚫ | |||
if not monthCatTitle.exists(): |
|||
⚫ | |||
yearCatTitle = pywikibot.Category(site, "Wikipedia Bar - Archivi per mese " + curYear) |
|||
else: |
|||
yearCatText = ("In questa categoria sono raggruppate le categorie che raccolgono tutte le sottopagine del bar di uno stesso mese del {anno}. " |
|||
wikipedia.output(str(monthCatTitle) + " already exists: skip.") |
|||
"Ogni categoria mensile contiene le categorie giornaliere, che contengono le pagine giornaliere e tutte le sottopagine di " |
|||
"discussione del giorno.\n\n[[Categoria:Wikipedia Bar - Archivi per mese| {anno}]]" |
|||
).format(anno=curYear) |
|||
yearCatText = "In questa categoria sono raggruppate le categorie che raccolgono tutte le sottopagine del bar di uno stesso mese del " + curYear + ". Ogni categoria mensile contiene le categorie giornaliere, che contengono le pagine giornaliere e tutte le sottopagine di discussione del giorno.\n\n[[Categoria:Wikipedia Bar - Archivi per mese| " + curYear + "]]" |
|||
⚫ | |||
if not yearCatTitle.exists(): |
|||
⚫ | |||
⚫ | |||
else: |
|||
wikipedia.output(str(yearCatTitle) + " already exists: skip.") |
|||
⚫ | |||
weekCatText = "[[Categoria:Wikipedia Bar - Archivi per settimana " + time.strftime("%G") + "]]" |
weekCatText = "[[Categoria:Wikipedia Bar - Archivi per settimana " + time.strftime("%G") + "]]" |
||
⚫ | |||
if not weekCatTitle.exists(): |
|||
⚫ | |||
weekYearCatTitle = pywikibot.Category(site, "Wikipedia Bar - Archivi per settimana" + time.strftime(" %G")) |
|||
else: |
|||
weekYearCatText = ("In questa categoria sono raggruppate le categorie che raccolgono tutte le sottopagine del bar di una stessa settimana del {anno}. " |
|||
wikipedia.output(str(weekCatTitle) + " already exists: skip.") |
|||
"Ogni categoria settimanale contiene direttamente ogni sottopagina di discussione della settimana corrispondente.\n\n" |
|||
"[[Categoria:Wikipedia Bar - Archivi per settimana| {anno}]]" |
|||
).format(anno=time.strftime("%G")) |
|||
weekYearCatText = "In questa categoria sono raggruppate le categorie che raccolgono tutte le sottopagine del bar di una stessa settimana del " + time.strftime("%G") + ". Ogni categoria settimanale contiene direttamente ogni sottopagina di discussione della settimana corrispondente.\n\n[[Categoria:Wikipedia Bar - Archivi per settimana| " + time.strftime("%G") + "]]" |
|||
⚫ | |||
if not weekYearCatTitle.exists(): |
|||
⚫ | |||
else: |
|||
wikipedia.output(str(weekYearCatTitle) + " already exists: skip.") |
|||
wikipedia.stopme() |
|||
</source> |
</source> |
Versione delle 14:52, 5 mag 2014
#!/usr/bin/python
# -*- coding: utf-8 -*-
##
# 23.00 UTC -> 0.00 CET
# 22.00 UTC -> 0.00 CEST
##
import os
import time
import pywikibot
os.environ['TZ'] = 'Europe/Rome'
monthConv = {
1: 'gennaio',
2: 'febbraio',
3: 'marzo',
4: 'aprile',
5: 'maggio',
6: 'giugno',
7: 'luglio',
8: 'agosto',
9: 'settembre',
10: 'ottobre',
11: 'novembre',
12: 'dicembre',
}
args = pywikibot.handleArgs()
site = pywikibot.Site('it', 'wikipedia')
curYear = time.strftime("%Y")
curMonth = time.strftime("%m")
curDay = str(int(time.strftime("%d")))
def create_only(page, text, summary):
if not page.exists():
page.text = text
page.save(summary)
else:
pywikibot.output("{} already exists: skip.".format(page))
pageBarTitle = pywikibot.Page(site, "Wikipedia:Bar/{anno} {mese} {giorno}".format(anno=curYear, mese=curMonth, giorno=curDay))
pageBarText = ("<noinclude>\n{{{{Bar4/light}}}}\n={giorno} {mese}=\n__TOC__\n[[Categoria:Wikipedia Bar - {giorno} {mese} {anno}]]\n"
"[[Categoria:Archivio bar]]\n</noinclude>"
).format(giorno=curDay, mese=monthConv[int(curMonth)], anno=curYear)
create_only(pageBarTitle, pageBarText, u"Bot: Creo sottopagina del bar odierno")
dayCatTitle = pywikibot.Category(site, "Wikipedia Bar - {giorno} {mese} {anno}".format(anno=curYear, mese=monthConv[int(curMonth)], giorno=curDay))
dayCatText = "[[Categoria:Wikipedia Bar - {mese} {anno}]]".format(anno=curYear, mese=monthConv[int(curMonth)])
create_only(dayCatTitle, dayCatText, u"Bot: Creo categoria del bar odierno")
monthCatTitle = pywikibot.Category(site, "Wikipedia Bar - " + monthConv[int(curMonth)] + ' ' + curYear)
monthCatText = "[[Categoria:Wikipedia Bar - Archivi per mese " + curYear + "| " + curMonth + "]]"
create_only(monthCatTitle, monthCatText, u"Bot: Creo categoria mensile del bar")
yearCatTitle = pywikibot.Category(site, "Wikipedia Bar - Archivi per mese " + curYear)
yearCatText = ("In questa categoria sono raggruppate le categorie che raccolgono tutte le sottopagine del bar di uno stesso mese del {anno}. "
"Ogni categoria mensile contiene le categorie giornaliere, che contengono le pagine giornaliere e tutte le sottopagine di "
"discussione del giorno.\n\n[[Categoria:Wikipedia Bar - Archivi per mese| {anno}]]"
).format(anno=curYear)
create_only(yearCatTitle, yearCatText, u"Bot: Creo categoria annuale del bar")
weekCatTitle = pywikibot.Category(site, "Wikipedia Bar - Archivio" + time.strftime(" %G-") + str(int(time.strftime("%V"))))
weekCatText = "[[Categoria:Wikipedia Bar - Archivi per settimana " + time.strftime("%G") + "]]"
create_only(weekCatTitle, weekCatText, u"Bot: Creo categoria settimanale del bar")
weekYearCatTitle = pywikibot.Category(site, "Wikipedia Bar - Archivi per settimana" + time.strftime(" %G"))
weekYearCatText = ("In questa categoria sono raggruppate le categorie che raccolgono tutte le sottopagine del bar di una stessa settimana del {anno}. "
"Ogni categoria settimanale contiene direttamente ogni sottopagina di discussione della settimana corrispondente.\n\n"
"[[Categoria:Wikipedia Bar - Archivi per settimana| {anno}]]"
).format(anno=time.strftime("%G"))
create_only(weekYearCatTitle, weekYearCatText, u"Bot: Creo categoria annuale del bar")