<commit_before>import twitter
import json

from datastore import TweetDatastore

f = open('secrets.json','rb')
secrets = json.load(f)
f.close()

class TwitterBot(object):
    """docstring for TwitterBot"""
    def __init__(self, account_name):
        super(TwitterBot, self).__init__()
        self.__app = secrets['twitter']['app']
        self.__account = secrets['twitter']['accounts'][account_name]
        self._api_client = twitter.Api(consumer_key = self.__app['consumer_key'],
                                       consumer_secret = self.__app['consumer_secret'],
                                       access_token_key = self.__account['token_key'],
                                       access_token_secret = self.__account['token_secret'])
        self.user = self._api_client.GetUser(user_id=self.__account['user_id'])
        self.db = TweetDatastore(account_name)
        self.__backfill_db()

    def __backfill_db(self):
        try:
            tweets = self._api_client.GetUserTimeline(user_id=self.__account['user_id'], count = 200)
            self.db.store(tweets)
        except Exception, e:
            pass

    def generate_text(self, in_reply_to=None):
        """
        extend this method with your generator
        """
        return "override this method in the TwitterBot class to generate your text"

    def tweet(self, text, in_reply_to=None):
        """
        posts an update as the authenticated user

        Args:
            in_reply_to: a Twitter.Status object
        """

        if in_reply_to == None:
            tweet = self._api_client.PostUpdate(text)
        else:
            assert(type(in_reply_to) == twitter.status.Status)
            self.db.store(in_reply_to)
            reply_text = '@%s %s' % (in_reply_to.user.screen_name, text)
            reply_text.replace('@%s ' % self.__account['screen_name'],'')
            tweet = self._api_client.PostUpdate(reply_text, in_reply_to_status_id = str(in_reply_to.id))

        self.db.store(tweet)
        return tweet
        
    def has_replied(self, tweet):
        sql = """
        SELECT count(status_id) from tweets
        where in_reply_to_status_id = ?
        """ 
        curs = self.db._TweetDatastore__conn.cursor()<commit_msg>bugfix: don't repeat own username in replies<commit_after>import twitter
import json

from datastore import TweetDatastore

f = open('secrets.json','rb')
secrets = json.load(f)
f.close()

class TwitterBot(object):
    """docstring for TwitterBot"""
    def __init__(self, account_name):
        super(TwitterBot, self).__init__()
        self.__app = secrets['twitter']['app']
        self.__account = secrets['twitter']['accounts'][account_name]
        self._api_client = twitter.Api(consumer_key = self.__app['consumer_key'],
                                       consumer_secret = self.__app['consumer_secret'],
                                       access_token_key = self.__account['token_key'],
                                       access_token_secret = self.__account['token_secret'])
        self.user = self._api_client.GetUser(user_id=self.__account['user_id'])
        self.db = TweetDatastore(account_name)
        self.__backfill_db()

    def __backfill_db(self):
        try:
            tweets = self._api_client.GetUserTimeline(user_id=self.__account['user_id'], count = 200)
            self.db.store(tweets)
        except Exception, e:
            pass

    def generate_text(self, in_reply_to=None):
        """
        extend this method with your generator
        """
        return "override this method in the TwitterBot class to generate your text"

    def tweet(self, text, in_reply_to=None):
        """
        posts an update as the authenticated user

        Args:
            in_reply_to: a Twitter.Status object
        """

        if in_reply_to == None:
            tweet = self._api_client.PostUpdate(text)
        else:
            assert(type(in_reply_to) == twitter.status.Status)
            self.db.store(in_reply_to)
            reply_text = '@%s %s' % (in_reply_to.user.screen_name, text)
            reply_text = reply_text.replace('@%s ' % self.__account['screen_name'],'')
            tweet = self._api_client.PostUpdate(reply_text, in_reply_to_status_id = str(in_reply_to.id))

        self.db.store(tweet)
        return tweet
        
    def has_replied(self, tweet):
        sql = """
        SELECT count(status_id) from tweets
        where in_reply_to_status_id = ?
        """ 
        curs = self.db._TweetDatastore__conn.cursor()
{'fraction_non_alphanumeric': 0.10888693356797184, 'fraction_numerical': 0.0013198416190057193, 'mean_word_length': 2.2925416364952933, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6285845', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1317, 'n_words': 256}