Example #1
0
def do_system_tweet(event, kbvars):
  """Sends a tweet using the system's account (if any)."""
  system_profile = util.get_site_profile(event.site)
  if not system_profile:
    print 'No system twitter profile, skipping system tweet'
    return

  name = 'Someone'
  user = event.user
  if user:
    name = user.username
    user_profile = util.get_user_profile(user)
    if user_profile:
      name = '@%s' % (user_profile.settings.twitter_name,)
  kbvars['name'] = name

  system_api = util.get_api(system_profile.oauth_token,
      system_profile.oauth_token_secret)

  tweet = None
  if event.kind == 'session_joined':
    tweet = util.DEFAULT_SYSTEM_SESSION_JOINED_TEMPLATE % kbvars
  elif event.kind == 'drink_poured':
    tweet = util.DEFAULT_SYSTEM_DRINK_POURED_TEMPLATE % kbvars

  if tweet:
    tweet = add_hashtag(tweet)
    print 'Sending system tweet: %s' % tweet
    try:
      ret = system_api.update_status(tweet)
    except tweepy.TweepError, e:
      print e
Example #2
0
def do_user_tweet(event, kbvars):
  """Sends a tweet using the user's account (if any)."""
  user = event.user
  if not user:
    return

  profile = util.get_user_profile(user)
  if not profile or not profile.settings.enabled:
    print 'User has disabled Twitter'
    return

  kind = event.kind
  tweet = None
  if kind == 'drink_poured':
    if not profile.settings.post_drink_poured:
      print 'User has disabled drink pour tweets: %s' % event.user
      return
    tweet = util.DEFAULT_USER_SESSION_JOINED_TEMPLATE % kbvars
  elif kind == 'session_joined':
    if not profile.settings.post_session_joined:
      print 'User has disabled session-join tweets: %s' % event.user
      return
    tweet = util.DEFAULT_USER_DRINK_POURED_TEMPLATE % kbvars

  user_api = util.get_api(profile.access_token.oauth_token,
      profile.access_token.oauth_token_secret)

  if tweet:
    tweet = add_hashtag(tweet)
    print 'Sending user tweet: %s' % tweet
    try:
      ret = user_api.update_status(tweet)
    except tweepy.TweepError, e:
      print e