![]() |
#1 |
Junior Member
![]() Posts: 2
Karma: 10
Join Date: Mar 2015
Device: none
|
Advanced Custom Icon with two requirements
First I would like to say HELP! Please and thank you. And I apologize for the long post up front.
I have been searching for the answer to this for four days now and I finally realized that I am not going to be able to figure this out on my own. I have read and reread almost every forum I could find and even spent a day searching Python. For those of you who understand this, well, my hats off to you...really, I mean that! Here is what I need/want/pray to the powers that be for, I am trying to create a custom icon that will appear when two conditions are met that will appear in its own column. Now my problem is that I have too many people - 'authors' in over a hundred different libraries. I use Calibre as a CMS...please don't ask, it's complicated but how I use it works the same way as someone using it for books, only with a LOT of books, or in my case files that are PDF's, RTF's, DOC's,...you get the idea. So, I have a bazillion books with thousands of people-authors. What I wanted to do was to find a way when I am uploading the new files to tell me if the author - person is already in the database, any of the databases at the same time when uploaded to one of the three upload libraries. The column I would like to reflect with an icon is called 'SA', I have the 'Authors' column, naturally, and another that is called 'New'. I would like for the 'SA' - #same_account -Column to show the icon if: 1. The 'New' Column is true. (This is a yes/no column) - #new 2. And if the 'Author' column matches any author in any database. The first part was easy enough to do in the Column Icons section, but the problem arises when I try to match the authors, now what I initially did was to add a rule that said if the 'Author' column 'has' and then I added some names with the & separator and it worked fabulously. I did my happy dance and then I formatted my csv file with all of the people-authors that I have and simply copy and pasted them into the new rule I created...This is where the problem occurred. I have too many authors it would not allow all of them to be entered. Well, bah! That won't work. So I checked into the advanced rule. Thus began my four day journey into frustration. I thought it would be so simple as I am not completely unintelligent. Python, along with the Calibre manual teased me relentlessly, telling me I could add an 'or' statement with as many values as I like, but not once did it show me how to format the code to do so, as well as other statements, 'with', 'and', etc. Okay in python's and Calibre's defense they do show the format but it's like trying to decipher hieroglyphics before the discovery of the Rosetta Stone. Google was not my friend. I did, however, managed to figure out the code for the 'New' Column which is: program: b = field('#new'); contains(b, 'Y', 'redbarrel.png', '') Don't know if that is the correct format but it worked, only those that were selected as 'New' got the icon. Awesome! Now I just need the other part of the code. So here is where I beg prettily for help. Now I tried a plethora of variations of the only two codes that I found on other posts: program: a = field('authors'); contains(a, 'John Doe', 'tincan.png', 'redcheck.png') This statement worked well by itself but I could not add two lines or more than one author name, because really, let's face it. I was doing it completely wrong. Apparently you cant add two Program statements to the same rule. I understand you can somehow compare the field('author') to a .csv list (or perhaps another file format), but again with the teasing. I feel like I am on some kind of a ten step program. Step 1. Admit you have a problem....Well, I admit it. If someone could help me. I would so appreciate any assistance (the code to make it work would be awesome!) Oh I also learned how to make a list: lists1 = ['John Doe' , 'Jane Doe', 'Farmer John'] This could represent the authors but I have no idea what to do with it, but I made it! Please help me! Thanks in advance. |
![]() |
![]() |
![]() |
#2 | |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
General Program Mode is activated by the "program:" at the beginning -- it means everything afterward is a part of the program. Don't repeat that text twice, simply end all statements with a ";" and the last one will be evaluated as the template result.
and(value, value, ...) Quote:
Code:
program: # return "Yes" if #new is set to yes, else return empty. rule1 = contains( field('#new'), 'Yes', 'Yes', '' ); # Return the list of authors that are in both # the authors field and a custom list. # Returns empty if there are no matches. list_of_authors = 'author1, author2, author3'; rule2 = list_intersection( list_of_authors, field('authors'), '&' ); # The "and" function tests if both rules returned # a value (and are therefore true). test( and(rule1, rule2), 'icon-if-true', '' ); TBH, this should probably be a custom python script run through calibre-debug.exe which writes the appropriate values to a custom column after evaluating the data. That would be a lot more usable. |
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Junior Member
![]() Posts: 2
Karma: 10
Join Date: Mar 2015
Device: none
|
This is solved...Thank You!
Well hello eschwartz, my favorite Irrational Optimist,
First I would like to say thank you so very, very, much! I believe you may be a God! I seriously am thinking of building a shrine in your honor in the back forty, sort of a Stonehenge of Iowa, now that I will have so much extra time since I will not have to sort through every file that I receive individually. Just so you don't think I was sitting idly by waiting for an answer, well okay, I did do just that for a day, but one can only wait on hold for so long. I did not give up on this, as a matter of fact I have spent hours every day trying to figure this out. Yeah, I know, doesn't say much for my intelligence but at least I'm persistent, or my OCD kicked in and would not let go, and I figured if I could not get help by groveling I would have to find the solution myself. I am smiling right now because for the last four hours I have downloaded and installed Python, PyCharm, QT5, and QT4 and I did a small tutorial. Yes, folks I was on my way to becoming a Python expert. My "Hello World" worked just fine, thank you very much. Then I saw your post and realized I could stop banging my head against the desktop. Your code worked flawlessly! I realize now why my efforts were not working, thank you for the tips. I was trying to put brackets everywhere, counting out four spaces. etc. I feel ridiculous right about now, but I don't care because I finally have my solution. I think you are right about putting this into a custom Python script. I did read the manual! I think I might try that, who knows maybe the thing might even work. I will let you know if I ever get it completed, for now though I am taking a Python break. Thank you again eschwartz, really, I mean that. Your help is more than appreciated! |
![]() |
![]() |
![]() |
#4 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Sure.
![]() A couple things, might be useful.
Last edited by eschwartz; 03-11-2015 at 02:20 AM. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
simple requirements: eink, epub, and custom fonts | aarcane | Which one should I buy? | 7 | 06-29-2014 09:42 PM |
Custom news source (basic/advanced) | bleario | Recipes | 1 | 04-05-2014 08:27 AM |
Custom Column Icon Help | alanHd | Library Management | 2 | 02-04-2013 03:30 AM |
Problem with Tag Browser Custom Icon for Languages | MartyTX | Library Management | 1 | 02-03-2013 03:44 AM |
Custom Icon Issues | allovertheglobe | iRex | 0 | 10-26-2008 03:40 PM |