OS Mini Project

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 20

BHARATI VIDYAPEETH (DEEMED TO BE UNIVERSITY)

COLLEGE OF ENGINEERING
DEPARTMENT OF ENGINEERING & TECHNOLOGY
OFFCAMPUS, KHARGHAR, NAVI MUMBAI, 410210

OS Mini Project
TASK SCHEDULAR
Presented By
ROLL NO NAME PRN No.

11 KAMRAN KHAN 2143110133


26 MOHIT SHARMA 2143110156
39 ANKUSH DUBEY 2143110170
48 ARIB QURISHI 2243110149

Signature of Internal Examiner


BHARATI VIDYAPEETH (DEEMED TO BE UNIVERSITY)
COLLEGE OF ENGINEERING
DEPARTMENT OF ENGINEERING & TECHNOLOGY
OFFCAMPUS, KHARGHAR, NAVI MUMBAI, 410210

This is to certify that the project entitled, “Task-Schedular”, which is being submitted here with for
the award of B.Tech, is the result of work completed by “Kamran Khan” under my supervision and
guidance within the four walls of the institute and same has not been submitted elsewhere for the
Award of any degree

Signature of Internal Examiner

1|Page
BHARATI VIDYAPEETH (DEEMED TO BE UNIVERSITY)
COLLEGE OF ENGINEERING
DEPARTMENT OF ENGINEERING & TECHNOLOGY
OFFCAMPUS, KHARGHAR, NAVI MUMBAI, 410210

This is to certify that the project entitled, “Task-Schedular”, which is being submitted here with for
the award of B.Tech, is the result of work completed by “Mohit Sharma” under my supervision and
guidance within the four walls of the institute and same has not been submitted elsewhere for the
Award of any degree

Signature of Internal Examiner

2|Page
BHARATI VIDYAPEETH (DEEMED TO BE UNIVERSITY)
COLLEGE OF ENGINEERING
DEPARTMENT OF ENGINEERING & TECHNOLOGY
OFFCAMPUS, KHARGHAR, NAVI MUMBAI, 410210

This is to certify that the project entitled, “Task-Schedular”, which is being submitted here with for
the award of B.Tech, is the result of work completed by “Ankush Dubey” under my supervision and
guidance within the four walls of the institute and same has not been submitted elsewhere for the
Award of any degree

Signature of Internal Examiner

3|Page
BHARATI VIDYAPEETH (DEEMED TO BE UNIVERSITY)
COLLEGE OF ENGINEERING
DEPARTMENT OF ENGINEERING & TECHNOLOGY
OFFCAMPUS, KHARGHAR, NAVI MUMBAI, 410210

This is to certify that the project entitled, “Task-Schedular”, which is being submitted here with for
the award of B.Tech, is the result of work completed by “Arib Qureshi” under my supervision and
guidance within the four walls of the institute and same has not been submitted elsewhere for the
Award of any degree

Signature of Internal Examiner

4|Page
Abstract
The task-scheduler project is a Python-based application designed to automate the
execution of various tasks based on a predefined schedule. It provides a flexible and
customizable solution for managing and automating routine activities such as
opening applications, accessing URLs, and running system commands. The project
utilizes the schedule library to define and execute tasks at specific times or dates.
The task-scheduler project consists of a main script that reads task configurations
from a JSON file. Each task in the configuration includes a task name, an action to be
performed (e.g., opening an application, accessing a URL, or running a command),
associated arguments, and a schedule specification. The schedule can be defined as
either daily or on a specific date.
The project leverages the logging module to record important events and errors to a
log file for future reference. This enables users to track task execution, identify
issues, and ensure smooth operation.
Upon execution, the task-scheduler loads the task configurations, schedules each
task according to its specified schedule type and time, and executes the associated
action when the scheduled time is reached. The application runs continuously,
ensuring that tasks are executed as per the defined schedule.
The task-scheduler project provides a convenient and efficient way to automate
repetitive tasks, improve productivity, and streamline workflows. It can be easily
customized and expanded to accommodate additional actions or scheduling options
based on specific requirements.

5|Page
Table of Contents
Introduction 7
Software and Hardware Requirements 9
System Design 10
Implementation 12
Results 16
Future Scope 17
Conclusions 19

