Bugs item #1776822, was opened at 2007-08-18 15:01
Message generated for change (Comment added) made by wikipedian
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=1776822&group_…
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Private: No
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: bot fails to run when ctypes not present
Initial Comment:
When ctypes is not present, a missing declaration in terminal_interface.py (probably caused by r4002) causes python to stop with the following error message: http://adam78.webzona.hu/pywiki.gif
(Name error: global name 'startTagR' is not defined in userinterfaces/terminal_interface.py, line 109).
Note that while the comment before the else branch claims it is used only with python<2.5, at least one user with the last version of python for windows reported this.
Quick workaround is to set colorized_output = False in user-config.py.
----------------------------------------------------------------------
>Comment By: Daniel Herding (wikipedian)
Date: 2007-08-18 22:40
Message:
Logged In: YES
user_id=880694
Originator: NO
This should now be fixed in CVS.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=1776822&group_…
Revision: 4072
Author: siebrand
Date: 2007-08-18 18:10:50 +0000 (Sat, 18 Aug 2007)
Log Message:
-----------
Patches by Filnik.
Modified Paths:
--------------
trunk/pywikipedia/welcome.py
Modified: trunk/pywikipedia/welcome.py
===================================================================
--- trunk/pywikipedia/welcome.py 2007-08-18 15:29:43 UTC (rev 4071)
+++ trunk/pywikipedia/welcome.py 2007-08-18 18:10:50 UTC (rev 4072)
@@ -72,6 +72,9 @@
-random Use a random signature, taking the signatures from a wiki
page (for istruction, see below).
+ -file[:#] Use a file instead of a wikipage to take the random sign.
+ N.B. If you use this parameter, you don't need to use -random.
+
-savedata This feature saves the random signature index to allow to
continue to welcome with the last signature used.
@@ -157,6 +160,7 @@
import wikipedia, config, string, locale
import time, re, cPickle, os, urllib
+import codecs, wikipediatools
locale.setlocale(locale.LC_ALL,'')
@@ -173,7 +177,7 @@
random = False # should signature be random or not
savedata = False # should save the signature index or not
filename = 'welcome.data' # file where is stored the random signature index
-directory = str(os.getcwd())
+fileOption = False # check if the user wants to use a file or the wikipage
# Script users the class wikipedia.translate() to find the right
# page/user/summary/etc so the need to specify language and project have
@@ -328,7 +332,7 @@
# I search with a regex how many user have not the talk page
# and i put them in a list (i find it more easy and secure)
while 1:
- regl = "(\"|\')(.*?)(\"|\')(, |\))"
+ regl = r"(\"|\')(.*?)(\"|\')(, |\))"
page = re.compile(regl, re.UNICODE)
xl = page.search(raw, pos)
if xl == None:
@@ -355,7 +359,7 @@
# and i put them in a list (i find it more easy and secure)
while 1:
# FIXME: That's the regex, if there are problems, take a look here.
- reg = '\(<a href=\"/w/index.php\?title=' + talk + '(.*?)&(amp;|)action=edit\"'
+ reg = r'\(<a href=\"/w/index.php\?title=' + talk + r'(.*?)&(amp;|)action=edit\"'
p = re.compile(reg, re.UNICODE)
x = p.search(raw, pos)
if x == None:
@@ -372,8 +376,7 @@
userpage = wikipedia.Page(wsite, username)
usertalkpage = wikipedia.Page(wsite, talk + username)
# Defing the contrib's page of the user
- # TODO: Doesn't work if path is not /wiki/
- con = '/wiki/Special:Contributions/'+ userpage.urlname()
+ con = pathWiki + 'Special:Contributions/'+ userpage.urlname()
# Getting the contribs...
contribs = wsite.getUrl(con)
contribnum = contribs.count('<li>') # Maxes at 50, but not important
@@ -421,8 +424,9 @@
wikipedia.output(u'%s is already in the report page.' % username)
def blocked(wsite, username):
+ pathWiki = wsite.family.nicepath(wsite.lang)
#A little function to check if the user has already been blocked (to skip him).
- reg = """<li>[0-9][0-9]:[0-9][0-9], [0-9]([0-9])? (.*?) [0-9][0-9][0-9][0-9] <a href=\"/wiki/(.*?)\" title=\"(.*?)\">(.*?)</a> \(<a href=\"/wiki/(.*?)\" title=\"(.*?)\">(.*?)</a>"""
+ reg = r"""<li>[0-9][0-9]:[0-9][0-9], [0-9]([0-9])? (.*?) [0-9][0-9][0-9][0-9] <a href=\"""" + pathWiki + r"""(.*?)\" title=\"(.*?)\">(.*?)</a> \(<a href=\"""" + pathWiki + r"""(.*?)\" title=\"(.*?)\">(.*?)</a>"""
block_text = wsite.getUrl('/w/index.php?title=Special:Log/block&page=User:' + username)
numblock = re.findall(reg, block_text)
# If the bot doesn't find block-line, it will return False otherwise True.
@@ -431,12 +435,22 @@
else:
return True
-def defineSign(wsite, signPageTitle):
+def defineSign(wsite, signPageTitle, fileSignName, fileOption = False):
#A little function to load the random signatures.
- signPage = wikipedia.Page(wsite, signPageTitle)
- signText = signPage.get()
- reg = "\* ?(.*?)\n"
- listSign = re.findall(reg, signText)
+ reg = r"^\* ?(.*?)$"
+ creg = re.compile(reg, re.M)
+ if fileOption == False:
+ signPage = wikipedia.Page(wsite, signPageTitle)
+ signText = signPage.get()
+ else:
+ try:
+ f = codecs.open(wikipediatools.absoluteFilename(fileSignName), 'r', encoding = config.console_encoding)
+ except:
+ f = codecs.open(wikipediatools.absoluteFilename(fileSignName), 'r', encoding = 'utf-8')
+ signText = f.read()
+ f.close()
+
+ listSign = creg.findall(signText)
return listSign
def logmaker(wsite, welcomed_users):
@@ -507,6 +521,13 @@
offset_variable = int(wikipedia.input(u'Which offset for new users would you like to use?'))
else:
offset_variable = int(arg[8:])
+ elif arg.startswith('-file:'):
+ random = True
+ fileOption = True
+ if len(arg) == 6:
+ fileSignName = wikipedia.input(u'Where have you saved your signatures?')
+ else:
+ fileSignName = arg[6:]
elif arg == '-break':
recursive = False
elif arg == '-nlog':
@@ -531,6 +552,7 @@
numberlog = int(arg[11:])
# The site
wsite = wikipedia.getSite()
+ pathWiki = wsite.family.nicepath(wsite.lang)
# A little block-statement to ensure that the bot won't start with en-parameters
if wsite.lang not in project_inserted:
wikipedia.output(u'Your project is not supported by the framework. You have to edit the script and add it!')
@@ -555,18 +577,16 @@
talk = urlname(talk_page, wsite) + ':'
# A parameter for different projects of the same language...
- if wsite.family.name == "wikinews":
- if wsite.lang == "it":
- logg = u'Wikinotizie:Benvenuto log'
- welcomer = u'{{subst:benvenuto|%s}}'
- sign = 'Tooby'
- elif wsite.family.name == "wiktionary":
- if wsite.lang == "it":
- logg = u'Wiktionary:Benvenuto log'
- welcomer = u'{{subst:Utente:Filnik/Benve|nome={{subst:PAGENAME}}}} %s'
+ if wsite.family.name == "wikinews" and wsite.lang == "it":
+ welcomer = u'{{subst:benvenuto|%s}}'
+ sign = 'Tooby'
+ elif wsite.family.name == "wiktionary" and wsite.lang == "it":
+ welcomer = u'{{subst:Utente:Filnik/Benve|nome={{subst:PAGENAME}}}} %s'
+ elif wsite.family.name == "wikiversity" and wsite.lang == "it":
+ welcomer = u'{{subst:Benvenuto}} %s'
welcomed_users = list()
- if savedata == True and os.path.exists(directory + '/' + filename):
+ if savedata == True and os.path.exists(wikipediatools.absoluteFilename(filename)):
f = file(filename)
number_user = cPickle.load(f)
else:
@@ -653,7 +673,7 @@
if random == True:
try:
wikipedia.output(u'Loading random signatures...')
- signList = defineSign(wsite, signPageTitle)
+ signList = defineSign(wsite, signPageTitle, fileSignName, fileOption)
except wikipedia.NoPage:
wikipedia.output(u'The list with signatures is not available... Using default signature...')
random = False
@@ -793,4 +813,4 @@
f = file(filename, 'w')
cPickle.dump(number_user, f)
f.close()
- wikipedia.stopme()
\ No newline at end of file
+ wikipedia.stopme()
Revision: 4070
Author: misza13
Date: 2007-08-18 14:24:41 +0000 (Sat, 18 Aug 2007)
Log Message:
-----------
* Archiver object and variable dict are now passed as low as to the Page object, which alows a variable-based header of a new archive.
* Fixed two instances where variables where not int()'d before being used.
Modified Paths:
--------------
trunk/pywikipedia/archivebot.py
Modified: trunk/pywikipedia/archivebot.py
===================================================================
--- trunk/pywikipedia/archivebot.py 2007-08-18 13:11:24 UTC (rev 4069)
+++ trunk/pywikipedia/archivebot.py 2007-08-18 14:24:41 UTC (rev 4070)
@@ -177,15 +177,19 @@
Feed threads to it and run an update() afterwards."""
#TODO: Make it a subclass of wikipedia.Page
- def __init__(self, title, header='{{talkarchive}}'):
+ def __init__(self, title, archiver, vars=None):
self.title = title
self.threads = []
self.Page = wikipedia.Page(Site,self.title)
self.full = False
+ self.archiver = archiver
+ self.vars = vars
try:
self.loadPage()
except wikipedia.NoPage:
- self.header = header
+ self.header = archiver.get('archiveheader','{{talkarchive}}')
+ if self.vars:
+ self.header = self.header % self.vars
def loadPage(self):
"""Loads the page to be archived and breaks it up into threads."""
@@ -257,7 +261,7 @@
self.tpl = tpl
self.salt = salt
self.force = force
- self.Page = DiscussionPage(Page.title())
+ self.Page = DiscussionPage(Page.title(),self)
self.loadConfig()
self.commentParams = {
'from' : self.Page.title,
@@ -300,7 +304,7 @@
if mode == 0 or not self.get('algo',''):
raise MissingConfigError
- def feedArchive(self, archive, thread, maxArchiveSize):
+ def feedArchive(self, archive, thread, maxArchiveSize, vars=None):
"""Feed the thread to one of the archives.
If it doesn't exist yet, create it.
If archive name is an empty string (or None), discard the thread (/dev/null).
@@ -310,7 +314,7 @@
if not self.force and not self.Page.title+'/' == archive[:len(self.Page.title)+1] and not self.key_ok():
raise ArchiveSecurityError
if not self.archives.has_key(archive):
- self.archives[archive] = DiscussionPage(archive)
+ self.archives[archive] = DiscussionPage(archive,self,vars)
return self.archives[archive].feedThread(thread,maxArchiveSize)
def analyzePage(self):
@@ -321,7 +325,7 @@
T = time.mktime(time.gmtime())
whys = []
for t in oldthreads:
- if len(oldthreads) - self.archivedThreads <= self.get('minthreadsleft',5):
+ if len(oldthreads) - self.archivedThreads <= int(self.get('minthreadsleft',5)):
break #Because there's too little threads left.
#TODO: Make an option so that unstamped (unsigned) posts get archived.
why = t.shouldBeArchived(self)
@@ -336,7 +340,7 @@
'monthnameshort' : int2month_short(TStuple[1]),
}
archive = archive % vars
- if self.feedArchive(archive,t,maxArchSize):
+ if self.feedArchive(archive,t,maxArchSize,vars):
archCounter += 1
self.set('counter',str(archCounter))
whys.append(why)
@@ -347,7 +351,7 @@
def run(self):
whys = self.analyzePage()
- if self.archivedThreads < self.get('minthreadstoarchive',2):
+ if self.archivedThreads < int(self.get('minthreadstoarchive',2)):
return #We might not want to archive a measly few threads (lowers edit frequency)
if whys:
#Save the archives first (so that bugs don't cause a loss of data)
Bugs item #1776822, was opened at 2007-08-18 06:01
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=1776822&group_…
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: bot fails to run when ctypes not present
Initial Comment:
When ctypes is not present, a missing declaration in terminal_interface.py (probably caused by r4002) causes python to stop with the following error message: http://adam78.webzona.hu/pywiki.gif
(Name error: global name 'startTagR' is not defined in userinterfaces/terminal_interface.py, line 109).
Note that while the comment before the else branch claims it is used only with python<2.5, at least one user with the last version of python for windows reported this.
Quick workaround is to set colorized_output = False in user-config.py.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603138&aid=1776822&group_…