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


Python Markov.gen方法代码示例

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


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

示例1: main

# 需要导入模块: from markov import Markov [as 别名]
# 或者: from markov.Markov import gen [as 别名]
def main(params):
    consumer_key = params.get('twitter', 'consumer_key')
    consumer_secret = params.get('twitter', 'consumer_secret')
    access_token = params.get('twitter', 'access_token')
    access_token_secret = params.get('twitter', 'access_secret')

    auth = tweepy.auth.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)
    api = tweepy.API(auth)

    corpus = params.get('markov', 'corpus')
    is_pickled = params.getboolean('markov', 'pickled')
    m = Markov(corpus)
    if is_pickled:
        m.load_db()
    else:
        m.make_db()

    text = m.gen(climit=140)
    api.update_status(text)
开发者ID:Battleroid,项目名称:anangrybot,代码行数:22,代码来源:twit.py

示例2: AveryBot

# 需要导入模块: from markov import Markov [as 别名]
# 或者: from markov.Markov import gen [as 别名]
class AveryBot(SingleServerIRCBot):
    def __init__(self, mindfile, blfile, logfile, agefile,
        real_id, real, ident, birthday, friend):
        SingleServerIRCBot.__init__(self,
            [(ident.server, ident.port)], ident.nickname, ident.realname)

        self.mindfile = mindfile
        self.blfile = blfile
        self.logfile = logfile
        self.agefile = agefile
        # load mind
        try:
            self.mind = pickle.load(open(mindfile, 'rb'))
        except IOError:
            print("No markov file (" + mindfile + ") found; making a blank one")
            self.mind = Markov(2)

        # words that will highlight some nicks, in the form of a dictionary
        # from words to the nicks they hilight.
        try:
            self.blacklist = pickle.load(open(self.blfile, "rb"))
        except FileNotFoundError:
            self.blacklist = []

        class State(dict):
            def __getitem__(self, key):
                if key not in self:
                    super(State, self).__setitem__(key, random.getstate())

                return super(State, self).__getitem__(key)

        # the handle generator
        self.handlegen = Markov(2)
        for line in open("nicks", "r"):
            line = line[:-1] # strip newl
            n = []
            for c in line:
                n.append(MarkovElem(c))

            #n = map(MarkovElem, line)

            n[0].tags["pos"] = "BEGIN"
            n[-1].tags["pos"] = "END"

            self.handlegen.learn(n)

        try:
            self.states = pickle.load(open("rstate", "rb"))
        except FileNotFoundError:
            self.states = State()
        
        self.waiting_for_friend = queue.Queue() # channels to send lurkers to

        self.nick = ident.nickname
        self.password = ident.password
        self.channel = ident.channel    # active channels
        self.cafe = ident.cafe
        self.rstate = random.getstate() # random state
        self.real_id = real_id          # whether self.real is a user or a nick
        self.real = real                # real user she imitates (i.e. avery)
        #self.save_counter = 0           # write to disk every 100 talks
        self.friend = friend
        self.birthday = birthday

    def at_bday(self, birthday):
        now = datetime.datetime.today()
        bday = self.birthday.replace(year = now.year)
        if bday <= now: bday = bday.replace(year = bday.year + 1)
        print("next birthday:", bday)

        bday_action = threading.Timer((bday - now).total_seconds(), birthday)
        bday_action.daemon=True
        bday_action.start()

    def on_welcome(self, c, e):
        c.mode(self.nick, '+B-x')
        c.privmsg("NickServ", "IDENTIFY " + self.password)
        for channel in self.channel:
            c.join(channel)
        c.join(self.cafe)

        def birthday():
            age = int(open(self.agefile, 'r').read()) + 1
            c.action(self.cafe, "is %s years old today!" % age)
            print(age, file=open(self.agefile, 'w'))
            self.at_bday(birthday)

        self.at_bday(birthday)

    # cache each channel's mode
    def on_join(self, c, e):
        if e.source.nick == self.nick:
            c.mode(e.target, "")

    # basically borrowed from irc.bot.py's _on_mode(), since this library is a
    # god damn piece of shit
    def on_channelmodeis(self, c, e):
        print("debugging mode change:", e.arguments[1])
        modes = irc.modes.parse_channel_modes(e.arguments[1])
        t = e.arguments[0]
#.........这里部分代码省略.........
开发者ID:anachrome,项目名称:averybot,代码行数:103,代码来源:averybot.py


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