読者です 読者をやめる 読者になる 読者になる

ntddk信者のためのネトスト機能

ntddk

話変わるけど、はてなブログイマイチ使い方わかってない

 

# -*- coding: utf-8 -*-
from tweepy.streaming import StreamListener, Stream
from tweepy.auth import OAuthHandler
from tweepy.api import API
import re

cons_key = "*"
cons_sec = "*"
aces_tok = "*"
aces_sec = "*"
auth = OAuthHandler(cons_key, cons_sec)
auth.set_access_token(aces_tok, aces_sec)
api = API(auth)

def search(text):
    regex = re.compile(u".+だから(.+)てる")
    result = regex.match(text)
    if result != None:
        return u"ntddk信者だから" + result.group(1) + u"てる"
    return None

class UserStream(StreamListener):
    def __init__(self):
        StreamListener.__init__(self)

    def on_status(self, status):
        try:
            if status.author.screen_name == "ntddk":
                s = search(status.text)
                api.update_status(s)
                if s != None:
                    api.update_status(s)
        except:
            pass

def main():
    stream = Stream(auth, UserStream(), secure=True)
    stream.userstream()

if __name__ == "__main__":

    main()