View Single Post
Old 08-05-2012, 04:21 AM   #2
_Em
Junior Member
_Em began at the beginning.
 
Posts: 8
Karma: 10
Join Date: Sep 2010
Device: iPod
Quote:
Originally Posted by TMSxMR View Post
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?
I've spent quite some time trying to figure this out, and I always get a "unicode values" error resulting in too many values of the wrong type reported.

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.
_Em is offline   Reply With Quote