A Python package for managing and interacting with a JSON-based riddle library.
Project description
Riddle Handler
Overview
Riddle Handler is a lighthearted Python package designed to bring a bit of joy and levity to developers' lives. It provides an interactive experience where users can generate riddles of varying difficulties and topics, check answers, submit new riddles, and receive hints. The package is built following rigorous software engineering practices, ensuring quality and reliability.
PyPI Link
Installation
Install the package via pip:
pip install riddle-handler==1.0.3
Usage
Importing the Package
import riddle_handler
Functions and Examples
Function 1: generate_riddle(difficulty: int) -> str
Generates a random riddle based on the specified difficulty level.
-
Parameters:
difficulty(int): The difficulty level of the riddle (1 to 4).
-
Returns:
- A string containing the riddle's question.
-
Example:
import riddle_handler # Generate a riddle of difficulty level 2 riddle = riddle_handler.generate_riddle(2) print(f"Here's your riddle: {riddle}")
Function 2: check_answer(riddle_id: int, answer: str) -> str
Checks if the provided answer to the riddle is correct.
-
Parameters:
riddle_id(int): The ID of the riddle.answer(str): The user's answer to the riddle.
-
Returns:
- A string indicating whether the answer is correct or incorrect.
-
Example:
import riddle_handler # Check the answer to a riddle with ID 5 result = riddle_handler.check_answer(5, 'shadow') print(result) # Outputs: "Correct answer!" or "Incorrect answer. Try again!"
Function 3: submit_riddle(riddle: dict) -> str
Allows users to submit their own riddles to the library.
-
Parameters:
-
riddle(dict): A dictionary containing the riddle's details.question(str): The riddle's question.answer(list): A list of acceptable answers.hint(str): A hint for the riddle.difficulty(int): Difficulty level (1 to 4).topic(str): The topic of the riddle.
-
-
Returns:
- A string indicating success or an error message.
-
Example:
import riddle_handler # Define your custom riddle my_riddle = { "question": "I can move, yet I stay in one place; People use me to send messages, but I'm nowhere to be seen; Anytime, anywhere, you can call for me, and I'll always be there. What am I?", "answer": ["sound"], "hint": "You can hear me but cannot see me.", "difficulty": 3, "topic": "Communication" } # Submit the riddle response = riddle_handler.submit_riddle(my_riddle) print(response) # Outputs: "Riddle submitted successfully!"
Function 4: provide_hint(riddle_id: int) -> str
Provides a hint for the specified riddle.
-
Parameters:
riddle_id(int): The ID of the riddle.
-
Returns:
- A string containing the hint or an error message.
-
Example:
import riddle_handler # Get a hint for a riddle hint = riddle_handler.provide_hint(5) print(hint) # Outputs the hint for the riddle
For more examples, check out this example program.
Contributing
Setting Up the Development Environment
-
Clone the repository:
git clone https://github.com/software-students-fall2024/3-python-package-codecrafter
-
Install
pipenv:
If you haven’t installed pipenv yet, use the following command:
pip install pipenv
- Set Up the Virtual Environment:
To create a virtual environment and install dependencies using the Pipfile, run:
pipenv install
This command will read the Pipfile and create a virtual environment with all the specified dependencies.
If you only want to create the environment without installing dependencies, you can use:
pipenv install --ignore-pipfile
- Activate the Virtual Environment:
To activate the virtual environment, use:
pipenv shell
This command works on both Mac and Windows, as pipenv will automatically locate and activate the correct environment.
- Install Additional Dependencies(If Needed):
If you need to add more dependencies later, you can use the following commands:
-
For production dependencies:
pipenv install <package-name>
-
For development dependencies (e.g., testing or debugging tools):
pipenv install --dev <package-name>
- Exit the Virtual Environment:
To exit the virtual environment, simply type:
exit
Or press Ctrl + D.
- Remove the Virtual Environmen:
If you need to delete the virtual environment, use:
pipenv --rm
This will remove the virtual environment associated with the Pipfile.
Building and Testing
-
Run Tests:
We use
pytestfor testing.pytest
-
Build Package:
Use
buildto create the package artifacts.For Mac:
python3 -m build
For Windows:
python -m build
-
Upload to PyPI (For maintainers):
Use
twineto upload the package.twine upload dist/*
Note that API key should only be acquired by contacting administrators
Git Workflow
All code changes must be done in feature branches and not directly in the main branch.
To merge code from a feature branch into main:
- Create a pull request from the feature branch to
main. - Request a code review from a team member.
- Review and approve the code after ensuring all tests pass.
- Merge the pull request into
main. - Delete the feature branch.
Note: Regularly merge feature branches to avoid merge conflicts.
Contributors
Instructions for Running the Project
For Developers
-
Ensure Python 3.11 or higher is installed on your system.
-
Clone the repository and set up the environment as described in the Contributing section.
-
Run the example program:
For Mac:
python3 example_program.py
For Windows:
python example_program.py
For Users
-
Install the package via pip:
install riddle-handler==1.0.3
-
Use the package in your Python scripts as shown in the Usage examples.
Configuration and Setup
Environment Variables
No environment variables are required for basic usage.
Importing Starter Data
The package uses a riddleLibrary.json file to store riddles. Ensure that this file is in the root directory of your project. You can use our library from this link or you can build your own by creating a riddleLibrary.json file.
Update Log
v1.0.3 Bug Fix: Resolved an issue where the package has no attribute.
v1.0.2 Bug Fix: Resolved an issue where the package appeared empty after installation. Documentation: Updated README with clearer instructions and added installation and usage details specific to Windows. Compatibility: Added a method for Windows users to ensure compatibility.
v1.0.1 Updated Package Structure: Reorganized the package structure to follow best practices for module organization, enhancing maintainability and usability. Bug Fixes: Resolved several issues related to imports and file path references, improving the stability and reliability of the package.
v1.0.0 Initial Release: Launched the riddle_handler package, offering core functionalities for managing and interacting with a JSON-based riddle library. This includes generating riddles, checking answers, providing hints, and submitting new riddles.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file riddle_handler-1.0.3.tar.gz.
File metadata
- Download URL: riddle_handler-1.0.3.tar.gz
- Upload date:
- Size: 20.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e23be8d397bb3995a8d264cda00199a0ffe3c30a5bbc23847f7fe87eadd96b2
|
|
| MD5 |
03ebe31bf28ca8ab25d47875e4a3c2a2
|
|
| BLAKE2b-256 |
04061f2500b71c7a9025663f10536cc0be433f0e6261551388a690d7d837b714
|
File details
Details for the file riddle_handler-1.0.3-py3-none-any.whl.
File metadata
- Download URL: riddle_handler-1.0.3-py3-none-any.whl
- Upload date:
- Size: 19.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be016f0e1729d0ffcb120940c086372a91b00e60d794f57c0ac410903dce7dd4
|
|
| MD5 |
ecbf8e7d1bb44ca1bf358de6908aa9eb
|
|
| BLAKE2b-256 |
055abd98f59f244931f4ad346f627f342d8d56df55d397ab9ea82da4c67af630
|