Skip to content

Commit

Permalink
chore:run service
Browse files Browse the repository at this point in the history
  • Loading branch information
Guovin committed Nov 15, 2024
1 parent 227220b commit 4197314
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
27 changes: 17 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,6 @@ async def main(self):
True,
url=f"{get_ip_address()}" if open_service else None,
)
if open_service:
run_service()
except asyncio.exceptions.CancelledError:
print("Update cancelled!")

Expand Down Expand Up @@ -253,14 +251,23 @@ def scheduled_task():


def run_service():
if not os.environ.get("GITHUB_ACTIONS"):
ip_address = get_ip_address()
print(f"📄 Result detail: {ip_address}/result")
print(f"📄 Log detail: {ip_address}/log")
print(f"✅ You can use this url to watch IPTV 📺: {ip_address}")
app.run(host="0.0.0.0", port=8000)
try:
if not os.environ.get("GITHUB_ACTIONS"):
ip_address = get_ip_address()
print(f"📄 Result detail: {ip_address}/result")
print(f"📄 Log detail: {ip_address}/log")
print(f"✅ You can use this url to watch IPTV 📺: {ip_address}")
app.run(host="0.0.0.0", port=8000)
except Exception as e:
print(f"❌ Service start failed: {e}")


if __name__ == "__main__":
if len(sys.argv) == 1 or (len(sys.argv) > 1 and sys.argv[1] == "scheduled_task"):
scheduled_task()
if len(sys.argv) == 1 and config.open_service:
loop = asyncio.new_event_loop()

async def run_service_async():
loop.run_in_executor(None, run_service)

asyncio.run(run_service_async())
scheduled_task()
10 changes: 8 additions & 2 deletions tkinter_ui/tkinter_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from PIL import Image, ImageTk
from utils.config import config
from utils.tools import resource_path
from main import UpdateSource
from main import UpdateSource, run_service
import asyncio
import threading
import webbrowser
Expand Down Expand Up @@ -113,11 +113,17 @@ async def run_update(self):
self.progress_label.pack_forget()

def on_run_update(self):
loop = asyncio.new_event_loop()

async def run_service_async():
loop.run_in_executor(None, run_service)

def run_loop():
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(self.run_update())

if config.open_service:
asyncio.run(run_service_async())
self.thread = threading.Thread(target=run_loop, daemon=True)
self.thread.start()

Expand Down
15 changes: 9 additions & 6 deletions utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,15 @@ def get_result_file_content(show_result=False):
Get the content of the result file
"""
user_final_file = resource_path(config.final_file)
if config.open_m3u_result:
user_final_file = os.path.splitext(user_final_file)[0] + ".m3u"
if show_result == False:
return send_file(user_final_file, as_attachment=True)
with open(user_final_file, "r", encoding="utf-8") as file:
content = file.read()
if os.path.exists(user_final_file):
if config.open_m3u_result:
user_final_file = os.path.splitext(user_final_file)[0] + ".m3u"
if show_result == False:
return send_file(user_final_file, as_attachment=True)
with open(user_final_file, "r", encoding="utf-8") as file:
content = file.read()
else:
content = "🔍️正在更新,请耐心等待更新完成..."
return render_template_string(
"<head><link rel='icon' href='{{ url_for('static', filename='images/favicon.ico') }}' type='image/x-icon'></head><pre>{{ content }}</pre>",
content=content,
Expand Down

0 comments on commit 4197314

Please sign in to comment.