this post was submitted on 13 Jul 2023
2 points (100.0% liked)
ShareGPT
1 readers
1 users here now
To share AI output.
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
To rewrite the script following clean code principles, we can break down the script into smaller functions, each with a single responsibility. Here's the updated script:
This updated script breaks down the original script into smaller functions, each with a single responsibility. The
fetch_github_issues
,initialize_lemmy_instance
,discover_community
,extract_issue_info
, andpost_issues_to_lemmy
functions handle different aspects of the task, making the code easier to read and maintain.Citations: [1] https://testdriven.io/blog/clean-code-python/ [2] https://workat.tech/machine-coding/tutorial/introduction-clean-code-software-design-principles-nwu4qqc63e09 [3] https://dev.to/alexomeyer/10-must-know-patterns-for-writing-clean-code-with-python-56bf [4] https://gist.github.com/wojteklu/73c6914cc446146b8b533c0988cf8d29 [5] https://github.com/zedr/clean-code-python [6] https://www.ionos.com/digitalguide/websites/web-development/clean-code-principles-advantages-and-examples/ [7] https://towardsdatascience.com/python-clean-code-6-best-practices-to-make-your-python-functions-more-readable-7ea4c6171d60 [8] https://www.pluralsight.com/blog/software-development/10-steps-to-clean-code [9] https://www.geeksforgeeks.org/best-practices-to-write-clean-python-code/ [10] https://x-team.com/blog/principles-clean-code/ [11] https://jerrynsh.com/how-to-write-clean-code-in-python/ [12] https://betterprogramming.pub/12-conventions-for-writing-clean-code-e16c51e3939a [13] https://youtube.com/watch?v=F14BKKHeAKU [14] https://medium.com/gojekengineering/the-basics-of-writing-clean-code-39ed770b626d [15] https://www.octobot.io/blog/clean-python-code/ [16] https://www.freecodecamp.org/news/how-to-write-clean-code/
Make it keep working and checking for new posts every couple hours. Don't create duplicate posts.
To modify the script to keep checking for new issues every couple of hours and avoid creating duplicate posts, you can use the
schedule
library[1] to run the script periodically and maintain a record of posted issues to prevent duplicates.First, install the
schedule
library:Then, update the script as follows:
This updated script uses the
schedule
library to run themain()
function every 2 hours. It also maintains aposted_issues
set to keep track of the posted issues and prevent duplicates. When posting issues, the script checks if the issue URL is not in theposted_issues
set before posting it to Lemmy and adding it to the set.Citations: [1] https://www.geeksforgeeks.org/python-schedule-library/ [2] https://www.trainingint.com/how-to-find-duplicates-in-a-python-list.html [3] https://schedule.readthedocs.io [4] https://stackoverflow.com/questions/1541797/how-do-i-check-if-there-are-duplicates-in-a-flat-list [5] https://medium.com/@timothymugayi/7-ways-to-execute-scheduled-jobs-with-python-47d481d22b91 [6] https://note.nkmk.me/en/python-list-duplicate-check/ [7] https://plainenglish.io/blog/5-ways-to-schedule-jobs-in-python-99de8a80f28e [8] https://www.educative.io/answers/how-to-find-duplicates-from-a-list-in-python [9] https://youtube.com/watch?v=yDPQfj4bZY8 [10] https://thispointer.com/python-3-ways-to-check-if-there-are-duplicates-in-a-list/ [11] https://youtube.com/watch?v=FCPBG6NqMmQ [12] https://blog.finxter.com/5-best-ways-to-check-a-list-for-duplicates-in-python/ [13] https://docs.python.org/3/library/sched.html [14] https://www.pythonforbeginners.com/basics/check-if-a-list-has-duplicate-elements [15] https://www.airplane.dev/blog/using-python-scheduler-to-schedule-asynchronous-tasks [16] https://datagy.io/python-list-duplicates/ [17] https://www.geeksforgeeks.org/python-program-print-duplicates-list-integers/
posted issues should be saved to memory so that the program remembers them when restarted
To save the posted issues to memory so that the program remembers them when restarted, you can use a file to store the posted issue URLs. You can read the file when the script starts and update it whenever a new issue is posted. Here's the updated script:
This updated script uses the
load_posted_issues
function to read the posted issue URLs from thePOSTED_ISSUES_FILE
when the script starts. Thesave_posted_issue
function is called to save a new posted issue URL to the file. This way, the script will remember the posted issues even when restarted.Citations: [1] https://stackoverflow.com/questions/36622564/how-to-save-a-text-file-received-in-a-post-request-using-python [2] https://stackoverflow.com/questions/46144452/writing-a-set-to-an-output-file-in-python [3] https://discuss.python.org/t/problem-saving-values-to-a-text-file/12350 [4] https://note.nkmk.me/en/python-file-io-open-with/ [5] https://www.geeksforgeeks.org/saving-text-json-and-csv-to-a-file-in-python/ [6] https://www.geeksforgeeks.org/writing-to-file-in-python/ [7] https://docs.djangoproject.com/en/4.2/topics/http/file-uploads/ [8] https://www.geeksforgeeks.org/reading-writing-text-files-python/ [9] https://pynative.com/python-write-list-to-file/ [10] https://stackabuse.com/reading-and-writing-lists-to-a-file-in-python/ [11] https://www.scrapingbee.com/blog/download-image-python/ [12] https://www.freecodecamp.org/news/file-handling-in-python/ [13] https://www.codementor.io/@aviaryan/downloading-files-from-urls-in-python-77q3bs0un [14] https://www.pythonmorsels.com/creating-and-writing-file-python/ [15] https://realpython.com/storing-images-in-python/