File size: 774 Bytes
ce1dd07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import json
import os
from datetime import datetime


def log_stats(file_path, new_data):
    # Check if the file exists, and read its content
    if os.path.exists(file_path):
        with open(file_path, 'r') as file:
            try:
                content = json.load(file)
            except json.JSONDecodeError:
                content = []
    else:
        content = []

    # Get the current date and time
    now = datetime.now()
    # Format the date and time as a string
    date_time_string = now.strftime("%Y-%m-%d %H:%M:%S")
    new_data.append(date_time_string)

    # Append the new data to the content
    content.append(new_data)

    # Write the updated content back to the file
    with open(file_path, 'w') as file:
        json.dump(content, file)