Skip to content

Commit ba176e8

Browse files
committed
修复pipy问题
1 parent ed7cb20 commit ba176e8

3 files changed

Lines changed: 23 additions & 10 deletions

File tree

main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ def main():
2929
gradio_parent.add_argument(
3030
"--port",
3131
type=int,
32-
default=int(
33-
os.environ.get("BTB_PORT", os.environ.get("GRADIO_SERVER_PORT", 7860))
34-
),
32+
default=os.environ.get("BTB_PORT", os.environ.get("GRADIO_SERVER_PORT", None)),
3533
help='Server port for Gradio. Defaults to env "BTB_PORT"/"GRADIO_SERVER_PORT" or 7860.',
3634
)
3735

task/buy.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import json
2+
import os
23
import subprocess
34
import sys
45
import time
56
from random import randint
67
from datetime import datetime
78
from json import JSONDecodeError
8-
from urllib.parse import urlencode
9-
9+
import shutil
1010
import qrcode
1111
from loguru import logger
1212

@@ -145,7 +145,6 @@ def buy_stream(
145145
if err == 100051:
146146
break
147147
yield f"[尝试 {attempt}/60] [{err}]({ERRNO_DICT.get(err, '未知错误码')}) | {ret}"
148-
149148

150149
time.sleep(interval / 1000)
151150

@@ -257,9 +256,25 @@ def buy_new_terminal(
257256
show_random_message=True,
258257
terminal_ui="网页",
259258
) -> subprocess.Popen:
260-
command = [sys.executable]
261-
if not getattr(sys, "frozen", False):
262-
command.extend(["main.py"])
259+
command = None
260+
261+
# 1️⃣ PyInstaller / frozen
262+
if getattr(sys, "frozen", False):
263+
command = [sys.executable]
264+
else:
265+
# 2️⃣ 源码模式:检查「当前脚本目录」是否有 main.py
266+
script_dir = os.path.dirname(os.path.abspath(__file__))
267+
main_py = os.path.join(script_dir, "main.py")
268+
269+
if os.path.exists(main_py):
270+
command = [sys.executable, main_py]
271+
# 3️⃣ 兜底:使用 btb(pip / pipx)
272+
else:
273+
btb_path = shutil.which("btb")
274+
if not btb_path:
275+
raise RuntimeError("Cannot find main.py or btb command")
276+
277+
command = [btb_path]
263278
command.extend(["buy", tickets_info])
264279
if interval is not None:
265280
command.extend(["--interval", str(interval)])

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)