At the end I decided to choose my own strategy and develop 2 essential Python Scripts for my Automation Project. Especally some articles written on "BuiltIn" helped me to figure out how to manage ordered and unordered lists in Python :
The generate_facts_about_animals.py script retrieves facts from the chosen website.
- requests: Used for making HTTP requests to the website to fetch content.
- BeautifulSoup: A library for web scraping, employed to parse the HTML content and extract relevant information.
- Establishes a connection to the specified website and retrieves the HTML content.
- Utilizes BeautifulSoup to locate and extract animal facts from the HTML structure.
- Randomly selects one fact from the obtained list and returns it.
- Calls the generate_random_animal_fact() function.
- Prints the randomly selected animal fact to the console.
Advantages:
-
The script fetches animal facts from a website, ensuring that your blog always has fresh and engaging content. This enhances reader interest and provides a continuously evolving experience.
-
The script automates the process of retrieving facts, saving you time and effort that would be required to manually search for and update facts in each blog post.
-
The use of random.choice() ensures that the facts inserted into your posts are diverse, preventing repetitive or monotonous content.
-
The script checks for the success of the HTTP request and gracefully handles cases where the retrieval of facts fails.
Disadvantages:
-
The script relies on the external website for content. If the website structure changes or becomes unavailable, the script might fail.
-
Since the facts are fetched from an external source, you have limited control over the specific facts that are retrieved. This might result in occasional irrelevant or less contextually fitting content.
Another my .py skript file replace_placeholders.py seamlessly replaces designated placeholders in my blog posts with dynamically generated facts.
- requests: Similar to the other script, used for making HTTP requests to fetch content.
- generate_random_animal_fact: Importing the function from your first script for obtaining random animal facts.
- Accepts a list of file names (your blog posts in Markdown format).
- For each file, reads its content line by line. Searches for a specific placeholder (**"Did you know? ") and replaces it with the dynamically generated animal fact.
- Writes the updated content back to the file.
- Calls replace_fact_placeholder() with a list of your blog posts (['Second_Post.md', 'Third_Post.md', 'Fourth_Post.md']).
- Prints the updated content to the console.
Additional Notes: This script is designed to be run after creating your blog posts, ensuring that the placeholders are correctly positioned in your Markdown files.
Advantages:
- The script seamlessly integrates dynamically generated facts into your blog posts, maintaining a cohesive flow of content.
- By using placeholders like **"Did you know? ", you can easily customize the placement of the facts in your posts, ensuring they fit naturally within the context.
- The script ensures a consistent format for displaying facts across multiple blog posts, contributing to a unified and professional appearance.
Disadvantages:
-
The script directly modifies the content of existing files. If not used carefully, it could overwrite changes made manually to the blog posts.
-
The script assumes a specific placeholder structure. If you want to change the format or location of facts in your posts, you may need to modify the script accordingly.
-
The script prints information to the console, which might be unnecessary or confusing for someone not familiar with the script's inner workings.
As a result, we can see the provided entertaining fact in each Post: