Sure, let's create a simple Python script for a trucking dispatch system. This will include basic functionalities like adding dispatches, updating status, and viewing dispatch details.
Python Script for Trucking Dispatch System
Step 1: Setup
- Install Python (if not already installed).
- Create a new Python file, e.g.,
dispatch_system.py.
Step 2: Code
# dispatch_system.py
# Import necessary modules
import json
# Initialize an empty list to store dispatches
dispatches = []
# Function to add a new dispatch
def add_dispatch(truck_id, driver_name, destination, load_details, status="Pending"):
dispatch = {
"truck_id": truck_id,
"driver_name": driver_name,
"destination": destination,
"load_details": load_details,
"status": status
}
dispatches.append(dispatch)
print(f"Dispatch added for Truck {truck_id} to {destination}.")
# Function to update dispatch status
def update_status(truck_id, new_status):
for dispatch in dispatches:
if dispatch["truck_id"] == truck_id:
dispatch["status"] = new_status
print(f"Status updated for Truck {truck_id} to {new_status}.")
return
print(f"No dispatch found for Truck {truck_id}.")
# Function to view dispatch details
def view_dispatch(truck_id):
for dispatch in dispatches:
if dispatch["truck_id"] == truck_id:
print(json.dumps(dispatch, indent=2))
return
print(f"No dispatch found for Truck {truck_id}.")
# Function to list all dispatches
def list_all_dispatches():
for dispatch in dispatches:
print(json.dumps(dispatch, indent=2))
# Main function to run the dispatch system
def main():
while True:
print("\nTrucking Dispatch System")
print("1. Add Dispatch")
print("2. Update Status")
print("3. View Dispatch")
print("4. List All Dispatches")
print("5. Exit")
choice = input("Enter your choice: ")
if choice == "1":
truck_id = input("Enter Truck ID: ")
driver_name = input("Enter Driver Name: ")
destination = input("Enter Destination: ")
load_details = input("Enter Load Details: ")
add_dispatch(truck_id, driver_name, destination, load_details)
elif choice == "2":
truck_id = input("Enter Truck ID: ")
new_status = input("Enter New Status: ")
update_status(truck_id, new_status)
elif choice == "3":
truck_id = input("Enter Truck ID: ")
view_dispatch(truck_id)
elif choice == "4":
list_all_dispatches()
elif choice == "5":
print("Exiting...")
break
else:
print("Invalid choice. Please try again.")
# Run the main function
if __name__ == "__main__":
main()
How to Run:
- Save the script as
dispatch_system.py.
- Open a terminal or command prompt.
- Navigate to the directory where the script is saved.
- Run the script using
python dispatch_system.py.
Features:
- Add Dispatch: Adds a new dispatch with truck ID, driver name, destination, load details, and status.
- Update Status: Updates the status of a dispatch by truck ID.
- View Dispatch: Displays details of a dispatch by truck ID.
- List All Dispatches: Lists all current dispatches.
Next Steps:
- Persistence: Save dispatches to a file or database for persistent storage.
- Validation: Add input validation for better data integrity.
- User Interface: Create a simple GUI using libraries like
tkinter or PyQt.
Need further customization or features? Let me know!