View Single Post
Old 03-27-2024, 06:46 AM   #1
413Michele
Enthusiast
413Michele began at the beginning.
 
Posts: 47
Karma: 10
Join Date: Jan 2021
Location: Italy
Device: Kobo Libra 2, Kindle Paperwhite (1st gen)
Question Help with image processing

Hi all,

some time ago I wrote a recipe for the Plane Crash Series on Medium. I recently picked it up again and improved it after gaining some knowledge of Python, and I believe I obtained a good result of extracting the main text and minimising Medium's clutter.

The only thing missing that I'd like to add is a custom cover. I implemented the get_cover_url method as shown here:

Code:
def get_cover_url(self):
        soup = self.index_to_soup('https://admiralcloudberg.medium.com/about')
        cover_url_list = []
        for style in soup.find_all('style'):
            for element in style:
                match = re.search('https://.+?\.jpeg', element)
                cover_url_list.append(match)
        i = 0
        while i < len(cover_url_list):
            if cover_url_list[i] is not None:
                cover_url = cover_url_list[i].group()
            i = i+1
        return cover_url
to retrieve the image I want to use. The image however has a landscape aspect ratio: I'd like to crop it to obtain a portrait-style cover.

After looking at calibre's code, it seems this function does what I need, but I have no idea how to deal with files in a news recipe, particularly retrieving them and passing them along between methods. Could somebody help me with this?

The full recipe is attached for reference
Attached Files
File Type: recipe myrecipe.recipe (4.6 KB, 37 views)
413Michele is offline   Reply With Quote