當前位置: 首頁>>代碼示例>>Python>>正文


Python Channel.setOnline方法代碼示例

本文整理匯總了Python中channel.Channel.setOnline方法的典型用法代碼示例。如果您正苦於以下問題:Python Channel.setOnline方法的具體用法?Python Channel.setOnline怎麽用?Python Channel.setOnline使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在channel.Channel的用法示例。


在下文中一共展示了Channel.setOnline方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from channel import Channel [as 別名]
# 或者: from channel.Channel import setOnline [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.setOnline方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。