Untitled
unknown
python
a year ago
1.2 kB
12
Indexable
import json import time import keyboard def save_timestamp(timestamp): timestamp_data = {"timestamp": timestamp} with open("timestamps.json", "a") as file: json.dump(timestamp_data, file) file.write("\n") # Add newline for readability def format_time_difference(diff_seconds): hours = int(diff_seconds // 3600) minutes = int((diff_seconds % 3600) // 60) seconds = int(diff_seconds % 60) return f"{hours} hours, {minutes} minutes, {seconds} seconds" def main(): start_time = time.time() print(f"Start Timestamp: {start_time}") # Define your keybind, for example, F1 keybind = "F1" # Set up the keybind listener keyboard.add_hotkey(keybind, lambda: save_timestamp(format_time_difference(time.time() - start_time))) print(f"Press {keybind} to save current timestamp. Press 'Esc' to exit.") # Keep the script running until 'Esc' is pressed keyboard.wait("esc") if __name__ == "__main__": main() # Content of the Json File #{"timestamp": "0 hours, 0 minutes, 3 seconds"} #{"timestamp": "0 hours, 0 minutes, 5 seconds"} #{"timestamp": "0 hours, 0 minutes, 5 seconds"}
Editor is loading...
Leave a Comment