示例#1
0
文件: suggest.py 项目: tantalor/emend
def yahoo_suggest(query, **kwargs):
  url = "http://query.yahooapis.com/v1/public/yql"
  yql = "select * from search.spelling where query='%s'" % query.replace("'", "\\'").encode('utf8')
  response = urlfetch.fetch('%s?%s' % (url, urlencode(dict(format='json', q=yql))))
  if response:
    try:
      data = json.read(response.content)
      if data and 'query' in data and data['query']['results']:
        return data['query']['results']['suggestion']
    except json.ReadException:
      pass
示例#2
0
文件: twitter.py 项目: tantalor/emend
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
示例#3
0
文件: bitly.py 项目: tantalor/emend
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