TzorAL / daily-random-xkcd

This repository automates the process of generating a daily random xkcd comic RSS feed. Using GitHub Actions, a new random xkcd comic is selected and added to the feed every day. The RSS feed is hosted on GitHub Pages and can be integrated with services like RSS.app to receive daily emails featuring the comic.
https://tzoral.github.io/daily-random-xkcd/
MIT License
2 stars 1 forks source link

Some Errors in Code #2

Open snootysteppes opened 1 month ago

snootysteppes commented 1 month ago

Here are a couple of potential issues or bugs in your script:

  1. Date Formatting in RSS: In the pubDate field of the RSS feed, you're using the year, month, and day attributes from the comic data, which may not always be formatted correctly for RSS. The month and day values need to be zero-padded. Consider formatting them like this:

    pubDate = f"{comic_data['year']}-{int(comic_data['month']):02d}-{int(comic_data['day']):02d}"

    Alternatively, you can use the datetime library to format the date properly.

  2. Seen Comics Reset Logic: The clear_seen_comics_if_complete function clears the seen comics list if the count of seen comics reaches or exceeds the latest comic number. This can lead to unintended resets if the user frequently requests comics. You might want to adjust this logic to only reset if the user explicitly requests it, or implement a threshold for the maximum number of seen comics before a reset occurs.

  3. File Paths: The RSS file is saved to docs/rss/xkcd_feed.xml, which may not exist on all systems. You might want to check if the directory exists before trying to save the file, or create it if it doesn't:

    os.makedirs('docs/rss', exist_ok=True)
  4. Infinite Loop on Comic Fetching: If all comics have been seen, the fetch_random_comic function may enter an infinite loop since it continues to fetch comics until it finds one that hasn't been seen. If the seen comics list is complete and no reset occurs, it could get stuck. You could add a safeguard to break the loop after a certain number of attempts.

  5. Network Error Handling: In fetch_random_comic, if there is a network error while fetching a random comic, it will retry indefinitely. You might want to add a limit on retries or a delay before retrying.

Hope this is ok sir.

snootysteppes commented 1 month ago

I can also write a prototype for this to implement boss.

TzorAL commented 1 month ago

I can also write a prototype for this to implement boss.

TL:DR check what's currently in my .py, write a prototype and I'll check it as soon as I can

  1. Okay, we can modify this
  2. The purpose of this comic is to automate the processs and get a new comic each day/hour/any through github actions. Also there is already a threshold, since once the user has seen once all comics, the json is going to reset
  3. Okay, nice addition. However, any who is going to fork the repo, will also have the entire filesystem of the repo
  4. I think I've added a functionality that clear the json once it reaches the total number of available XKCDs
  5. I think you've added a limit in the request function on your fork and I've added it in mine. Thank you for the suggestion😊
snootysteppes commented 1 month ago

here is your prototype: https://github.com/TzorAL/daily-random-xkcd/pull/3 thank you sir