<commit_before># -*- coding: utf-8 -*-

from datetime import datetime, timedelta
import tweepy
from config import consumer_key, consumer_secret, access_key, access_secret
import protect_secret as ps

class Bot(tweepy.streaming.StreamListener):
    """
    Public Timelineを監視
    適当なツイートを秘密保護してぱくつい
    """
    def __init__(self):
        super(Bot, self).__init__()
        auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_key, access_secret)
        self.api = tweepy.API(auth_handler = auth, api_root = '/1.1', secure = True)
        self.next_time = datetime(2000, 1, 1)

    def on_status(self, tweet):
        lang = getattr(tweet, 'lang', u'')
        if lang != u'ja':
            return
        if datetime.now() > self.next_time:
            self.tweet_tekito(tweet.text)

    def tweet(self, text):
        self.api.update_status(text)

    def run(self):
        stream = tweepy.Stream(self.api.auth, listener = self, retry_count = 10, retry_time = 60.0)
        try:
            stream.sample()
        except KeyboardInterrupt:
            pass

    def tweet_tekito(self, text):
        self.next_time = datetime.now() + timedelta(seconds = 30)
        protected = ps.protect_secret(text)
        self.tweet(protected)
        print protected, u'\n'


if __name__ == '__main__':
    Bot().run()

<commit_msg>ツイートエラーを握りつぶす<commit_after># -*- coding: utf-8 -*-

from datetime import datetime, timedelta
import tweepy
from config import consumer_key, consumer_secret, access_key, access_secret
import protect_secret as ps

class Bot(tweepy.streaming.StreamListener):
    """
    Public Timelineを監視
    適当なツイートを秘密保護してぱくつい
    """
    def __init__(self):
        super(Bot, self).__init__()
        auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
        auth.set_access_token(access_key, access_secret)
        self.api = tweepy.API(auth_handler = auth, api_root = '/1.1', secure = True)
        self.next_time = datetime(2000, 1, 1)

    def on_status(self, tweet):
        lang = getattr(tweet, 'lang', u'')
        if lang != u'ja':
            return
        if datetime.now() > self.next_time:
            self.tweet_tekito(tweet.text)

    def tweet(self, text):
        try:
            self.api.update_status(text)
            print text
        except tweepy.error.TweepError:
            print 'ついーとえらーだって'
        print

    def run(self):
        stream = tweepy.Stream(self.api.auth, listener = self, retry_count = 10, retry_time = 60.0)
        try:
            stream.sample()
        except KeyboardInterrupt:
            pass

    def tweet_tekito(self, text):
        self.next_time = datetime.now() + timedelta(seconds = 30)
        protected = ps.protect_secret(text)
        self.tweet(protected)


if __name__ == '__main__':
    Bot().run()


{'fraction_non_alphanumeric': 0.11095406360424029, 'fraction_numerical': 0.011307420494699646, 'mean_word_length': 2.5255292652552925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2377797', 'n_tokens_mistral': 998, 'n_tokens_neox': 943, 'n_words': 199}