6|Page
Introduction
The task-scheduler project is a Python-based automation tool designed to simplify
and streamline the execution of routine tasks. In today's fast-paced world, individuals
and organizations often find themselves performing repetitive activities, such as
opening applications, accessing specific URLs, or running system commands, on a
regular basis. Manually performing these tasks can be time-consuming and error-
prone. The task-scheduler project aims to address this challenge by providing an
efficient and customizable solution for automating such tasks based on predefined
schedules.
The project leverages the power of Python programming language and various
libraries to achieve task automation. Key libraries used in the project include json, os,
webbrowser, schedule, subprocess, time, and logging. These libraries enable the
project to interact with the system, schedule tasks, execute actions, handle errors,
and maintain a log of events.
The task-scheduler project operates based on a task configuration file in JSON
format. Each task in the configuration file includes essential details such as the task
name, the action to be performed (such as opening an application, accessing a URL,
or running a command), associated arguments, and the schedule for task execution.
The schedule can be defined as a daily occurrence or on a specific date and time.
To ensure proper execution and tracking of tasks, the project utilizes the logging
module to record events and errors in a dedicated log file. This logging functionality
enables users to monitor task execution, diagnose issues, and maintain an audit trail.
Upon execution, the task-scheduler project loads the task configurations, schedules
each task according to its defined schedule type and time, and triggers the associated
action when the scheduled time is reached. The project runs continuously,
periodically checking for pending tasks and executing them as per the defined
schedule.
The task-scheduler project provides a versatile and user-friendly solution for
automating repetitive tasks, improving productivity, and reducing manual effort. It
can be easily adapted and extended to accommodate additional actions or
scheduling options based on specific requirements.
In the subsequent sections of this project report, we will delve into the project's
implementation details, including the code structure, key functionalities, and the
7|Page
overall workflow. We will also discuss potential use cases, limitations, and future
enhancements for the task-scheduler project.

8|Page
Hardware and Software requirements
Hardware Requirements:
1. Computer or server capable of running Python 3.x.
2. Adequate memory (RAM) to handle the operating system, Python, and
scheduled tasks simultaneously.
3. Stable internet connection (if tasks involve accessing URLs or web-based
resources).
Software Requirements:
1. Operating System: Compatible with Windows, macOS, or Linux.
2. Python: The project requires Python 3.x to be installed on the system. It is
recommended to use the latest stable version of Python.
3. Python Libraries: The project relies on several Python libraries, including json,
os, webbrowser, schedule, subprocess, time, and logging. Ensure that these
libraries are installed and up to date.
4. Integrated Development Environment (IDE): While not mandatory, having an
IDE such as PyCharm, Visual Studio Code, or IDLE can greatly facilitate code
editing, debugging, and project management.
5. Text Editor: A text editor is necessary to create and modify the task
configuration file in JSON format. Notepad++, Sublime Text, or any other
preferred text editor can be used.
6. Web Browser: Depending on the tasks involved, a web browser may be
required to open specific URLs or web-based resources.
It is important to ensure that the hardware and software meet the minimum
requirements to run the task-scheduler project smoothly. Additionally, regular
updates of Python and the required libraries are recommended to benefit from bug
fixes, security patches, and new features.
Note: The specific hardware and software requirements may vary depending on the
complexity of the tasks being scheduled and executed.

9|Page
System Design
1. Task Configuration:
 The task-scheduler project relies on a task configuration file in JSON
format. This file contains a collection of tasks, each defined with the
following information:
 Task name: A descriptive name for the task.
 Action: The type of action to be performed (e.g., opening an
application, accessing a URL, or running a command).
 Arguments: Any specific arguments required for the action.
 Schedule: The schedule for task execution, including the type
(daily or date) and the time/date of execution.
2. Libraries and Modules:
 The project utilizes various Python libraries and modules to accomplish
its functionality:
 json: For parsing and loading the task configuration file.
 os: To execute system commands.
 webbrowser: To open URLs in a web browser.
 schedule: To schedule and manage task execution based on
specified time or date.
 subprocess: To open applications or execute commands.
 time: To introduce delays and manage the scheduler's sleep
intervals.
 logging: To record events and errors in a log file.
3. Task Execution Workflow:
 Upon execution, the main script of the task-scheduler project follows
these steps:
 Loads the task configuration file in JSON format.
 Iterates over each task defined in the configuration.
10 | P a g e
 Retrieves the task name, action, arguments, and schedule details.
 Based on the schedule type (daily or date), schedules the task
using the schedule library.
 When the scheduled time is reached, the associated action
function is executed, passing the specified arguments.
 If a target date is specified for a date-based schedule, the task is
only executed on that specific date.
 The execution of each task is logged using the logging module.
4. Logging and Error Handling:
 The task-scheduler project incorporates logging functionality to maintain
a log of events and errors.
 The logging module is configured to record events at a specified level
(e.g., INFO) and save them in a log file.
 Information such as task execution, successful actions, or encountered
errors is logged for future reference.
 In case of any exceptions or errors during task execution, the logging
module captures and logs the details.
5. Continuous Task Execution:
 The project employs an infinite loop to ensure continuous task
execution.
 The loop periodically checks for pending tasks and executes them as per
the defined schedule.
 The scheduler's sleep interval (e.g., 1 second) allows the script to check
