Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This is a Python daily task planner that displays a motivational quot… #507

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions daily_planner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

import requests
import json
from datetime import datetime

# Function to fetch a random motivational quote
def fetch_quote():
fallback_quote = "'Stay positive, work hard, make it happen.' - Unknown"
url = "https://zenquotes.io/api/random"

try:
response = requests.get(url, timeout=5)
if response.status_code == 200:
quote_data = response.json()
if len(quote_data) > 0:
quote = quote_data[0]
return f"'{quote['q']}' - {quote['a']}"
else:
return fallback_quote
else:
return fallback_quote
except Exception as e:
print(f"Error fetching quote: {e}")
return fallback_quote

# Function to create a daily task planner
def task_planner():
tasks = []
print("Enter your tasks for the day (type 'done' to finish):")

while True:
task = input("> ")
if task.lower() == 'done':
break
tasks.append(task)

return tasks

# Function to save tasks to a file
def save_tasks(date, tasks):
planner = {"date": date, "tasks": tasks}
with open(f"tasks_{date}.json", 'w') as file:
json.dump(planner, file, indent=4)

def main():
today = datetime.now().strftime("%Y-%m-%d")
print(f"\nToday's Date: {today}")

# Fetch and display a motivational quote
quote = fetch_quote()
print(f"\nDaily Motivation: {quote}\n")

# Collects the tasks from the user
tasks = task_planner()

# Saves the tasks to a file
if tasks:
save_tasks(today, tasks)
print("\nYour tasks have been saved!\n")
else:
print("No tasks to save.\n")

if __name__ == "__main__":
main()