Utente:G4/Script: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
G4 (discussione | contributi)
G4 (discussione | contributi)
Riga 117:
inseriscitesto.py -perco:c:/ -fileda:testo.txt
</pre>-->
===<tt>inseriscitesto.py</tt> v. 12.50===
<source lang="python">
import re, string, sys, getpass
Riga 124:
 
def scrivi(pagina,testo):
all = False
crlf = chr(13) + chr(10)
sito=wikipedia.getSite(code='it',fam='wikibooks')
Line 135 ⟶ 136:
if i > -1:
break
print i
if i == -1:
testo_nuovo = testo_originale + crlf + crlf + testo
Line 142 ⟶ 141:
testo_nuovo = testo_originale[:i] + crlf + testo + crlf + testo_originale[i:]
 
wikipedia.showDiff(testo_originale, testo_nuovo)
pl.put(testo_nuovo,'+ ' + testo)
printif 'inserito(not ' + testoall):
# Chiede la conferma prima di
#print testo_nuovo
# editare (se non è in modalità automatica)
choice = wikipedia.inputChoice(u"Aggiungo questo testo?", ['Yes', 'No', 'All'], ['y', 'N', 'a'], 'N')
else:
choice = 'y'
if choice in ['A', 'a']:
all = True
choice = 'y'
if choice in ['Y', 'y']:
pl.put(testo_nuovo,'+[[Wikibooks:Bot|Bot]]: Aggiungo: "' + testo + '"')
 
def main():
nomefilecart = "c:/testo.txt"
file = "testo.txt"
args = wikipedia.handleArgs()
for currentArgument in args:
if currentArgument.startswith("-cartella:"):
cart = currentArgument[10:]
# Se l'utente dice da dove deve cominciare, lo memorizza
if currentArgument.startswith("-file:"):
file = currentArgument[6:]
# Se l'utente dice da dove deve cominciare, lo memorizza
if currentArgument.startswith("-always"):
all = True
nomefile = cart + file
f = open(nomefile, 'r')
for line in f.readlines():