Exemple #1
0
class ReplyService(StoppableProcess):
    _twitter = None
    _storage = None
    _config = None
    _db_path = None

    def __init__(self, config, db_path, *args, **kwargs):
        self._config = config
        self._db_path = db_path
        super(ReplyService, self).__init__(*args, **kwargs)

    def _setup(self):
        self._twitter = Twitter(**self._config)
        self._storage = Storage(db_path=self._db_path)

    def _teardown(self):
        msg = self.name + " shutting down"
        if self.exit.is_set():
            msg += ", via signal"
        _logger.info(msg)

    def _ping(self):
        reply = self._storage.get_first_message()
        if reply:
            self._twitter.post_reply(
                reply['tweet_id'],
                reply['username'],
                reply['status']
            )
            self._storage.remove_message(reply)
class TwitterTestCase(unittest.TestCase):
    
    def setUp(self):
        self.twitter = Twitter(TwitterRepositoryMock())

    def test_lists_for_user(self):
        slugs = self.twitter.get_lists("bob")
        self.assertTrue(("53257043", "software-development") in slugs)

    def test_members_for_owner_screen_name_and_slug(self):
        members = self.twitter.get_members("bob", "software-development")
        self.assertTrue("rebeccaparsons" in members)
        self.assertTrue("mpoppendieck" in members)
        self.assertTrue("postwait" in members)

    def test_member_subscriber_counts(self):
        m, s = self.twitter.get_member_subscriber_counts("bob", "53257043")
        self.assertEqual(25, m)
        self.assertEqual(0, s)
Exemple #3
0
def latest(limit=5):
  """
    Controller interface to feed services. Definitely needs a makeover.
  """

  config = ConfigParser.RawConfigParser()
  config.read('config/auth.cfg') # not ideal, but will fix soon

  tweeter = Twitter({'consumer_secret': config.get('twitter', 'consumer_secret'),
                  'access_token': config.get('twitter', 'access_token'),
                  'consumer_key': config.get('twitter', 'consumer_key'),
                  'access_secret': config.get('twitter', 'access_secret')})

  tweets = tweeter.pull(config.get('twitter', 'shortname'))[0:limit]

  github = GitHub()
  github_events = github.pull('stderr')

  merged = tweets + github_events
  return sorted(merged, key=lambda activity: activity.date, reverse=True)[0:limit]
Exemple #4
0
 def _setup(self):
     self._twitter = Twitter(**self._config)
     self._storage = Storage(db_path=self._db_path)
 def setUp(self):
     self.twitter = Twitter(TwitterRepositoryMock())