View Single Post
Old 02-23-2012, 10:54 AM   #13
ilovejedd
hopeless n00b
ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.ilovejedd ought to be getting tired of karma fortunes by now.
 
ilovejedd's Avatar
 
Posts: 5,110
Karma: 19597086
Join Date: Jan 2009
Location: in the middle of nowhere
Device: PW4, PW3, Libra H2O, iPad 10.5, iPad 11, iPad 12.9
Woohoo. Just installed a nightly build of PRS+ (thanks Analogus!) and it now supports sub-collections. Granted, it's just one level but that's good enough for me. Here's a revised template to get sub-collections. Basically the same as chaley's script above except it uses Series| and Genre| as the prefix instead of Series: and Genre:

Code:
'''
Function: myFunc
Arg count: 1

Documentation:
myFunc(categories) -- Format tags and series so they show up as sub-collections on the PRS+ custom firmware for Sony Readers.

example:
{:'myFunc('fiction, non-fiction, fanfiction, magazine, news')'} - Creates a top-level collection for any tag named fiction, non-fiction, fanfiction, magazine or news. All other tags will be created as sub-collections under Genre.
'''

def evaluate(self, formatter, kwargs, mi, locals, cats):
    categories = set([v.strip() for v in cats.split(',') if v.strip()])
    tags = [v.strip() for v in kwargs.get('tags') if v.strip()]
    res = []
    for v in tags:
        if v.lower() in categories:
            res.append(v)
        else:
            res.append('Genre|' + v)
    series = kwargs.get('series')
    if series:
        res.append('Series|' + series)
    return ', '.join(res)

I've also created a modified version of the script which would create the sub-collections under the main categories.

e.g.
Fiction, Children, Fantasy -> Fiction, Fiction|Children, Fiction|Fantasy
FanFiction, Harry Potter, Twilight -> FanFiction, FanFiction|Harry Potter, FanFiction|Twilight
News, New York Times -> News, News|New York Times
Code:
'''
Function: myFunc
Arg count: 1

Documentation:
myFunc(categories) -- Format tags and series so they show up as sub-collections on the PRS+ custom firmware for Sony Readers.

example:
{:'myFunc('fiction, non-fiction, fanfiction, magazine, news')'} - Creates a top-level collection for any tag named fiction, non-fiction, fanfiction, magazine or news. All other tags will be created as sub-collections under one of the top-level collections. If a main category isn't found, the book is assigned to Fiction.
'''

def evaluate(self, formatter, kwargs, mi, locals, cats):
    categories = set([v.strip() for v in cats.split(',') if v.strip()])
    tags = [v.strip() for v in kwargs.get('tags') if v.strip()]
    res = []
    booktype = ''
    for v in tags:
        if v.lower() in categories:
            booktype = v
    if booktype == '':
        booktype = 'Fiction'
    res.append(booktype)
    for v in tags:
        if v.lower() not in categories:
            res.append(booktype + '|' + v)
    series = kwargs.get('series')
    if series:
        res.append('Series|' + series)
    return ', '.join(res)
Help optimizing would be much appreciated. I'm sure there's a much better way to get the booktype without having to iterate through all the tags.

Screenshots of how sub-collections work can be found here:
https://www.mobileread.com/forums/sho...postcount=2964
ilovejedd is offline   Reply With Quote