one_click_launcher.py

import sys
import time
import threading
from datetime import datetime

class MobileAutoStarter:
def init(self):
self.running = False
self.thread = None

def show_menu(self):
    print("""
    === 手机APP自动运营系统 ===
    1. 立即运行一次
    2. 启动定时任务
    3. 停止所有任务
    4. 查看运行状态
    5. 退出系统
    """)

def immediate_run(self):
    """立即运行一次"""
    print(f"{datetime.now()} - 开始执行任务...")
    # 这里调用您的自动化逻辑
    self.simulate_operations()
    print(f"{datetime.now()} - 任务执行完成")

def start_scheduled(self):
    """启动定时任务"""
    if self.running:
        print("任务已经在运行中")
        return
    
    self.running = True
    self.thread = threading.Thread(target=self._scheduler)
    self.thread.daemon = True
    self.thread.start()
    print("定时任务已启动")

def stop_all(self):
    """停止所有任务"""
    self.running = False
    if self.thread:
        self.thread.join(timeout=1)
    print("所有任务已停止")

def _scheduler(self):
    """定时调度器"""
    while self.running:
        current_hour = datetime.now().hour
        if 9 <= current_hour <= 22:  # 只在白天运行
            self.immediate_run()
            time.sleep(1800)  # 每30分钟运行一次
        else:
            time.sleep(600)  # 晚上每10分钟检查一次

def simulate_operations(self):
    """模拟自动化操作"""
    operations = [
        "启动目标APP",
        "浏览推荐内容",
        "执行互动操作",
        "返回主界面"
    ]
    for op in operations:
        print(f"执行: {op}")
        time.sleep(2)

def run(self):
    """主运行循环"""
    while True:
        self.show_menu()
        choice = input("请选择操作 (1-5): ").strip()
        
        if choice == '1':
            self.immediate_run()
        elif choice == '2':
            self.start_scheduled()
        elif choice == '3':
            self.stop_all()
        elif choice == '4':
            status = "运行中" if self.running else "已停止"
            print(f"当前状态: {status}")
        elif choice == '5':
            self.stop_all()
            print("系统退出")
            break
        else:
            print("无效选择,请重新输入")
        
        input("\n按Enter键继续...")

if name == "main":
starter = MobileAutoStarter()
starter.run()

HAMI_4697761593 · 5 小时前

回答

Hamibot AI
1
· 5 小时前

对不起,我已经学习的知识中不包含问题相关内容,暂时无法提供答案。如果你有Hamibot产品的其他相关问题,我会帮助你解答。

ℹ️ 本回答由 AI 生成,内容仅供参考