for pending tasks without consuming excessive resources.
The system design of the task-scheduler project focuses on flexibility, scalability, and
automation. It enables users to define a set of tasks with specific actions and
schedules, automating routine activities and enhancing productivity. The logging
functionality aids in monitoring task execution and diagnosing any encountered
issues.

11 | P a g e
Implementation
1. Task Configuration File:
 Create a task configuration file named 'tasks.json' in the same directory
as the main script.
 Define tasks in JSON format, specifying the task name, action,
arguments, and schedule details for each task.
 Example task configuration:
1. [
2. {
3. "task_name": "Open Notepad",
4. "Action": "openApp",
5. "args": "notepad.exe",
6. "schedule": {
7. "type": "daily",
8. "time": "23:47"
9. }
10. },
11. {
12. "task_name": "Open YouTube",
13. "Action": "openUrl",
14. "args": "https://www.youtube.com/",
15. "schedule": {
16. "type": "date",
17. "date": "2023-04-18",
18. "time": "15:06"
19. }
20. },
21. {
22. "task_name": "Run a script",
23. "Action": "runCommand",
24. "args": "python script.py",
25. "schedule": {
26. "type": "date",
27. "date": "2023-04-22",
28. "time": "11:00"
29. }
30. }
31. ]
32.

2. Import Required Libraries:


 Import the necessary libraries at the beginning of the script:
1. import json
2. import os
3. import webbrowser
4. import schedule
5. import subprocess
6. import time
7. import logging
8. import datetime

12 | P a g e
3. Define Action Functions:
 Implement functions for each action type, such as opening an
application, accessing a URL, or running a command.
 Functions should accept the necessary arguments and perform the
required action.
 Example function:
1. def openApp(args, target_date=None):
2. current_date = datetime.date.today()
3. if target_date is not None and current_date != target_date:
4. return
5. try:
6. subprocess.call(args)
7. logging.info(f'Opened app "{args}"')
8. except FileNotFoundError:
9. logging.error(f'Could not open app "{args}"')
10.
11.
12. def openUrl(args, target_date=None):
13. current_date = datetime.date.today()
14. if target_date is not None and current_date != target_date:
15. return
16. try:
17. webbrowser.open(args)
18. logging.info(f'Opened URL "{args}"')
19. except Exception as e:
20. logging.error(f'Could not open URL "{args}": {e}')
21.
22.
23. def runCommand(args, target_date=None):
24. current_date = datetime.date.today()
25. if target_date is not None and current_date != target_date:
26. return
27. try:
28. os.system(args)
29. logging.info(f'Executed command "{args}"')
30. except Exception as e:
31. logging.error(f'Could not execute command "{args}": {e}')
32.

4. Schedule Tasks:
 Implement the schedule_tasks() function to load the task configurations,
schedule tasks, and run the scheduler.
 Open the 'tasks.json' file, parse its contents, and iterate over each task.
 Retrieve the task details (task name, action, arguments, and schedule).
 Based on the schedule type, use the schedule library to schedule the
task at the specified time or date.
 Log the scheduled task details.

13 | P a g e
 Example code snippet:
1. def schedule_tasks():
2. with open('tasks.json') as f:
3. tasks = json.load(f)
4. for task in tasks:
5. task_name = task['task_name']
6. Action = task['Action']
7. args = task['args']
8. schedule_obj = task['schedule']
9. schedule_type = schedule_obj['type']
10.
11. # Get the function object based on its name
12. function = globals().get(Action)
13.
14. # Schedule the task
15. try:
16. if schedule_type == 'daily':
17. schedule_time = schedule_obj['time']
18. schedule.every().day.at(schedule_time).do(function, args)
19. elif schedule_type == 'date':
20. schedule_time = schedule_obj['time']
21. schedule_date_time = datetime.datetime.strptime(schedule_obj['date'] + ' ' +
schedule_obj['time'], '%Y-%m-%d %H:%M')
22. schedule.every().day.at(schedule_time).do(function, args,
target_date=schedule_date_time.date())
23. logging.info(
24. f'Scheduled task "{task_name}" to run at {schedule_time} ({schedule_type})')
25. except Exception as e:
26. logging.error(f'scheduling task "{task_name}": {e}')
27.
28. # Keep the scheduler running
29. while True:
30. schedule.run_pending()
31. time.sleep(1)
32.

5. Execute the Scheduler:


 Place the if __name__ == '__main__': block at the end of the script.
 Inside this block, call the schedule_tasks() function to start the task
scheduling and execution.
 Example code snippet:
1. if __name__ == '__main__':
2. schedule_tasks()

6. Logging Configuration:
 Configure the logging module to record events and errors in a log file.
 Example code snippet (add this before the schedule_tasks() function):
