Mobileread
How to set customer column value in plugin?
#1  likekindle 08-21-2020, 09:22 AM
Hi there, I have a plugin called "douban.py", which can get some metadata from a website, and I also create a customer column called "#douban_rating".
In the douban.py file, there're code like this:
Code
 def to_metadata(self, browser, log, entry_, timeout): # {{{ from calibre.utils.date import parse_date, utcnow
#...... # Ratings if rating: try: mi.rating = float(rating['average']) / 2.0 except: log.exception('Failed to parse rating') mi.rating = 0
#......
and i want to put the value float(rating['average']) in my column "#douban_rating", how to do that?
Thanks a lot.
Reply 

#2  kovidgoyal 08-21-2020, 10:18 AM
Metadata download plugins can only store data in builtin columns, not custom one.
Reply 

#3  likekindle 08-21-2020, 11:40 AM
Well, are there any workaround to do that? maybe i could just save the value into a txt file, then write a script to load them into my column?
or any other method? i just want to save the rating value into my column.
thanks for reply.
Reply 

#4  kovidgoyal 08-21-2020, 12:14 PM
Save it as a tag and use a custom column template to display it in another column or use search and replace to copy it into another column.
Reply 

#5  likekindle 08-21-2020, 12:21 PM
that seems OK, but i'm not sure how to do that:
"use a custom column template to display it in another column"
"use search and replace to copy it into another column"
could you give me a demo?
Reply 

#6  BetterRed 08-21-2020, 06:27 PM
@likekindle - for the Skoob bookstore (Brazilian) there are two plugins, a Metadata Download plugin, and a GUI plugin called Skoob Synch, you might want to have a look at those, and IIRC Goodreads might have something similar. See ==>> Index of plugins

BR
Reply 

#7  davidfor 08-21-2020, 11:47 PM
The Goodreads_rating plugin does it by adding the rating to the publisher column and then the F_rating plugin moves this to the separate column.
Reply 

#8  likekindle 08-22-2020, 06:20 AM
@BetterRed Thanks, it seems a little complicated for me, i may try it later if i have no other ways.
Reply 

#9  likekindle 08-22-2020, 06:29 AM
@davidfor
that's clever, i've tried the plugins, and they work for me, i could get rating from goodreads and store the value into a custom column.
Then I have to modify my douban plugin just like the goodreads, right?
maybe something like this:
Code
 if rating: try: #print(float(rating['average'])) my_rate = float(rating['average']) print(title + " ----: " + str(my_rate)) if not(mi.rating==None): mi.publisher+="#PrB.rating#"+ str(my_rate) print ('mi.publisher:', mi.publisher) mi.rating = float(rating['average']) / 2.0 except: log.exception('Failed to parse rating') mi.rating = 0
Reply 

#10  davidfor 08-22-2020, 07:48 AM
Quote likekindle
@davidfor
that's clever, i've tried the plugins, and they work for me, i could get rating from goodreads and store the value into a custom column.
Then I have to modify my douban plugin just like the goodreads, right?
maybe something like this:
Code
 if rating: try: #print(float(rating['average'])) my_rate = float(rating['average']) print(title + " ----: " + str(my_rate)) if not(mi.rating==None): mi.publisher+="#PrB.rating#"+ str(my_rate) print ('mi.publisher:', mi.publisher) mi.rating = float(rating['average']) / 2.0 except: log.exception('Failed to parse rating') mi.rating = 0
That should work. But, has "mi.rating" been set earlier? Otherwise, you are testing if it before setting it.
Reply 

  Next »  Last »  (1/2)
Today's Posts | Search this Thread | Login | Register