Patches item #2005964, was opened at 2008-06-29 17:23
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603140&aid=2005964&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: Melancholie (melancholie)
Assigned to: Nobody/Anonymous (nobody)
Summary: Update/optimization of featured.py
Initial Comment:
1. added dsb summary
2. removed all namespace prefixes (else they just get obsolete with the time); using English standards in that patch (how to use module dicts?)...
Diff patch is attached ;-)
See also coloured diff:
http://als.wikipedia.org/w/index.php?title=Benutzer%3AMelancholieBot%2Ffeat…
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=603140&aid=2005964&group_…
I'm new to using bots. I've had some success, using it on the wiki
appropedia.org, but when I run replace.py without the -always parameter, I
get an error. The second time I answer "y" (yes), I get "RuntimeError:
thread already started" and the bot stops.
E.g. when I run this command:
python replace.py -xml:currentdump.xml -excepttext:"[[appropriate
technology]]" "appropriate technology" "[[appropriate technology]]"
...the first change is successful, but the next time I hit yes, I get:
Do you want to accept these changes? ([y]es, [N]o, [a]ll) y
Changing page [[en:Tire shingles]]
Traceback (most recent call last):
File "replace.py", line 555, in <module>
main()
File "replace.py", line 551, in main
bot.run()
File "replace.py", line 325, in run
page.put_async(new_text)
File "/home/cwg/pwb/wikipedia.py", line 1033, in put_async
_putthread.start()
File "/usr/lib/python2.5/threading.py", line 434, in start
raise RuntimeError("thread already started")
RuntimeError: thread already started
Any help appreciated!
Thanks
--
Chris Watkins (a.k.a. Chriswaterguy)
Appropedia.org - Sharing knowledge to build rich, sustainable lives.
Blog: chriswaterguy.livejournal.com/
Buying at Amazon, eBay etc? Start at http://appropedia.maatiam.com and a
percentage of your purchase supports Appropedia - at no extra cost.
Where men are the most sure and arrogant, they are commonly the most
mistaken, and have there given reins to passion, without that proper
deliberation and suspense, which can alone secure them from the grossest
absurdities. -- David Hume
Revision: 5659
Author: filnik
Date: 2008-06-29 12:54:25 +0000 (Sun, 29 Jun 2008)
Log Message:
-----------
Fixed self.image that was used in multiple functions causing some nosense.
Modified Paths:
--------------
trunk/pywikipedia/checkimages.py
Modified: trunk/pywikipedia/checkimages.py
===================================================================
--- trunk/pywikipedia/checkimages.py 2008-06-29 11:49:33 UTC (rev 5658)
+++ trunk/pywikipedia/checkimages.py 2008-06-29 12:54:25 UTC (rev 5659)
@@ -465,12 +465,15 @@
self.duplicatesReport = duplicatesReport
image_n = self.site.image_namespace()
self.image_namespace = "%s:" % image_n # Example: "User_talk:"
- def report(self, newtext, image, notification = None, head = None,
+ def setParameters(self, image):
+ """ Function to set parameters, now only image but maybe it can be used for others in "future" """
+ self.image = image
+ def report(self, newtext, image_to_report, notification = None, head = None,
notification2 = None, unver = True, commTalk = None, commImage = None):
""" Function to make the reports easier (or I hope so). """
# Defining some useful variable for next...
+ self.image_to_report = image_to_report
self.newtext = newtext
- self.image = image
self.head = head
self.notification = notification
self.notification2 = notification2
@@ -528,7 +531,7 @@
""" Function to add the template in the image and to find out
who's the user that has uploaded the image. """
# Defing the image's Page Object
- p = wikipedia.ImagePage(self.site, 'Image:%s' % self.image)
+ p = wikipedia.ImagePage(self.site, 'Image:%s' % self.image_to_report)
# Get the image's description
try:
testoa = p.get()
@@ -541,14 +544,14 @@
if put:
p.put(testoa + self.newtext, comment = self.commImage, minorEdit = True)
# paginetta it's the image page object.
- paginetta = wikipedia.ImagePage(self.site, self.image_namespace + self.image)
+ paginetta = wikipedia.ImagePage(self.site, self.image_namespace + self.image_to_report)
try:
nick = paginetta.getLatestUploader()[0]
except wikipedia.NoPage:
- wikipedia.output(u"Seems that %s hasn't the image at all, but there is something in the description..." % self.image)
+ wikipedia.output(u"Seems that %s hasn't the image at all, but there is something in the description..." % self.image_to_report)
repme = "\n*[[:Image:%s]] problems '''with the APIs'''"
# We have a problem! Report and exit!
- self.report_image(self.image, self.rep_page, self.com, repme)
+ self.report_image(self.image_to_report, self.rep_page, self.com, repme)
return False
luser = wikipedia.url2link(nick, self.site, self.site)
pagina_discussione = "%s:%s" % (self.site.namespace(3), luser)
@@ -565,7 +568,7 @@
if self.notification2 == None:
self.notification2 = self.notification
else:
- self.notification2 = self.notification2 % self.image
+ self.notification2 = self.notification2 % self.image_to_report
second_text = False
# Getting the talk page's history, to check if there is another advise...
# The try block is used to prevent error if you use an old wikipedia.py's version.
@@ -697,9 +700,8 @@
encodedTitle = title.encode(self.site.encoding())
return urllib.quote(encodedTitle)
- def checkImageOnCommons(self, image):
+ def checkImageOnCommons(self):
""" Checking if the image is on commons """
- self.image = image
wikipedia.output(u'Checking if %s is on commons...' % self.image)
commons_site = wikipedia.getSite('commons', 'commons')
regexOnCommons = r"\n\*\[\[:Image:%s\]\] is also on '''Commons''': \[\[commons:Image:.*?\]\]$" % self.image
@@ -727,7 +729,7 @@
# Problems? No, return True
return True
- def checkImageDuplicated(self, image):
+ def checkImageDuplicated(self):
""" Function to check the duplicated images. """
# {{Dupe|Image:Blanche_Montel.jpg}}
dupText = wikipedia.translate(self.site, duplicatesText)
@@ -736,7 +738,6 @@
dupTalkText = wikipedia.translate(self.site, duplicates_user_talk_text)
dupComment_talk = wikipedia.translate(self.site, duplicates_comment_talk)
dupComment_image = wikipedia.translate(self.site, duplicates_comment_image)
- self.image = image
duplicateRegex = r'\n\*(?:\[\[:Image:%s\]\] has the following duplicates:|\*\[\[:Image:%s\]\])$' % (self.convert_to_url(self.image), self.convert_to_url(self.image))
imagePage = wikipedia.ImagePage(self.site, 'Image:%s' % self.image)
hash_found = imagePage.getHash()
@@ -1126,6 +1127,7 @@
except IndexError:# Namespace image not found, that's not an image! Let's skip...
wikipedia.output(u"%s is not an image, skipping..." % image.title())
continue
+ mainClass.setParameters(imageName) # Setting the image for the main class
# Skip block
if skip == True:
# If the images to skip are more the images to check, make them the same number
@@ -1164,16 +1166,16 @@
wikipedia.output(u"Skipping %s because it has been deleted." % imageName)
continue
except wikipedia.IsRedirectPage:
- wikipedia.output(u"The file description for %s is a redirect?!" % imageName )
+ wikipedia.output(u"The file description for %s is a redirect?!" % imageName)
continue
# Check on commons if there's already an image with the same name
if commonsActive == True:
- response = mainClass.checkImageOnCommons(imageName)
+ response = mainClass.checkImageOnCommons()
if response == False:
continue
# Check if there are duplicates of the image on the project selected
if duplicatesActive == True:
- response2 = mainClass.checkImageDuplicated(imageName)
+ response2 = mainClass.checkImageDuplicated()
if response2 == False:
continue
# Is the image already tagged? If yes, no need to double-check, skip
Revision: 5657
Author: filnik
Date: 2008-06-29 11:24:10 +0000 (Sun, 29 Jun 2008)
Log Message:
-----------
Little bugfix for image.getHash()
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2008-06-29 11:16:09 UTC (rev 5656)
+++ trunk/pywikipedia/wikipedia.py 2008-06-29 11:24:10 UTC (rev 5657)
@@ -2641,25 +2641,29 @@
""" Function that return the Hash of an image in oder to understand if two
Images are the same or not.
"""
- params = {
- 'action' :'query',
- 'titles' :self.title(),
- 'prop' :'imageinfo',
- 'iiprop' :'sha1',
- }
- # First of all we need the Hash that identify an image
- data = query.GetData(params, useAPI = True, encodeTitle = False)
- pageid = data['query']['pages'].keys()[0]
- try:
- hash_found = data['query']['pages'][pageid][u'imageinfo'][0][u'sha1']
- except KeyError:
- if self.exists():
- raise NoHash('No Hash found in the APIs! Maybe the regex to catch it is wrong or someone has changed the APIs structure.')
+ if self.exists():
+ params = {
+ 'action' :'query',
+ 'titles' :self.title(),
+ 'prop' :'imageinfo',
+ 'iiprop' :'sha1',
+ }
+ # First of all we need the Hash that identify an image
+ data = query.GetData(params, useAPI = True, encodeTitle = False)
+ pageid = data['query']['pages'].keys()[0]
+ try:
+ hash_found = data['query']['pages'][pageid][u'imageinfo'][0][u'sha1']
+ except KeyError:
+ if self.exists():
+ raise NoHash('No Hash found in the APIs! Maybe the regex to catch it is wrong or someone has changed the APIs structure.')
+ else:
+ wikipedia.output(u'Image deleted before getting the Hash. Skipping...')
+ return None
else:
- wikipedia.output(u'Image deleted before getting the Hash. Skipping...')
- return None
+ return hash_found
else:
- return hash_found
+ wikipedia.output(u'Image deleted before getting the Hash. Skipping...')
+ return None
def getFileVersionHistoryTable(self):
"""Return the version history in the form of a wiki table."""