import json from datetime import datetime def generate_trip_report(): report = {} report['name'] = input("Enter name of report: ") report['chemical'] = input("Chemical: ") report['tester'] = input("Tester: ") report['dosage'] = input("Dosage (example: 5mg): ") report['tolerance'] = input("Tolerance: ") report['cross_tolerance'] = input("Cross-Tolerance: ") report['entries'] = [] start_time = None # Variable to store the start time while True: entry = {} current_time = datetime.now().strftime("%I:%M:%S %p") if start_time is None: start_time = datetime.now() # Set start time when submitting the first timestamp elapsed_time = datetime.now() - start_time formatted_elapsed_time = "{:02}:{:02}:{:02}".format(elapsed_time.seconds // 3600, (elapsed_time.seconds // 60) % 60, elapsed_time.seconds % 60) entry['timestamp'] = current_time entry['elapsed_time'] = formatted_elapsed_time entry['notes'] = input(f"Notes (example: Took {report['dosage']} {report['chemical']}): ") report['entries'].append(entry) stop_input = input("Write 'save' to stop: ") if stop_input.lower() == 'save': report['submit_date'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S") break return report def save_report_to_json(report): with open(f"{report['name']}.json", 'w') as json_file: json.dump(report, json_file, indent=4) if __name__ == "__main__": trip_report = generate_trip_report() save_report_to_json(trip_report) print(f"Trip report saved to {trip_report['name']}.json.")