daily pastebin goal
4%
SHARE
TWEET

Yuv

a guest Nov 21st, 2009 219 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from time import sleep
  2. from pprint import pprint
  3. import json
  4. import urllib
  5. import json
  6.  
  7. def showsome(searchfor):
  8.   query = urllib.urlencode({'q': searchfor})
  9.   url = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' % query
  10.   search_response = urllib.urlopen(url)
  11.   search_results = search_response.read()
  12.   results = json.loads(search_results)
  13.   data = results['responseData']
  14.   pprint(data)
  15.   #print 'Total results: %s' % data['cursor']['estimatedResultCount']
  16.   hits = data['results']
  17.   #print 'Top %d hits:' % len(hits)
  18.   #for h in hits: print ' ', h['url']
  19.   #print 'For more results, see %s' % data['cursor']['moreResultsUrl']
  20.   return data['cursor']['estimatedResultCount']
  21.  
  22. sizes = {}
  23. for i in range(4):
  24.     try:
  25.         query = 'a' * i
  26.         sizes[query] = int(showsome(query))
  27.         sleep(1)
  28.     except Exception:
  29.         sizes[query] = 'exception'
  30.  
  31.  
  32. def jsonize_xy(items):
  33.     points_list = []
  34.     for point in items:
  35.         x, y = point
  36.         d = {
  37.                 "x": x,
  38.                 "y": y,
  39.             }
  40.         points_list.append(d)
  41.    
  42.     return json.dumps(points_list)
  43.  
  44. points = [ ((len(key), val)) for key,val in sizes.items() if val != 'exception' ]
  45. points.sort()
  46. open('output.json', 'w').write(jsonize_xy(points))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top