diff --git a/rss-generator.py b/rss-generator.py index 5072c12..3a75441 100644 --- a/rss-generator.py +++ b/rss-generator.py @@ -37,8 +37,8 @@ def fetch_apps_data(url): print(f"Error fetching data: {e}") return None -def fetch_app_description(app_id): - """Fetch the description for a specific app from its detail endpoint.""" +def fetch_app_details(app_id): + """Fetch the full app details from the detail endpoint.""" detail_url = f"https://repebblesearch.com/api/v1/apps/{app_id}" try: response = requests.get(detail_url) @@ -47,14 +47,14 @@ def fetch_app_description(app_id): # Try parsing as JSON first try: data = response.json() - return data.get('description', '') + return data except json.JSONDecodeError: # If not JSON, try to extract from response text print(f"Warning: Detail endpoint returned non-JSON for {app_id}") - return "" + return {} except requests.exceptions.RequestException as e: - print(f"Error fetching description for {app_id}: {e}") - return "" + print(f"Error fetching details for {app_id}: {e}") + return {} def format_description(text): """Convert plain text description to formatted HTML with proper line breaks and lists.""" @@ -72,11 +72,11 @@ def format_description(text): stripped = line.strip() # Check if this is a bullet point - if stripped and stripped[0] in ('-', '*', '•'): + if stripped and stripped[0] == '-': if not in_list: formatted_lines.append('
Released: {formatted_date}
') + except (ValueError, AttributeError): + changelog_html.append(f'Released: {published_date}
') + + if release_notes: + formatted_notes = format_description(release_notes) + changelog_html.append(formatted_notes) + else: + changelog_html.append('No release notes provided.
') + + description_sections.append('\n'.join(changelog_html)) - # Fallback to latest release notes if no changelog - if not changelog_html and 'latest_release_notes' in app and app['latest_release_notes']: + # Fallback to latest_release_notes if no changelog + elif app.get('latest_release_notes'): release_notes = str(app['latest_release_notes']).strip() if release_notes: formatted_notes = format_description(release_notes) @@ -235,8 +233,8 @@ def create_rss_feed(apps_data, feed_name, feed_description, output_file): fe.description("No description available") # Add screenshot URLs as enclosures (for readers that support them) - screenshots = app.get("screenshots", []) - if not screenshots and 'screenshot_url' in app and app['screenshot_url']: + screenshots = app_details.get("screenshots", []) if app_details else [] + if not screenshots and app.get('screenshot_url'): screenshots = [{'url': app['screenshot_url']}] for screenshot in screenshots: @@ -247,17 +245,17 @@ def create_rss_feed(apps_data, feed_name, feed_description, output_file): # Set publication date if available pub_date = None - # Try changelog first - changelog = app.get("changelog", []) - if changelog and len(changelog) > 0: - pub_date_str = changelog[0].get("published_date", "") - if pub_date_str: + # Try to get the earliest changelog date + if app_details and 'changelog' in app_details and isinstance(app_details['changelog'], list) and len(app_details['changelog']) > 0: + # Get the last entry (oldest) of the changelog + last_entry = app_details['changelog'][-1] + if isinstance(last_entry, dict) and 'published_date' in last_entry: try: - pub_date = datetime.fromisoformat(pub_date_str.replace('Z', '+00:00')) - except: + pub_date = datetime.fromisoformat(last_entry['published_date'].replace('Z', '+00:00')) + except (ValueError, AttributeError): pass - # Fallback to release_date + # Fallback to release_date from the app list if pub_date is None and 'release_date' in app and app['release_date']: try: pub_date = datetime.fromisoformat(app['release_date'].replace('Z', '+00:00')) @@ -271,7 +269,9 @@ def create_rss_feed(apps_data, feed_name, feed_description, output_file): fe.pubDate(pub_date) # Add author if available - if 'author' in app and app['author']: + if app_details and 'author' in app_details and app_details['author']: + fe.author(name=str(app_details['author'])) + elif 'author' in app and app['author']: fe.author(name=str(app['author'])) # Write the RSS feed to file