![]() |
#1 |
Junior Member
![]() Posts: 4
Karma: 10
Join Date: Nov 2010
Device: Kindle 3
|
Write custom column from Python
Hello,
Sorry for a noob question but I have one-day experience with Python. I'm working on a metadata downloader plugin and I would like to store a source URL for the metadata. I have created a new database field called url (multiline, non-taggable text) and want my script to fill it in. This is what I tried: mi = Metadata(title) ... fill in other stuff mi.url = sourceurl This doesn't give any error but also leaves the field empty. Any help would be appreciated. |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
All custom attributes begin with '#'. which means that you cannot use attribute notation to set them. Use mi['#url'] = ..., where '#url' is the sort key, instead.
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Junior Member
![]() Posts: 4
Karma: 10
Join Date: Nov 2010
Device: Kindle 3
|
Thanks for the tip, but I couldn't make it work.
coverurl = root.xpath(xpath_cover) if len(coverurl) > 0: mi['#molyurl'] = coverurl[0] I'm getting this error: 'Metadata' object does not support item assignment. |
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Sorry. Been a while since I messed with the code.
Try mi.set(field key, field value) e.g. mi.set('#foo', 'this is what foo is') If 'foo' is a series-type field, then you need to supply a third parameter that is the series index. The python prototype is 'def set(self, field, val, extra=None):' |
![]() |
![]() |
![]() |
#5 |
Junior Member
![]() Posts: 4
Karma: 10
Join Date: Nov 2010
Device: Kindle 3
|
Thanks, but still no joy. This did not cause any error, but doesn't fill the field either.
Looking at the code of metadata, my suspicion is that it only accepts fields it already knows about: elif field in _data['user_metadata'].iterkeys(): ... store the value If I'm not wrong, this field is initialized with an empty map. I tried mi = Metadata(title, authors=[], other={'#molyurl':'x'}) but this results in some other strange error, 'dict' object has no title or something similar. |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
A metadata instance will contain custom field information only if someone has put it there. Because of that, I think you are facing at least two problems.
1) If you are creating a Metadata instance yourself, then it will have no knowledge of custom fields. The only way I know to get a complete Metadata instance for a given db/custom column set is to use library.database2.get_metadata. 2) Assigning a metadata field in the mi structure has no effect on anything. Something later must take that data and put it into the database. I have no idea where that happens, or how it happens. That said, it is highly unlikely to work unless the code calls the set_metadata method in database2. My guess is that the plugin doesn't know about the database (doesn't have an instance of an open db), in which case you will not be able to see custom field information. I am uninterested in plugins, so I can't give you any more information than that. FWIW: the 'other' argument to the constructor is expected to be a Metadata instance, not some random dict. |
![]() |
![]() |
![]() |
#7 |
Junior Member
![]() Posts: 4
Karma: 10
Join Date: Nov 2010
Device: Kindle 3
|
Thanks, I'll then just put it in the Comment field with some special mark.
|
![]() |
![]() |
![]() |
#8 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,443
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
###myurl###:the url text:###/myurl### source: comments search for: ###myurl### ![]() replace with:\1 Destination: #myurl A similar one would remove the tagged text from comments. |
|
![]() |
![]() |
![]() |
Tags |
custom metadata access |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Custom column read ? | pchrist7 | Calibre | 2 | 10-04-2010 02:52 AM |
custom column i need a little help | shinken | Calibre | 3 | 09-15-2010 03:41 AM |
Custom Column Problem | MSJim | Calibre | 7 | 09-08-2010 05:07 PM |
custom column not searchable | SkyDream | Calibre | 5 | 07-26-2010 05:38 AM |
Calibre custom news feed and python help. | harrynewman | Calibre | 4 | 10-08-2009 09:26 AM |