View Single Post
Old 09-02-2022, 09:50 PM   #26
jcnelson
Junior Member
jcnelson began at the beginning.
 
Posts: 1
Karma: 10
Join Date: Jun 2021
Device: kindle paperwhite 2
# of ratings modification

Hello,

I love this plug in! Thank you so much for spending time to create and maintain it! I had found a suggested edit to your code that added the count of ratings in the publisher field along with the rating itself (below). Though I am no programmer, I was able to use column formatting in Calibre to parse it and convert the text into 2 separate custom number columns so they were sortable. It really helps me understand how meaningful the rating is. Sadly, with the recent update to 4.0, I can't figure out how to incorporate below into the new version. Is there an easy way to do this or would it need to be re-written by something more capable than myself?


ADDED THIS to your version based on 1.5.1 (I believe):
try:
mi.publisher, mi.pubdate = self.parse_publisher_and_date(root)
# Added 1 line below
mi.publisher = self.parse_rating_withcount(root)
except:
self.log.exception('Error parsing publisher and date for url: %r'%self.url)


THEN ADDED THIS AT THE END:
# Added section below
def parse_rating_withcount(self, root):
# rating_node = root.xpath('//div[@id="metacol"]/div[@id="bookMeta"]/span[@class="value rating"]/span')
rating_node = root.xpath('//span[@itemprop="ratingValue"]')
rating_count = root.xpath('//*[@itemprop="ratingCount"]/@content')
# rating_node = root.xpath('//div[@id="metacol"]/div[@id="details"]/div[@class="buttons"]/div[@id="bookDataBox"]/div/div[@itemprop="inLanguage"]')
self.log.info("parse_rating: rating_node=", rating_node)
if rating_node and len(rating_node) > 0:
try:
self.log.info("parse_rating: have rating node - rating_node[0].text=", rating_node[0].text)
rating_text = rating_node[0].text
rating_value = float(rating_text)
rating_text = rating_node[0].text + " " + rating_count[0]
# rating_text = rating_count[0]
return rating_text
except:
self.log.info("parse_rating: Exception getting rating")
import traceback
traceback.print_stack()
return None
jcnelson is offline   Reply With Quote