Daily Knowledge Bot
A Python application that delivers interesting facts about rotating topics using the Perplexity AI API. Perfect for daily learning, newsletter content, or personal education.π Features
- Daily Topic Rotation: Automatically selects topics based on the day of the month
- AI-Powered Facts: Uses Perplexityβs Sonar API to generate interesting and accurate facts
- Customizable Topics: Easily extend or modify the list of topics
- Persistent Storage: Saves facts to dated text files for future reference
- Robust Error Handling: Gracefully manages API failures and unexpected errors
- Configurable: Uses environment variables for secure API key management
π Requirements
- Python 3.6+
- Required packages:
- requests
- python-dotenv
- (optional) logging
π Installation
- Clone this repository or download the script
- Install the required packages:
- Set up your Perplexity API key:
- Create a
.env
file in the same directory as the script - Add your API key:
PERPLEXITY_API_KEY=your_api_key_here
- Create a
π§ Usage
Running the Bot
Simply execute the script:- Select a topic based on the current day
- Fetch an interesting fact from Perplexity AI
- Save the fact to a dated text file in your current directory
- Display the fact in the console
Customizing Topics
Edit thetopics.txt
file (one topic per line) or modify the topics
list directly in the script.
Example topics:
Automated Scheduling
On Linux/macOS (using cron):
On Windows (using Task Scheduler):
- Open Task Scheduler
- Create a new Basic Task
- Set it to run daily
- Add the action: Start a program
- Program/script:
C:\path\to\python.exe
- Arguments:
C:\path\to\daily_knowledge_bot.py
π Configuration Options
The following environment variables can be set in your.env
file:
PERPLEXITY_API_KEY
(required): Your Perplexity API keyOUTPUT_DIR
(optional): Directory to save fact files (default: current directory)TOPICS_FILE
(optional): Path to your custom topics file
π Output Example
π οΈ Extending the Bot
Some ways to extend this bot:- Add email or SMS delivery capabilities
- Create a web interface to view fact history
- Integrate with social media posting
- Add multimedia content based on the facts
- Implement advanced scheduling with specific topics on specific days
β οΈ Limitations
- API rate limits may apply based on your Perplexity account
- Quality of facts depends on the AI model
- The free version of the Sonar API has a token limit that may truncate longer responses
π License
MIT Licenseπ Acknowledgements
- This project uses the Perplexity AI API (https://docs.perplexity.ai/)
- Inspired by daily knowledge calendars and fact-of-the-day services