示例#1
0
def find_twitter_friends(request, template_name="profiles/find_friends.html"):
  """
  Very simple Twitter friend finder. Not a very robust method, 
  but it'll work until Twitter gets oAuth going.
  """
  if request.GET.__contains__('username'):
    service_username = request.GET['username']
    service_user_info_url = "http://twitter.com/users/show/%s.xml" % service_username
    service_user_info = getxml(service_user_info_url)
    try:
      friend_count = int(service_user_info.find('friends_count').text)
    except AttributeError:
      raise Http404("No friend count. This probably means our Twitter API limit has been reached for this hour.")
    if friend_count:
      page_range = range(1, friend_count/100+2)
      friend_screennames = []
      for page in page_range:
        service_friends_url = "http://twitter.com/statuses/friends/%s.json?page=%s" % (service_username, page)
        service_friends = getjson(service_friends_url)
        service_friends_screennames = friend_screennames.extend(friend['screen_name'] for friend in service_friends)
      users = User.objects.filter(username__in=friend_screennames)
      return render_to_response(template_name, RequestContext(request, { 'friend_list': users, }))
  else:
    return render_to_response(template_name, RequestContext(request, { }))
  
    
示例#2
0
 def __call__(self, **params):
     # Enforce Yahoo's "no calls quicker than every 1 second" rule
     delta = time.time() - DeliciousClient.lastcall
     if delta < 2:
         time.sleep(2 - delta)
     DeliciousClient.lastcall = time.time()
     url = ("https://api.del.icio.us/%s?" % self.method) + urllib.urlencode(params)
     return importers.getxml(url, username=self.username, password=self.password)
示例#3
0
 def __call__(self, **params):
     params['api_key'] = self.api_key
     url = ("http://ma.gnolia.com/api/rest/1/%s/?" % (self.method)) + urllib.urlencode(params)
     return importers.getxml(url)
示例#4
0
 def __call__(self):
     url = "http://beermapping.com/webservice/locstate/%s/%s/?" % (self.api_key, self.state)
     return importers.getxml(url)