本文整理汇总了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)
#.........这里部分代码省略.........