Exemplo n.º 1
0
            data['new_roomids'])
        return web.json_response({
            'code': 0,
            'data': {
                'sleep_time': sleep_time,
            }
        })
    except json_req_exceptions.JsonReqError as e:
        return web.json_response(e.RSP_SUGGESTED)
    except:
        return web.json_response(json_req_exceptions.DataError.RSP_SUGGESTED)


if sys.platform != 'linux' or signal.getsignal(
        signal.SIGHUP) == signal.SIG_DFL:
    console_thread = threading.Thread(target=BiliConsole(loop).cmdloop)
    console_thread.start()
else:
    console_thread = None

loop.create_task(raffle_handler.run())
loop.create_task(monitors_ctrl_center.run())

app = web.Application()
setup(app)
app.router.add_route('GET', '/check', check_handler)
app.router.add_route('POST', '/add_new_roomids', add_new_roomids_handler)

with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
    s.connect(("114.114.114.114", 80))
    print('本机 IP 为', s.getsockname()[0])
Exemplo n.º 2
0
    if other_control['substance_raffle']:
        _danmu_monitors.append(SubstanceRaffleMonitor())
    if other_control['dyn_raffle']:
        _danmu_monitors.append(
            DynRaffleMonitor(should_join_immediately=other_control[
                'join_dyn_raffle_at_once']))
    return _danmu_printer, _danmu_monitors


danmu_printer, monitors = loop.run_until_complete(init_monitors())
bili_sched.init(monitors=monitors,
                sleep_ranges=dict_ctrl['other_control']['sleep_ranges'])

# 初始化控制台
if sys.platform != 'linux' or signal.getsignal(
        signal.SIGHUP) == signal.SIG_DFL:
    console_thread = threading.Thread(
        target=BiliConsole(loop, default_roomid, danmu_printer).cmdloop)
    console_thread.start()
else:
    console_thread = None

tasks = [monitor.run() for monitor in monitors]
other_tasks = [bili_sched.run(), raffle_handler.run(), danmu_printer.run()]
if other_tasks:
    loop.run_until_complete(asyncio.wait(tasks + other_tasks))
loop.run_forever()
if console_thread is not None:
    console_thread.join()
Exemplo n.º 3
0

async def fetch_roomid_periodic():
    yjmonitor_tcp_addr = other_control['yjmonitor_tcp_addr']
    yjmonitor_tcp_key = other_control['yjmonitor_tcp_key']
    monitor = TcpYjMonitorClient(
        key=yjmonitor_tcp_key,
        url=yjmonitor_tcp_addr,
        area_id=0)
    asyncio.create_task(monitor.run())
    await PollRoomChecker(START, END).run()


# 初始化控制台
if sys.platform != 'linux' or signal.getsignal(signal.SIGHUP) == signal.SIG_DFL:
    console_thread = threading.Thread(
        target=BiliConsole(loop).cmdloop)
    console_thread.start()
else:
    console_thread = None

other_tasks = [
    raffle_handler.run(),
    fetch_roomid_periodic()
]
if other_tasks:
    loop.run_until_complete(asyncio.wait(other_tasks))
loop.run_forever()
if console_thread is not None:
    console_thread.join()