zhaoqingang
2025-04-01 6846a4c98a793e74ae17b47f04a0ff8b210aeb24
app/utils/common.py
@@ -1,6 +1,31 @@
import pytz
import platform
import subprocess
from datetime import datetime
def current_time():
    tz = pytz.timezone('Asia/Shanghai')
    return datetime.now(tz)
def get_machine_id():
    """获取机器的唯一标识"""
    if platform.system() == "Windows":
        # Windows 系统
        command = "wmic csproduct get UUID"
        process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
        output, _ = process.communicate()
        machine_id = output.decode().strip().split("\n")[1].strip()
    elif platform.system() == "Darwin":
        # macOS 系统
        command = "system_profiler SPHardwareDataType | grep 'Hardware UUID' | awk '{print $4}'"
        process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
        output, _ = process.communicate()
        machine_id = output.decode().strip()
    else:
        # Linux 系统
        machine_id = open("/etc/machine-id").read().strip()
    # print(machine_id)
    return machine_id