mirror of
https://github.com/yshtcn/heartbeat.git
synced 2025-12-14 02:00:29 +08:00
Update heartbeat.py
- 增加自动复制范例的功能 - 修正无法正确读取UTF-8
This commit is contained in:
parent
c01ed6e00c
commit
b7fc6bab38
@ -52,12 +52,19 @@ def quit_action(icon, item):
|
||||
image = create_image()
|
||||
icon = pystray.Icon("系统心跳", image, "系统状态报送", menu=pystray.Menu(pystray.MenuItem('关闭主机状态报送', quit_action)))
|
||||
|
||||
# 检查config.ini是否存在,如果不存在,从config.Exsample.ini复制一份
|
||||
config_path = os.path.join(current_dir, 'config.ini')
|
||||
if not os.path.exists(config_path):
|
||||
exsample_config_path = os.path.join(current_dir, 'config.Exsample.ini')
|
||||
shutil.copyfile(exsample_config_path, config_path)
|
||||
|
||||
# 从配置文件读取设置
|
||||
config = configparser.ConfigParser()
|
||||
config.read(os.path.join(current_dir, 'config.ini'))
|
||||
config.read(config_path, encoding='utf-8') # 使用UTF-8编码来读取文件
|
||||
interval = config.getint('Settings', 'interval')
|
||||
heartbeat_url = config.get('Settings', 'heartbeat_url')
|
||||
|
||||
|
||||
# 创建一个新的Session对象,并根据需要配置代理
|
||||
session = requests.Session()
|
||||
if config.get('Settings', 'proxy_enabled', fallback='0') == '1':
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user