Example #1
0
def tweet(status, **credentials):
  if not credentials:
    # shortcut for no-credentials case
    credentials = local.config_get('twitter')
    if not credentials:
      return
  update_url = "%s/statuses/update.json" % __TWITTER_API__
  fetch_url = signed_url(url=update_url, method='POST', status=status, **credentials)
  response = urlfetch.fetch(fetch_url, method=urlfetch.POST)
  try:
    content = json.read(response.content)
    return content.get('id')
  except json.ReadException:
    pass
Example #2
0
def shorten(longUrl, login=None, apiKey=None):
  if login is None and apiKey is None:
    # shortcut for no-credentials case
    credentials = local.config_get('bitly')
    return shorten(longUrl, **credentials)
  payload = urlencode(dict(
    longUrl=longUrl,
    login=login,
    apiKey=apiKey,
    version="2.0.1",
    format="json"))
  url = "http://api.bit.ly/shorten"
  response = urlfetch.fetch("%s?%s" % (url, payload))
  if response:
    try:
      data = json.read(response.content)
      if data['errorCode'] == 0:
        return data['results'][longUrl]['shortUrl']
    except json.ReadException:
      pass
Example #3
0
def site_name():
  try:
    return 'Emend: %s' % local.config_get('tagline')
  except KeyError:
    return 'Emend'
Example #4
0
 def twitter_credentials(self):
   """Returns Emend's twitter credentials, if any."""
   try:
     return local.config_get('twitter')
   except KeyError, e:
     logging.warn('missing credentials: %s', e)