From f83fee99f3579b58292cfeda41ebf774aea5643e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Sat, 6 Sep 2025 00:09:11 +0200 Subject: [PATCH] Enhance DropCampaignFeed to include detailed drop information in the RSS feed --- twitch/feeds.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/twitch/feeds.py b/twitch/feeds.py index eb088ca..9f4f183 100644 --- a/twitch/feeds.py +++ b/twitch/feeds.py @@ -98,6 +98,69 @@ class DropCampaignFeed(Feed): if item.end_at: description += f"

Ends: {item.end_at.strftime('%Y-%m-%d %H:%M %Z')}

" + # Add information about the drops in this campaign + drops = item.time_based_drops.select_related().prefetch_related("benefits").all() # type: ignore[attr-defined] + if drops: + description += "

Drops in this campaign:

" + table_header = ( + '' + "" + '' + '' + '' + '' + "" + ) + description += table_header + + for drop in drops: + description += "" + # Benefits column with images + description += '" + + # Drop name + description += f'' + + # Requirements + requirements = "" + if drop.required_minutes_watched: + requirements = f"{drop.required_minutes_watched} minutes watched" + if drop.required_subs > 0: + if requirements: + requirements += f" and {drop.required_subs} subscriptions required" + else: + requirements = f"{drop.required_subs} subscriptions required" + description += f'' + + # Period + period = "" + if drop.start_at: + period += drop.start_at.strftime("%Y-%m-%d %H:%M %Z") + if drop.end_at: + if period: + period += " - " + drop.end_at.strftime("%Y-%m-%d %H:%M %Z") + else: + period = drop.end_at.strftime("%Y-%m-%d %H:%M %Z") + description += f'' + + description += "" + + description += "
BenefitsDrop NameRequirementsPeriod
' + for benefit in drop.benefits.all(): + if benefit.image_asset_url: + description += format_html( + '{}', + benefit.image_asset_url, + benefit.name, + ) + else: + placeholder_img = ( + 'No Image Available' + ) + description += placeholder_img + description += "{drop.name}{requirements}{period}

" + # Add a clear link to the campaign details page if item.details_url: description += format_html('

About this drop

', item.details_url) @@ -127,7 +190,7 @@ class DropCampaignFeed(Feed): def item_guid(self, item: DropCampaign) -> str: """Return a unique identifier for each campaign.""" - return item.id + return item.id + "@ttvdrops.com" def item_author_name(self, item: DropCampaign) -> str: """Return the author name for the campaign, typically the game name."""