<commit_before>import os, sys

from twisted.application.service import Service
from twisted.internet.defer import Deferred, inlineCallbacks, returnValue

from jersey import log

from twittytwister.twitter import TwitterFeed

from vtwt.util import recodeText



class VtwtService(Service):

    def __init__(self, user, password):
        self._twt = self._buildTwitterClient(user, password)
        self._mostRecentId = None


    def _buildTwitterClient(self, user, password):
        return TwitterFeed(user, password)


    @inlineCallbacks
    def getTimelineUpdates(self, params={}):
        """Get recent updates from the user's home timeline.
        """
        if self._mostRecentId:
            params.setdefault("since_id", self._mostRecentId)

        messages = []
        yield self._twt.home_timeline(lambda m: messages.insert(0, m), params)
        for msg in messages:
            msg.text = recodeText(msg.text)
            self._mostRecentId = msg.id

        returnValue(messages)


    def tweet(self, text):
        return self._twt.update(text)


    @inlineCallbacks
    def follow(self, user):
        users = []
        yield self._twt.follow_user(user, users.append)
        returnValue(users[0])


    @inlineCallbacks
    def unfollow(self, user):
        users = []
        yield self._twt.unfollow_user(user, users.append)
        returnValue(users[0])


    def block(self, user):
        return self._twt.block(user)


    def unblock(self, user):
        return self._twt.unblock(user)<commit_msg>Add user timelines.  Remove internal state tracking mostRecentId (its done in the watch command).<commit_after>import os, sys

from twisted.application.service import Service
from twisted.internet.defer import Deferred, inlineCallbacks, returnValue

from jersey import log

from twittytwister.twitter import TwitterFeed

from vtwt.util import recodeText



class VtwtService(Service):

    name = "vtwt"

    def __init__(self, user, password):
        self._twt = self._buildTwitterClient(user, password)


    def _buildTwitterClient(self, user, password):
        return TwitterFeed(user, password)


    @inlineCallbacks
    def getHomeTimeline(self, params={}):
        """Get recent updates from a user's timeline.
        """
        log.trace("Getting home timeline.")

        messages = []
        yield self._twt.home_timeline(lambda m: messages.insert(0, m), params)

        for msg in messages:
            msg.text = self._recodeText(msg.text)

        returnValue(messages)


    @inlineCallbacks
    def getUserTimeline(self, user, params={}):
        """Get recent updates from the user's home timeline.
        """
        log.trace("Getting timeline for {0}".format(user))

        messages = []
        yield self._twt.user_timeline(lambda m: messages.insert(0, m),
                user, params)

        for msg in messages:
            msg.text = self._recodeText(msg.text)

        returnValue(messages)


    def _recodeText(self, text):
        """Recode HTML entities refs; e.g. '&amp;' to '&'
        
        Work around buggy Twitter clients that mangle retweets such that
        &amp;lt;3 recodes to <3 (instead of &lt;3).
        """
        return recodeText(recodeText(text))


    def tweet(self, text):
        return self._twt.update(text)


    @inlineCallbacks
    def follow(self, user):
        users = []
        yield self._twt.follow_user(user, users.append)
        returnValue(users[0])


    @inlineCallbacks
    def unfollow(self, user):
        users = []
        yield self._twt.unfollow_user(user, users.append)
        returnValue(users[0])


    def block(self, user):
        return self._twt.block(user)


    def unblock(self, user):
        return self._twt.unblock(user)
{'fraction_non_alphanumeric': 0.09920212765957447, 'fraction_numerical': 0.002925531914893617, 'mean_word_length': 2.665692007797271, 'pattern_counts': {'":': 0, '<': 4, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7604962', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1074, 'n_words': 285}