Exemplo n.º 1
0
def OnBlipSubmitted(properties, context):
    blip = context.GetBlipById(properties['blipId'])
    text = blip.GetDocument().GetText()
    # 既に全裸になっていれば何もしない
    if re.search(u'全裸で', text):
        return
    # config.yamlから設定情報を取得
    #     ---
    #     robot:
    #       appid: **************
    config_data = yaml.load(open('config.yaml'))
    zenra = Zenra(appid = config_data['robot']['appid'])
    zenra_text = zenra.zenrize(text).decode('utf-8')
    logging.debug(text)
    logging.debug(zenra_text)

    # 全裸になってなければ何もしない
    if text == zenra_text:
        return

    for match in re.finditer(u'全裸で', zenra_text):
        blip.GetDocument().InsertText(match.start(), u'全裸で')
        blip.GetDocument().SetAnnotation(
            document.Range(match.start(), match.end()),
            'style/fontWeight',
            'bold',
            )
Exemplo n.º 2
0
Arquivo: twitter.py Projeto: aeg/Zenra
    def zenrize(self):
        cache = memcache.decr(ZENRIZE_COUNT)
        if cache:
            logging.debug('count: %d' % cache)
            return

        url = 'http://twitter.com/statuses/friends_timeline.json?count=100'
        result = urlfetch.fetch(
            url     = url,
            headers = self.auth_header,
            )
        logging.debug(result.status_code)
        if result.status_code == 200:
            statuses = simplejson.loads(result.content)

            # 次の実行時間を決定する
            format = '%a %b %d %H:%M:%S +0000 %Y'
            first = datetime.strptime(statuses[ 0]['created_at'], format)
            last  = datetime.strptime(statuses[-1]['created_at'], format)
            logging.debug('first : %s' % first)
            logging.debug('last  : %s' % last)
            logging.debug(first - last)
            memcache.set(ZENRIZE_COUNT, (first - last).seconds / 60)

            def judge(status):
                # 自分の発言は除く
                if status['user']['screen_name'] == self.bot_config['username']:
                    return False
                # 非公開の発言も除く
                if status['user']['protected']:
                    return False
                # RTっぽい発言も除く
                if re.search('RT[ :].*@\w+', status['text']):
                    return False
                # ハッシュタグっぽいものを含んでいる発言も除く
                if re.search(' #\w+', status['text']):
                    return False
                # 既に「全裸で」が含まれている発言も除く
                if re.search(u'全裸で', status['text']):
                    return False
                # それ以外のものはOK
                return True

            # 残ったものからランダムに選択して全裸にする
            candidate = filter(judge, statuses)
            random.shuffle(candidate)
            zenra = Zenra()
            for status in candidate:
                text = zenra.zenrize(status['text']).decode('utf-8')
                # うまく全裸にできたものだけ投稿
                if re.search(u'全裸で', text):
                    logging.debug(text)
                    self.update(status = u'@%s が全裸で言った: %s' % (
                            status['user']['screen_name'],
                            text,
                            ), in_reply_to = status['id'])
                    break
Exemplo n.º 3
0
    def zenrize(self):
        cache = memcache.decr(ZENRIZE_COUNT)
        if cache:
            logging.debug("count: %d" % cache)
            return

        url = "http://twitter.com/statuses/friends_timeline.json?count=50"
        result = urlfetch.fetch(url=url, headers=self.auth_header)
        logging.debug(result.status_code)
        if result.status_code == 200:
            statuses = simplejson.loads(result.content)

            # 次の実行時間を決定する
            format = "%a %b %d %H:%M:%S +0000 %Y"
            first = datetime.strptime(statuses[0]["created_at"], format)
            last = datetime.strptime(statuses[-1]["created_at"], format)
            logging.debug("first : %s" % first)
            logging.debug("last  : %s" % last)
            logging.debug(first - last)
            memcache.set(ZENRIZE_COUNT, (first - last).seconds / 60)

            def judge(status):
                # 自分の発言は除く
                if status["user"]["screen_name"] == self.bot_config["username"]:
                    return False
                # 非公開の発言も除く
                if status["user"]["protected"]:
                    return False
                # RTっぽい発言も除く
                if re.search("RT[ :].*@\w+", status["text"]):
                    return False
                # ハッシュタグっぽいものを含んでいる発言も除く
                if re.search(" #\w+", status["text"]):
                    return False
                # 既に「夜」が含まれている発言も除く
                if re.search(u"夜", status["text"]):
                    return False
                # それ以外のものはOK
                return True

            # 残ったものからランダムに選択して全裸にする
            candidate = filter(judge, statuses)
            random.shuffle(candidate)
            zenra = Zenra()
            for status in candidate:
                text = zenra.zenrize(status["text"]).decode("utf-8")
                # うまくできたものだけ投稿
                if re.search(u"夜", text):
                    logging.debug(text)
                    self.update(
                        status=u"@%s のオトナな発言: %s" % (status["user"]["screen_name"], text), in_reply_to=status["id"]
                    )
                    break
Exemplo n.º 4
0
def OnBlipSubmitted(properties, context):
    blip = context.GetBlipById(properties['blipId'])
    text = blip.GetDocument().GetText()
    # config.yamlから設定情報を取得
    #     ---
    #     robot:
    #       appid: **************
    config_data = yaml.load(open('config.yaml'))
    zenra = Zenra(appid = config_data['robot']['appid'])
    zenra_text = zenra.zenrize(text).decode('utf-8')
    logging.debug(text)
    logging.debug(zenra_text)
    # 全裸になってなければ何もしない
    if text == zenra_text:
        return
    blip.GetDocument().SetText(zenra_text)
Exemplo n.º 5
0
    def zenrize(self):
        url = 'http://twitter.com/statuses/friends_timeline.json??count=50'
        result = urlfetch.fetch(
            url     = url,
            headers = self.auth_header,
            )
        logging.debug(result.status_code)
        if result.status_code == 200:
            statuses = simplejson.loads(result.content)

            def judge(status):
                # 自分の発言は除く
                if status['user']['screen_name'] == self.bot_config['username']:
                    return False
                # 非公開の発言も除く
                if status['user']['protected']:
                    return False
                # RTっぽい発言も除く
                if re.search('RT[ :].*@\w+', status['text']):
                    return False
                # ハッシュタグっぽいものを含んでいる発言も除く
                if re.search(' #\w+', status['text']):
                    return False
                # それ以外のものはOK
                return True

            # 残ったものからランダムに選択して全裸にする
            candidate = filter(judge, statuses)
            random.shuffle(candidate)
            zenra = Zenra()
            for status in candidate:
                text = zenra.zenrize(status['text']).decode('utf-8')
                # うまく全裸にできたものだけ投稿
                if re.search(u'全裸で', text):
                    logging.debug(text)
                    self.update(status = u'@%s が全裸で言った: %s' % (
                            status['user']['screen_name'],
                            text,
                            ), in_reply_to = status['id'])
                    break