Skip to content

Commit

Permalink
start falsk 添加参数是否自动打开浏览器
Browse files Browse the repository at this point in the history
  • Loading branch information
xaoyaoo committed Jan 20, 2024
1 parent 2078619 commit 26a84f9
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions pywxdump/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def start_falsk(merge_path="", msg_path="", micro_path="", media_path="", wx_path="", key="", my_wxid="", port=5000,
online=False, debug=False):
online=False, debug=False,isopenBrowser=True):
"""
启动flask
:param merge_path: 合并后的数据库路径
Expand Down Expand Up @@ -75,21 +75,21 @@ def before_request():
save_session(session_file, "test", my_wxid)

app.register_blueprint(api)

try:
# 自动打开浏览器
url = f"http://127.0.0.1:{port}/"
# 根据操作系统使用不同的命令打开默认浏览器
if sys.platform.startswith('darwin'): # macOS
subprocess.call(['open', url])
elif sys.platform.startswith('win'): # Windows
subprocess.call(['start', url], shell=True)
elif sys.platform.startswith('linux'): # Linux
subprocess.call(['xdg-open', url])
else:
print("Unsupported platform, can't open browser automatically.")
except Exception as e:
pass
if isopenBrowser:
try:
# 自动打开浏览器
url = f"http://127.0.0.1:{port}/"
# 根据操作系统使用不同的命令打开默认浏览器
if sys.platform.startswith('darwin'): # macOS
subprocess.call(['open', url])
elif sys.platform.startswith('win'): # Windows
subprocess.call(['start', url], shell=True)
elif sys.platform.startswith('linux'): # Linux
subprocess.call(['xdg-open', url])
else:
print("Unsupported platform, can't open browser automatically.")
except Exception as e:
pass

def is_port_in_use(host, port):
import socket
Expand Down

0 comments on commit 26a84f9

Please sign in to comment.