mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-24 04:21:08 +00:00
Merge pull request #340 from heysagnik/patch-1
Task Scheduler for Awesome-Python-Scripts
This commit is contained in:
commit
8aa865cff9
|
@ -153,6 +153,7 @@ So far, the following projects have been integrated to this repo:
|
||||||
|[Youtube video downloader](Youtube_Video_Downloader)|[Christopher He](https://github.com/hecris)|
|
|[Youtube video downloader](Youtube_Video_Downloader)|[Christopher He](https://github.com/hecris)|
|
||||||
|[Zabbix API](zabbix_api)|[msg4sunny](https://github.com/msg4sunny)|
|
|[Zabbix API](zabbix_api)|[msg4sunny](https://github.com/msg4sunny)|
|
||||||
|[Zip password cracker](zip_password_cracker)|[umar abdullahi](https://github.com/umarbrowser)|
|
|[Zip password cracker](zip_password_cracker)|[umar abdullahi](https://github.com/umarbrowser)|
|
||||||
|
|[Task Scheduler](Task-Scheduler)|[heysagnik](https://github.com/heysagnik)|
|
||||||
|
|
||||||
## How to use:
|
## How to use:
|
||||||
- Clone/Download the directory and navigate to each folder. Or...
|
- Clone/Download the directory and navigate to each folder. Or...
|
||||||
|
|
85
Task-Scheduler/Readme.md
Normal file
85
Task-Scheduler/Readme.md
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
# Task Scheduler
|
||||||
|
|
||||||
|
This Python script, `task_scheduler.py`, is a simple command-line task management application that allows users to add, view, and delete tasks with due dates. The application stores task data in a JSON file.
|
||||||
|
|
||||||
|
## How to Use
|
||||||
|
|
||||||
|
1. **Installation**:
|
||||||
|
|
||||||
|
- Make sure you have Python installed on your system.
|
||||||
|
|
||||||
|
2. **Run the Application**:
|
||||||
|
|
||||||
|
- Open a terminal or command prompt.
|
||||||
|
- Navigate to the directory where `task_scheduler.py` is located.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ cd /path/to/directory
|
||||||
|
```
|
||||||
|
|
||||||
|
- Run the script:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ python task_scheduler.py
|
||||||
|
```
|
||||||
|
|
||||||
|
3. **Menu Options**:
|
||||||
|
|
||||||
|
- The application provides the following menu options:
|
||||||
|
|
||||||
|
- **Add Task**: Allows you to add a new task with a name and due date (in YYYY-MM-DD format).
|
||||||
|
|
||||||
|
- **View Tasks**: Displays a list of tasks with their names and due dates.
|
||||||
|
|
||||||
|
- **Delete Task**: Lets you delete a task by specifying its number in the list.
|
||||||
|
|
||||||
|
- **Quit**: Exits the application.
|
||||||
|
|
||||||
|
4. **Data Storage**:
|
||||||
|
|
||||||
|
- The tasks are stored in a JSON file named `tasks.json` in the same directory as the script.
|
||||||
|
|
||||||
|
5. **Error Handling**:
|
||||||
|
|
||||||
|
- The application handles various errors, such as invalid date format or task numbers.
|
||||||
|
|
||||||
|
## Example Usage
|
||||||
|
|
||||||
|
1. **Add Task**:
|
||||||
|
|
||||||
|
- Choose option 1.
|
||||||
|
- Enter a task name.
|
||||||
|
- Enter the due date in YYYY-MM-DD format.
|
||||||
|
|
||||||
|
2. **View Tasks**:
|
||||||
|
|
||||||
|
- Choose option 2 to see a list of added tasks with their due dates.
|
||||||
|
|
||||||
|
3. **Delete Task**:
|
||||||
|
|
||||||
|
- Choose option 3.
|
||||||
|
- Enter the number of the task you want to delete.
|
||||||
|
|
||||||
|
4. **Quit**:
|
||||||
|
|
||||||
|
- Choose option 4 to exit the application.
|
||||||
|
|
||||||
|
## Data Persistence
|
||||||
|
|
||||||
|
The application loads tasks from the `tasks.json` file when it starts and saves tasks back to the file after any additions or deletions. This ensures that your tasks are retained even when the application is closed and reopened.
|
||||||
|
|
||||||
|
## Error Handling
|
||||||
|
|
||||||
|
The application checks for invalid date formats and incorrect task numbers, providing appropriate error messages to guide the user.
|
||||||
|
|
||||||
|
## Important Notes
|
||||||
|
|
||||||
|
- Please ensure that you have Python installed on your system.
|
||||||
|
- Make sure to provide dates in the specified format (YYYY-MM-DD).
|
||||||
|
- Be cautious when deleting tasks, as this action is irreversible.
|
||||||
|
|
||||||
|
## Author
|
||||||
|
|
||||||
|
This Python Task Scheduler was created by Sagnik Sahoo.
|
||||||
|
|
||||||
|
Feel free to customize and extend this application to suit your needs. Enjoy managing your tasks!
|
1
Task-Scheduler/requirements.txt
Normal file
1
Task-Scheduler/requirements.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pytz==2021.3
|
74
Task-Scheduler/scheduler.py
Normal file
74
Task-Scheduler/scheduler.py
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
# Define the data file to store tasks
|
||||||
|
TASKS_FILE = "tasks.json"
|
||||||
|
|
||||||
|
# Load tasks from the data file (if it exists)
|
||||||
|
tasks = []
|
||||||
|
|
||||||
|
if os.path.exists(TASKS_FILE):
|
||||||
|
with open(TASKS_FILE, "r") as file:
|
||||||
|
tasks = json.load(file)
|
||||||
|
|
||||||
|
def save_tasks():
|
||||||
|
# Save tasks to the data file
|
||||||
|
with open(TASKS_FILE, "w") as file:
|
||||||
|
json.dump(tasks, file)
|
||||||
|
|
||||||
|
def add_task():
|
||||||
|
task_name = input("Enter the task name: ")
|
||||||
|
due_date = input("Enter the due date (YYYY-MM-DD): ")
|
||||||
|
|
||||||
|
try:
|
||||||
|
due_date = datetime.datetime.strptime(due_date, "%Y-%m-%d").date()
|
||||||
|
except ValueError:
|
||||||
|
print("Invalid date format. Please use YYYY-MM-DD.")
|
||||||
|
return
|
||||||
|
|
||||||
|
tasks.append({"name": task_name, "due_date": due_date})
|
||||||
|
save_tasks()
|
||||||
|
print(f"Task '{task_name}' added successfully!")
|
||||||
|
|
||||||
|
def view_tasks():
|
||||||
|
print("Tasks:")
|
||||||
|
for idx, task in enumerate(tasks, start=1):
|
||||||
|
print(f"{idx}. {task['name']} (Due: {task['due_date']})")
|
||||||
|
|
||||||
|
def delete_task():
|
||||||
|
view_tasks()
|
||||||
|
task_index = input("Enter the task number to delete: ")
|
||||||
|
|
||||||
|
try:
|
||||||
|
task_index = int(task_index)
|
||||||
|
if 1 <= task_index <= len(tasks):
|
||||||
|
deleted_task = tasks.pop(task_index - 1)
|
||||||
|
save_tasks()
|
||||||
|
print(f"Task '{deleted_task['name']}' deleted successfully!")
|
||||||
|
else:
|
||||||
|
print("Invalid task number.")
|
||||||
|
except ValueError:
|
||||||
|
print("Invalid input. Please enter a valid task number.")
|
||||||
|
|
||||||
|
while True:
|
||||||
|
print("\nTask Scheduler Menu:")
|
||||||
|
print("1. Add Task")
|
||||||
|
print("2. View Tasks")
|
||||||
|
print("3. Delete Task")
|
||||||
|
print("4. Quit")
|
||||||
|
|
||||||
|
choice = input("Enter your choice: ")
|
||||||
|
|
||||||
|
if choice == "1":
|
||||||
|
add_task()
|
||||||
|
elif choice == "2":
|
||||||
|
view_tasks()
|
||||||
|
elif choice == "3":
|
||||||
|
delete_task()
|
||||||
|
elif choice == "4":
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("Invalid choice. Please choose a valid option.")
|
||||||
|
|
||||||
|
print("Goodbye!")
|
Loading…
Reference in New Issue
Block a user