An exercise to create a Python package, build it, test it, distribute it, and use it. See instructions for details.
Fortunes
is a delightful Python package that brings a touch of randomness and inspiration into your projects. Whether you're looking for a daily dose of wisdom, a lucky number, or the ability to send personalized fortunes via email, Fortunes has you covered.
- Random Fortune Generation: Retrieve one or multiple unique fortunes along with lucky numbers.
- Email Integration: Send personalized fortunes to any email address effortlessly.
- Customizable Quotes: Get your own collection of fortunes and quotes.
Install the latest version of Fortunes from PyPI using pip
:
pip install fortune.package
Importing Fortunes into Your Project
To start using Fortunes in your Python code, simply import the desired functions:
from fortunes.random_fortune import get_fortune_cookie
from fortunes.get_quotes_by_author import get_quotes_by_author
from fortunes.send_email import send_fortune_email
from fortunes.getMultipleFortunes import getMultipleFortunes
# Example Usage:
fortune = get_fortune_cookie()
print(fortune)
quotes = get_quotes_by_author(quotes_dict)
print(quotes)
send_fortune_email("[email protected]", fortune)
multiple_fortunes = getMultipleFortunes(3)
for f in multiple_fortunes:
print(f)
Description:
Generates a single random fortune along with a lucky number.
Usage:
from fortunes.random_fortune import get_fortune_cookie
fortune = get_fortune_cookie()
print(fortune)
Output Example:
๐ฎ Your Fortune: Good luck is on the way!
๐ Your Lucky Number: 42
Description:
Retrieves quotes from a specified author. Users can choose to get one or multiple quotes.
Usage:
from fortunes.get_quotes_by_author import get_quotes_by_author
quotes_dict = {
"Albert Claude": [
"Once Ptolemy and Plato, yesterday Newton, today Einstein, and tomorrow new faiths, new beliefs, and new dimensions.",
"When I went to the University, the medical school was the only place where one could hope to find the means to study life, its nature, its origins, and its ills.",
"Looking back 25 years later, what I may say is that the facts have been far better than the dreams. In the long course of cell life on this earth it remained, for our age for our generation, to receive the full ownership of our inheritance.",
],
"Mikhail Bakunin": [
"The urge to destroy is also a creative urge.",
"If God really existed, it would be necessary to abolish Him.",
"People go to church for the same reasons they go to a tavern: to stupefy themselves, to forget their misery, to imagine themselves, for a few minutes anyway, free and happy."
]
}
quotes = get_quotes_by_author(quotes_dict)
print(quotes)
Output Example:
๐ฎ Your Fortune: The urge to destroy is also a creative urge.
๐ Your Lucky Number: 17
~ Mikhail Bakunin
๐ฎ Your Fortune: If God really existed, it would be necessary to abolish Him.
๐ Your Lucky Number: 23
~ Mikhail Bakunin
Description:
Sends a fortune to the specified email address.
Usage:
from fortunes.send_email import send_fortune_email
recipient = "[email protected]"
fortune = "๐ฎ Your Fortune: Happiness is around the corner.\n๐ Your Lucky Number: 12"
send_fortune_email(recipient, fortune)
Note:
Ensure that you have the necessary SMTP configurations and environment variables set up before using this function.
Description:
Generates multiple unique fortunes based on the number specified.
Usage:
from fortunes.getMultipleFortunes import getMultipleFortunes
fortunes = getMultipleFortunes(3)
for f in fortunes:
print(f)
Output Example:
๐ฎ Your Fortune: Fortune 1
๐ Your Lucky Number: 42
๐ฎ Your Fortune: Fortune 2
๐ Your Lucky Number: 88
๐ฎ Your Fortune: Fortune 3
๐ Your Lucky Number: 7
For comprehensive examples of how to use Fortunes in real-world scenarios, refer to our examples directory on GitHub.
We welcome contributions from the community! Here's how you can get started:
-
Clone the Repository:
git clone https://github.com/yourusername/fortunes.git cd fortunes
-
Create a Virtual Environment:
python3 -m venv venv source venv/bin/activate # On Windows, use venv\Scripts\activate
-
Install Dependencies:
pip install --upgrade pip pip install -e .[dev]
This installs the package in editable mode along with development dependencies.
-
Install requirements:
pip install -r requirements.txt
-
Run Tests:
Ensure that all tests pass before making changes.
pytest
-
Create a New Branch:
git checkout -b feature/your-feature-name
-
Implement Your Changes:
Make your desired changes to the codebase.
-
Run Tests:
Ensure that your changes do not break existing functionality.
pytest
-
Commit and Push:
git add . git commit -m "Add feature: your-feature-description" git push origin feature/your-feature-name
-
Open a Pull Request:
Navigate to the repository on GitHub and open a pull request detailing your changes.
- Follow PEP 8: Ensure your code adheres to Python's style guidelines.
- Write Tests: Add tests for new features or bug fixes.
- Document Your Code: Update documentation to reflect changes.
- Python 3.10+
- pip
- Virtual Environment Tool (optional)
-
Clone the Repository:
git clone https://github.com/yourusername/fortunes.git cd fortunes
-
Set Up Virtual Environment:
python3 -m venv venv source venv/bin/activate # On Windows, use venv\Scripts\activate
-
Install Dependencies:
pip install --upgrade pip pip install -e .[dev]
-
Generating a Fortune:
from fortunes.random_fortune import get_fortune_cookie fortune = get_fortune_cookie() print(fortune)
-
Sending a Fortune via Email:
from fortunes.send_email import send_fortune_email recipient = "[email protected]" fortune = "๐ฎ Your Fortune: Happiness is around the corner.\n๐ Your Lucky Number: 12" send_fortune_email(recipient, fortune)
-
Retrieving Quotes by Author:
from fortunes.get_quotes_by_author import get_quotes_by_author quotes_dict = { "Albert Claude": [ "Once Ptolemy and Plato, yesterday Newton, today Einstein, and tomorrow new faiths, new beliefs, and new dimensions.", # Add more quotes... ], # Add more authors... } quotes = get_quotes_by_author(quotes_dict) for q in quotes: print(q)
Fortunes is designed to work seamlessly across all major platforms, including:
- Windows
- macOS
- Linux
Ensure that Python 3.10 or higher is installed on your system.
Important:
Configuration files containing sensitive information, such as .env
, are not included in the version control repository for security reasons.
-
Create the File:
In the root directory of your project, create a file named
.env
. -
Add the Following Content:
SMTP_SERVER=smtp.gmail.com SMTP_PORT=587 SMTP_USERNAME=[email protected] SMTP_PASSWORD=your_email_password
Explanation of Variables:
SMTP_SERVER
: The address of your SMTP server.SMTP_PORT
: The port number for your SMTP server (commonly587
for TLS).SMTP_USERNAME
: Your SMTP server username (usually your email address).SMTP_PASSWORD
: Your SMTP server password.
-
Secure Your Credentials:
- Do Not Share: Never share your
.env
file or its contents publicly. - Add to
.gitignore
: Ensure that your.env
file is listed in.gitignore
to prevent it from being tracked by Git.
# .gitignore __pycache__/ *.pyc build/ dist/ *.egg-info/ .env
- Do Not Share: Never share your