importosimportdatetimeimportjson# -----------------------------# PHASE 1 (Final Clean Version): Incident Folder Creator# -----------------------------# What this script does:# 1. Lets the user choose an incident type (you can type spaces, e.g. "Domestic Violence")# 2. Assigns a letter identifier for the category# 3. Creates a folder named by: Date + Category + Identifier + Unique Case Number# 4. Adds two subfolders inside: "reports" and "evidence"# 5. Stores case number progress in a JSON file (so numbers keep increasing each run)# 6. Creates an "incident_summary.txt" with case details# 7. Adds placeholder for "Assigned Officers" (to be filled in later in Phase 2)# -----------------------------# Dictionary mapping incident categories to identifiersincident_categories= {
"homicide": "A",
"assault": "B",
"theft": "C",
"domestic_violence": "D",
"drug_offenses": "E",
"traffic_violations": "F"
}
# File that stores the last used case number (so numbers are continuous)case_file="case_counter.json"# Load the current case counter, or start at 0 if file doesn't existdefload_case_counter():
ifos.path.exists(case_file):
withopen(case_file, "r") asf:
returnjson.load(f)
else:
return {"last_case_number": 0}
# Save the updated case counter back into the JSON filedefsave_case_counter(counter):
withopen(case_file, "w") asf:
json.dump(counter, f)
# Main function: create an incident folderdefcreate_incident_folder(incident_type):
# Normalize input: replace spaces with underscores, lowercase everythingincident_type=incident_type.replace(" ", "_").lower()
# Check if the incident type is validifincident_typenotinincident_categories:
print("Invalid incident type. Please choose from:", list(incident_categories.keys()))
return# Load and update case countercounter=load_case_counter()
counter["last_case_number"] +=1case_number=counter["last_case_number"]
save_case_counter(counter) # Save immediately so the number persists# Today's date (YYYY-MM-DD)today=datetime.date.today().strftime("%Y-%m-%d")
# Get identifier letter for the chosen categoryidentifier=incident_categories[incident_type]
# Build folder name: Date_Category_Identifier_CaseNumberfolder_name=f"{today}_{incident_type}_{identifier}_{case_number:04d}"# Create main incident folderos.makedirs(folder_name, exist_ok=True)
# Create subfolders: "reports" and "evidence"os.makedirs(os.path.join(folder_name, "reports"), exist_ok=True)
os.makedirs(os.path.join(folder_name, "evidence"), exist_ok=True)
# Create an incident summary text file with case detailssummary_path=os.path.join(folder_name, "incident_summary.txt")
withopen(summary_path, "w") asf:
f.write("=== INCIDENT SUMMARY ===\n")
f.write(f"Case Number : {case_number:04d}\n")
f.write(f"Date : {today}\n")
f.write(f"Category : {incident_type}\n")
f.write(f"Identifier : {identifier}\n")
f.write("------------------------\n")
f.write("Reports Folder : ./reports\n")
f.write("Evidence Folder: ./evidence\n")
f.write("------------------------\n")
f.write("Assigned Officers: \n") # Placeholder for Phase 2# Confirmation messageprint(f"Folder created: {folder_name}")
print(" Subfolders: /reports, /evidence")
print(" Summary file: incident_summary.txt (with officer placeholder)")
# -----------------------------# Run the program# -----------------------------if__name__=="__main__":
print("Available categories:", list(incident_categories.keys()))
incident=input("Enter incident type: ").strip()
create_incident_folder(incident)