1. logging.basicConfig(
2. filename='tasks.log',
3. level=logging.INFO,
4. format='%(asctime)s %(levelname)s: %(message)s',
5. datefmt='%Y-%m-%d %H:%M:%S'
6. )

14 | P a g e
7. Run the Script:
 Execute the main script using a Python interpreter.
 Ensure that the 'tasks.json' file is present in the same directory as the
script.
 The script will load the task configurations, schedule tasks, and start
executing them based on the specified schedule.
The implementation of the task-scheduler project involves defining action functions,
scheduling tasks, and executing them based on the predefined schedule. The logging
module helps track task execution and handle any encountered errors.

15 | P a g e
Results

16 | P a g e
Future Scope
1. User Interface Enhancement:
 Currently, the task-scheduler project relies on a task configuration file in
JSON format. A potential future enhancement could involve developing
a user interface (UI) to simplify task creation, editing, and scheduling.
This UI could provide an intuitive interface for users to define tasks, set
schedules, and manage task execution.
2. Task Dependency Management:
 Introducing task dependency management can enhance the project's
functionality. This feature would allow users to specify dependencies
between tasks, ensuring that certain tasks are executed only after the
completion of their dependent tasks. This capability would enable more
complex task workflows and enable users to define intricate task
sequences.
3. Notification and Alert System:
 Implementing a notification and alert system can provide users with
real-time updates and notifications about task execution. This feature
can include email notifications, system tray notifications, or SMS alerts
to keep users informed about task completion, errors, or other relevant
events.
4. Task Monitoring and Analytics:
 Enhancing the project with monitoring and analytics capabilities can
provide valuable insights into task execution and performance. This
feature could include tracking task execution times, success rates, error
rates, and resource consumption. Analytics can help identify
bottlenecks, optimize task scheduling, and improve overall system
efficiency.
5. Task Repository and Sharing:
 Developing a task repository and sharing platform can enable users to
discover and share pre-configured tasks. Users can benefit from a
repository of commonly used tasks, saving time on task creation and

17 | P a g e
configuration. Additionally, users can share their own task
configurations, fostering collaboration and knowledge exchange.
6. Cross-Platform Support:
 Currently, the task-scheduler project supports Windows, macOS, and
Linux operating systems. Expanding the project's compatibility to other
platforms and environments, such as mobile platforms or cloud-based
systems, would increase its versatility and reach a wider user base.
7. Advanced Scheduling Options:
 Introducing advanced scheduling options can enhance the flexibility of
the task-scheduler project. This can include features such as recurring
patterns (e.g., every weekday or specific days of the month), time
intervals, cron-like expressions, or even integration with external
calendars or scheduling systems.
8. Integration with External Services:
 Integrating the task-scheduler project with external services, APIs, or
platforms can extend its capabilities. This can enable tasks such as
sending emails, interacting with cloud services, performing database
operations, or triggering actions in other applications. Integration can
enhance automation possibilities and make the task-scheduler project a
central hub for managing various tasks and systems.
These future scope ideas aim to further enhance the functionality, usability, and
versatility of the task-scheduler project. Implementing these features can make the
project even more powerful and valuable for users, expanding its range of
applications and opening up new possibilities for task automation and management.

18 | P a g e
Conclusion
The task-scheduler project provides an efficient and customizable solution for
automating routine tasks based on predefined schedules. By leveraging the power of
Python and various libraries, it allows users to automate actions such as opening
applications, accessing URLs, or running system commands, thereby saving time and
reducing manual effort.
The project's implementation involves defining a task configuration file in JSON
format, which specifies the tasks, actions, arguments, and schedules. The project
utilizes libraries such as json, os, webbrowser, schedule, subprocess, time, and
logging to load task configurations, schedule task execution, perform actions, handle
errors, and maintain a log of events.
The system design focuses on flexibility and scalability, allowing users to define tasks
with different schedules and actions. The continuous task execution loop ensures
that tasks are executed as per the defined schedule, while the logging functionality
enables monitoring and troubleshooting of task execution.
The task-scheduler project has various applications in personal and professional
settings. It can be used to automate repetitive activities, schedule backups, perform
system maintenance, retrieve and process data, and more. By reducing manual effort
and streamlining task execution, it improves productivity and allows users to focus on
more important aspects of their work.
However, it's important to note that the task-scheduler project has certain
limitations. It relies on the system being powered on and the script running
continuously for tasks to be executed. Additionally, it may require periodic
maintenance and updates to ensure compatibility with the latest versions of libraries
and dependencies.
In conclusion, the task-scheduler project offers a valuable tool for automating routine
tasks, enhancing productivity, and reducing manual effort. With its flexible
configuration options and customizable actions, it provides a user-friendly solution
for automating a wide range of tasks. By incorporating the project into daily
workflows, users can optimize their time and focus on more critical aspects of their
work or personal activities.

19 | P a g e

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy