#!/usr/bin/env python # # language_bookmarks.py - v0.1 # # Copyright (c) 2008 - Rich Burridge - Sun Microsystems Inc. # All Rights Reserved. # # Script to automatically generate links for a variety of topics, # for a variety of the currently popular programming languages. # These are written to standard out in HTML format. # # Google AJAX Search API usage based on the example from the DCortesi . blog: # http://dcortesi.com/2008/05/28/google-ajax-search-api-example-python-code/ # # Uses simplejson, a simple, fast, extensible JavaScript Object Notation # (JSON) encoder/decoder for Python: # http://pypi.python.org/pypi/simplejson # # Usage: # $ python language_bookmarks.py > language_bookmarks.html # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published # by the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. import urllib import simplejson # List of languages to check. # languages = [ 'Ada', 'Asp', 'Awk', 'Basic', 'Boo', 'C', 'C++', 'C#', 'Caml','Cobol', 'Eiffel', 'Erlang', 'F#', 'Forth', 'Fortran', 'Haskell', 'Java', 'JavaScript', 'Lisp', 'Lua', 'Oberon', 'OCaml', 'Oz', 'Pascal', 'Perl', 'PHP', 'Prolog', 'Python', 'Rebol', 'Rexx', 'Ruby', 'Scala', 'Scheme', 'Scriptol', 'Smalltalk', 'Tcl' ] # List of topics to check for each language. # topics = [ 'Home Page', 'Reference', 'FAQ', 'Tutorial', 'HOWTO' ] # The Google AJAX search URL. # search_URL = 'http://ajax.googleapis.com/ajax/services/search/web?v=1.0&%s' def do_search(query_string): """Perform a Google AJAX search. Return the first result. Arguments: - query_string: the search string. """ query = urllib.urlencode({ 'q' : query_string }) url = search_URL % (query) search_results = urllib.urlopen(url) json = simplejson.loads(search_results.read()) results = json['responseData']['results'] return results[0]['url'] def write_preamble(): """Write out the initial HTML commands for the page.""" print "" print "
" print "%s: " % language for topic in topics: query_language(language, topic) print write_postamble() # ChangeLog # 1st Sep 2008 - 0.1 - richb - Initial version.