Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 08-21-2020, 08:22 AM   #1
likekindle
Member
likekindle began at the beginning.
 
Posts: 21
Karma: 10
Join Date: Apr 2019
Device: Kindle
How to set customer column value in plugin?

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.
likekindle is offline   Reply With Quote
Old 08-21-2020, 09:18 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,851
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Metadata download plugins can only store data in builtin columns, not custom one.
kovidgoyal is offline   Reply With Quote
Advert
Old 08-21-2020, 10:40 AM   #3
likekindle
Member
likekindle began at the beginning.
 
Posts: 21
Karma: 10
Join Date: Apr 2019
Device: Kindle
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.
likekindle is offline   Reply With Quote
Old 08-21-2020, 11:14 AM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,851
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
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.
kovidgoyal is offline   Reply With Quote
Old 08-21-2020, 11:21 AM   #5
likekindle
Member
likekindle began at the beginning.
 
Posts: 21
Karma: 10
Join Date: Apr 2019
Device: Kindle
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?
likekindle is offline   Reply With Quote
Advert
Old 08-21-2020, 05:27 PM   #6
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 20,567
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
@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
BetterRed is offline   Reply With Quote
Old 08-21-2020, 10:47 PM   #7
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
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.
davidfor is offline   Reply With Quote
Old 08-22-2020, 05:20 AM   #8
likekindle
Member
likekindle began at the beginning.
 
Posts: 21
Karma: 10
Join Date: Apr 2019
Device: Kindle
@BetterRed Thanks, it seems a little complicated for me, i may try it later if i have no other ways.
likekindle is offline   Reply With Quote
Old 08-22-2020, 05:29 AM   #9
likekindle
Member
likekindle began at the beginning.
 
Posts: 21
Karma: 10
Join Date: Apr 2019
Device: Kindle
@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
likekindle is offline   Reply With Quote
Old 08-22-2020, 06:48 AM   #10
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,907
Karma: 47303748
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
Quote:
Originally Posted by likekindle View Post
@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.
davidfor is offline   Reply With Quote
Old 08-22-2020, 07:25 AM   #11
likekindle
Member
likekindle began at the beginning.
 
Posts: 21
Karma: 10
Join Date: Apr 2019
Device: Kindle
@davidfor
Thank you so much, it works for me, and saves a lot of time for me.

Cheers
likekindle is offline   Reply With Quote
Reply

Tags
custom column, metadata, plugin development


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Set a value to a custom column inside a plugin thiago.eec Development 2 08-27-2019 05:48 PM
How to set value of custom column automatically? steins Plugins 5 12-27-2018 03:23 AM
Set or Freeze Column Widths? Nyssa Library Management 14 11-20-2014 02:57 PM
Set value of another column from composite? dirgeon Library Management 1 02-03-2013 11:40 AM
Using OnDevice to set the value of a custom column WendyR14 Library Management 3 10-23-2011 08:03 PM


All times are GMT -4. The time now is 10:48 PM.


MobileRead.com is a privately owned, operated and funded community.