diff --git a/gen_raw.py b/gen_raw.py new file mode 100644 index 0000000..1dff60d --- /dev/null +++ b/gen_raw.py @@ -0,0 +1,35 @@ +import json +from datetime import datetime + +def generate_raw_text(trip_report): + raw_text += f"# Metadata\n" + raw_text += f"Chemical: {trip_report['chemical']}\n" + raw_text += f"Tester: {trip_report['tester']}\n" + raw_text += f"Dosage: {trip_report['dosage']}\n" + raw_text += f"Tolerance: {trip_report['tolerance']}\n" + raw_text += f"Cross-Tolerance: {trip_report['cross_tolerance']}\n\n" + + raw_text += "# Report\n" + + for entry in trip_report['entries']: + raw_text += f"{entry['timestamp']} ({entry['elapsed_time']}) {entry['notes']}\n" + + raw_text += f"\nReport generated on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n" + raw_text += f"Submit date: {trip_report['submit_date']}\n" + + return raw_text + +def save_raw_text(raw_text, destination_path): + with open(destination_path, 'w') as txt_file: + txt_file.write(raw_text) + print(f"Raw text saved to {destination_path}.") + +if __name__ == "__main__": + json_path = input("Enter path to JSON report: ") + destination_path = input("Enter path for destination TXT file: ") + + with open(json_path, 'r') as json_file: + trip_report = json.load(json_file) + + raw_text = generate_raw_text(trip_report) + save_raw_text(raw_text, destination_path) \ No newline at end of file diff --git a/gen_static.py b/gen_static.py new file mode 100644 index 0000000..8d01c2f --- /dev/null +++ b/gen_static.py @@ -0,0 +1,135 @@ +import json +from datetime import datetime + +def generate_metadata_table(trip_report): + metadata_table = """ +
Attribute | +Value | +
---|---|
Chemical | +{} | +
Tester | +{} | +
Dosage | +{} | +
Tolerance | +{} | +
Cross-Tolerance | +{} | +
Timestamp | +Elapsed Time | +Notes | +
---|---|---|
{} | +{} | +{} | +
Report submitted at: {}
+Static HTML generated at: {}
+ + + """.format(metadata_table, trip_report_table, submit_date, generation_date) + + return html_report + +def save_html_report(html_report, destination_path): + with open(destination_path, 'w') as html_file: + html_file.write(html_report) + print("HTML report saved to {}.".format(destination_path)) + +if __name__ == "__main__": + json_path = input("Enter path to JSON report: ") + destination_path = input("Enter path for destination HTML file: ") + + with open(json_path, 'r') as json_file: + trip_report = json.load(json_file) + + html_report = generate_html_report(trip_report) + save_html_report(html_report, destination_path) \ No newline at end of file diff --git a/report.py b/report.py new file mode 100644 index 0000000..bed7044 --- /dev/null +++ b/report.py @@ -0,0 +1,47 @@ +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.")