Fix ratings not being downloaded from Amazon

This commit is contained in:
Kovid Goyal 2011-03-16 16:07:09 -06:00
parent 0fbf30487e
commit 68f63e807a

View File

@ -154,17 +154,16 @@ def get_metadata(br, asin, mi):
return False return False
if root.xpath('//*[@id="errorMessage"]'): if root.xpath('//*[@id="errorMessage"]'):
return False return False
ratings = root.xpath('//form[@id="handleBuy"]/descendant::*[@class="asinReviewsSummary"]')
ratings = root.xpath('//div[@class="jumpBar"]/descendant::span[@class="asinReviewsSummary"]')
pat = re.compile(r'([0-9.]+) out of (\d+) stars')
if ratings: if ratings:
pat = re.compile(r'([0-9.]+) out of (\d+) stars') for elem in ratings[0].xpath('descendant::*[@title]'):
r = ratings[0] t = elem.get('title').strip()
for elem in r.xpath('descendant::*[@title]'):
t = elem.get('title')
m = pat.match(t) m = pat.match(t)
if m is not None: if m is not None:
try: try:
mi.rating = float(m.group(1))/float(m.group(2)) * 5 mi.rating = float(m.group(1))/float(m.group(2)) * 5
break
except: except:
pass pass
@ -216,6 +215,7 @@ def main(args=sys.argv):
print 'Failed to downlaod social metadata for', title print 'Failed to downlaod social metadata for', title
return 1 return 1
#print '\n\n', time.time() - st, '\n\n' #print '\n\n', time.time() - st, '\n\n'
print mi
print '\n' print '\n'
return 0 return 0