当前位置: 首页>>代码示例>>Python>>正文


Python Channel.selectOfflineUser方法代码示例

本文整理汇总了Python中channel.Channel.selectOfflineUser方法的典型用法代码示例。如果您正苦于以下问题:Python Channel.selectOfflineUser方法的具体用法?Python Channel.selectOfflineUser怎么用?Python Channel.selectOfflineUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在channel.Channel的用法示例。


在下文中一共展示了Channel.selectOfflineUser方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from channel import Channel [as 别名]
# 或者: from channel.Channel import selectOfflineUser [as 别名]
def main(lineMax=5000, logfileName='ircsimul.log', writeStdOut=False, realTime=False, 
    logInitialPopulation=False):
    # create character maps for various text processing/writing functions
    helpers.makeTransMaps()

    # load up markov generator
    markovGenerator = markov.MarkovGenerator(sourcefileName, reasonsfileName)

    # load channel
    channel = Channel(channelName, markovGenerator, initialUserCount)

    # open log
    fileObjectList = []
    fileObjectList.append(open(logfileName, 'wt', encoding='utf8'))
    if writeStdOut:
        fileObjectList.append(sys.stdout)
    log = Log(fileObjectList)

    # get current date
    date = datetime.datetime.utcnow()

    daycache = date.day

    # create queue
    queue = PriorityQueue()

    # write opening of log
    log.writeLogOpening(date)

    # populates channel with initialPopulation users
    if logInitialPopulation:
        for i in range(0, initialPopulation):
            event = JoinEvent(date, channel.selectOfflineUser(), channel)
            queue.put(event)
    else:
        for i in range(0, initialPopulation):
            channel.setOnline(channel.selectOfflineUser())

    # bulk of messages
    currentEvent = None
    while True:
        if not lineMax == -1:
            if log.totalLines >= lineMax - 1:
                break
        # empty queue
        try:
            while not queue.empty():
                currentEvent = queue.get()
                if currentEvent:
                    line = currentEvent.process()
                    if line:
                        now = datetime.datetime.utcnow()
                        if realTime and (currentEvent.date > now):
                            delta = currentEvent.date - datetime.datetime.utcnow()
                            print(str(delta.total_seconds()))
                            time.sleep(delta.total_seconds())
                            log.write(line)
                            log.flush()
                        else:
                            log.write(line)
                else: break
        except Empty:
            pass

        # check if day changed, if so, write day changed message
        # TODO: make this event based
        if daycache != date.day:
            log.writeDayChange(date)
            daycache = date.day

        # generate line
        determineType = random()
        if determineType > joinPartProbability:
            # user message
            user = channel.selectOnlineUser()
            event = MessageEvent(date, user, flavourText(markovGenerator.generateMessage(), user))
        elif determineType > actionProbability:
            # random join/part event
            user = channel.selectUser()
            if user in channel.online:
                if random() < quitProbability:
                    event = QuitEvent(date, user, markovGenerator.generateReason(), channel)
                else:
                    event = LeaveEvent(date, user, markovGenerator.generateReason(), channel)
            else:
                event = JoinEvent(date, user, channel)
        elif determineType > kickProbability:
            # user action
            # TODO: implement variable user action text
            event = UserActionEvent(date, channel.selectOnlineUser(), "does action")
        else:
            # kick event
            event = KickEvent(date, channel.selectOnlineUser(), channel.selectOnlineUser(), markovGenerator.generateReason(), channel)
        queue.put(event)

        # makes sure some amount of peeps are online or offline
        # TODO: check if population checks could be made obsolete by having the next join/parts already cached
        # TODO: move to channel class later?
        if channel.onlineUsers < minOnline:
            event = JoinEvent(date, channel.selectOfflineUser(), channel)
#.........这里部分代码省略.........
开发者ID:deweyvm,项目名称:ircsimul,代码行数:103,代码来源:ircsimul.py


注:本文中的channel.Channel.selectOfflineUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。