View Single Post
Old 05-15-2020, 07:08 AM   #497
DictatorAlly
Enthusiast
DictatorAlly began at the beginning.
 
Posts: 26
Karma: 10
Join Date: May 2020
Device: None
I was thinking it could speed up requests. It doesn't sound fit for purpose when it doesn't return all the books though.

I would like to suggest some different feature additions to this GR plugin.

I am currently working on them, but any help would be appreciated.

I would like to add 4 options to to the parse_tags function.

The first option would be to add all found GR genre's to the filter list, this would be a user option: ON/OFF. They would be added with a key and value equal to the GR genre.

Then I would like the user to choose between 3 methods when adding tags. The current and default method: Exclusive, plus two new methods: No Filter and Inclusive.

The current method will only add tag's if they are found in the user filter list. We keep this method the same and call this option: Method to add found Tags: Exclusive.

The next option No Filter would add all GR genre's found as tag's without passing them through the user filter. This option is the easiest to code, and currently work's in the code below.

I am stuck on the coding for this option. The third option, Inclusive, would work the same as Exclusive (passing all GR genre's through the filter) at first but then it will also include all GR genre's found that are not on the user filter list.

One problem not yet solved with these new feature's, how do we ignore a GR genre? Perhap's with some logic where we put the genre in the user filter with the value "IGNORED". Though this doesn't sound great, as it would break the Exclusive function, I think there would be a better way. Perhaps a new list for only ignored term's .

This is what I have so far, I'm having trouble iterating over a list I am removing item's from:
Spoiler:

Code:
    def parse_tags(self, root):
        # Goodreads does not have "tags", but it does have Genres (wrapper around popular shelves)
        # We will use those as tags (with a bit of massaging)
        genres_node = root.xpath('//div[@class="stacked"]/div/div/div[contains(@class, "bigBoxContent")]/div/div[@class="left"]')
        #self.log.info("Parsing tags")
        if genres_node:
            #self.log.info("Found genres_node")
            genre_tags = list()
            for genre_node in genres_node:
                sub_genre_nodes = genre_node.xpath('a')
                genre_tags_list = [sgn.text_content().strip() for sgn in sub_genre_nodes]
                #self.log.info("Found genres_tags list:", genre_tags_list)
                if genre_tags_list:
                    genre_tags.append(' > '.join(genre_tags_list))
            no_filter_tags = genre_tags
            exclusive_tags = self._convert_genres_to_calibre_tags(genre_tags)
            inclusive_tags = exclusive_tags + self._remove_filtered_genre_tags(genre_tags)
            calibre_tags = inclusive_tags
            if len(calibre_tags) > 0:
                return calibre_tags

    def _remove_filtered_genre_tags(self, genre_tags):
        # for each tag, remove if we have a dictionary lookup
        calibre_tag_lookup = cfg.plugin_prefs[cfg.STORE_NAME][cfg.KEY_GENRE_MAPPINGS]
        calibre_tag_map = dict((k.lower(), k) for k in calibre_tag_lookup.keys())
        self.log.info("Keys - Found calibre_tag_map keys result:", calibre_tag_map)
        for genre_tag in reversed(genre_tags):
            tags = calibre_tag_map.get(genre_tag.lower(), None)
            self.log.info("Keys - tags result::", tags)
            if tags:
                for tag in tags:
                    if tag in tags_to_remove:
                        genre_tags.remove(tag)
                        self.log.info("Keys - Removing from genre_tags keys result:", tag)
        return list(tags_to_remove)
DictatorAlly is offline   Reply With Quote