08-03-2012, 08:48 AM | #1 |
Member
Posts: 11
Karma: 10
Join Date: Jul 2012
Device: Impression
|
Search/Replace from Title Field to Pubdate
Hi
I spent for now more than an hour trying to use search/replace function using regular expression to extract publishing dates from Title or Authors fields and push them into Publishing date field, I used the expression \d{4} to extract the publish year, the preview of the results is OK, but after applying it, it corrupts the library most of the times (and strangly sometimes works just as supposed) , when it corrupts, calibre thinks that there is unrecognized sting in the pubdate field, and some time recognize it just right (all years that I extracted are valid), is there a way to convert or force calibre to understand that the result of regular expression is a number not a string? or I should do that in some other way? |
08-05-2012, 04:21 AM | #2 | |
Junior Member
Posts: 8
Karma: 10
Join Date: Sep 2010
Device: iPod
|
Quote:
Eg: Search Field: title Search Mode: Regex Search For: (\d{4})-(\d{2}).* Replace With: \2:::\1 (or \2-\1, which works when IMPORTING books) Destination Field: pubdate has these results: TypeError:QDateTime(): arguments did not match any overloaded call: overload 1: too many arguments overload 2: argument 1 has unexpected type 'unicode' overload 3: argument 1 has unexpected type 'unicode' overload 4: argument 1 has unexpected type 'unicode' overload 5: argument 1 has unexpected type 'unicode' So, obviously, field pubdate is expecting an ISO date value instead of a unicode value. But importing automatically typecasts 08-2012 into the apropriate iso value -- so what do we have to do to typecast the unicode value in here? Shouldn't Python be able to do that automatically? Shouldn't QDateTime() be doing this? do I have to somehow pre-transform it via regex? Help please (oh yes, and this results in my database being corrupted every time; so now I make a copy immediately before attempting this, and replace it after killing the process (the above error continuously loops until I kill the process)). Last edited by _Em; 08-05-2012 at 04:25 AM. |
|
Advert | |
|
08-05-2012, 11:27 AM | #3 |
Well trained by Cats
Posts: 30,451
Karma: 58055868
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Peeking into the DB
pubdate is shown as (Type: TIMESTAMP) Code:
2005-02-24 07:00:00 or 2005-02-24 07:00:00+00:00 Yuo might place a literal time value in the replace eg 01:00+00:00 |
08-06-2012, 03:24 AM | #4 |
Grand Sorcerer
Posts: 12,034
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
I was reluctant to make the change to allow search/replace to update date fields precisely because of the possibility of this sort of problem. Calibre was not designed to auto-convert between types and apparently the database calibre uses (SQLite) permits writing trash values into date fields. Sigh ...
The next release (0.8.64) will attempt to convert the string to a date in this case and some other cases that I found. |
08-06-2012, 04:26 AM | #5 | |
Junior Member
Posts: 8
Karma: 10
Join Date: Sep 2010
Device: iPod
|
Quote:
How come the import conversion works correctly? Could the same code be used for the search/replace? |
|
Advert | |
|
08-06-2012, 04:40 AM | #6 | |
Grand Sorcerer
Posts: 12,034
Karma: 7257323
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
FWIW: there was also a path where S/R attempted to set the timestamp. This would never work, so timestamp is no longer a permitted destination field. |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
generate series from title using search and replace | richreads | Calibre | 5 | 06-14-2012 10:36 AM |
Replace field with match or empty string? | charlweed | Library Management | 2 | 03-29-2012 01:44 AM |
Cleaning Title Names using Search and Replace | JTAL604622 | Calibre | 2 | 05-24-2011 06:23 AM |
search and replace - drops blanks in replace ? | cybmole | Conversion | 10 | 03-13-2011 04:07 AM |
Variable Search, Replace & Transfer to a new field | flopis | Library Management | 10 | 03-09-2011 12:41 PM |