View Single Post
Old 08-13-2025, 01:39 PM   #4
isarl
Addict
isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.
 
Posts: 293
Karma: 2534928
Join Date: Nov 2022
Location: Canada
Device: Kobo Aura 2
Just in case anybody else finds it helpful, my updated, now functional, template:

Code:
def evaluate(self, formatter, kwargs, metadata, _locals):
    awards = metadata.get('#awards')
    if not awards:
        return ''

    transformed_awards = []
    for award in awards:
        # Split the award record into its components
        components = award.split('.')
        if len(components) < 4:
            return 'error with award: ' + award

        # Extract the name of the award and the category
        award_name = components[0]
        award_name = award_name.removesuffix(' Award').removesuffix(' Awards')
        category_name = components[1]
        category_name = category_name.removeprefix('Best ')

        # Extract the year from the record and determine the decade it falls in
        year = int(components[2])
        decade = str(year // 10 * 10) + "s"

        # Extract the rank from the record and determine whether or not it is a winner
        rank = components[3]
        if rank == "winner":
            rank_message = "winners"
        else:
            rank_message = "nominees, etc."

       # Combine the components into the desired format
        transformed_awards.append(f"Awards: {award_name}, {category_name} ({rank_message})")

    return ':@:'.join(transformed_awards)
isarl is offline   Reply With Quote