#NEWLINE# def main( ) : #NEWLINE# #INDENT# args = parser . parse_args ( ) #NEWLINE# searchTerm = ( 'kittens' if args . kittens else 'cats' ) #NEWLINE# cat_count = ( args . count if ( args . count < 10 ) else 10 ) #NEWLINE# if args . breed : #NEWLINE# #INDENT# searchTerm += '%20{0}' . format ( args . breed ) #NEWLINE# #UNINDENT# service = discovery . build ( 'customsearch' , 'v1' , developerKey = os . environ . get ( 'GOOGLE_DEV_KEY' ) ) #NEWLINE# cse = service . cse ( ) #NEWLINE# search_kwrds = { #NEWLINE# #INDENT# 'q' : searchTerm , #NEWLINE# 'cx' : os . environ . get ( 'GOOGLE_CX' ) , #NEWLINE# 'fileType' : 'jpg' , #NEWLINE# 'imgType' : 'photo' , #NEWLINE# 'num' : cat_count , #NEWLINE# 'searchType' : 'image' , #NEWLINE# #UNINDENT# } #NEWLINE# request = cse . list ( ** search_kwrds ) #NEWLINE# response = request . execute ( ) #NEWLINE# for item in response [ 'items' ] : #NEWLINE# #INDENT# url = item . get ( 'link' ) #NEWLINE# filename = url . split ( '/' ) [ ( - 1 ) ] #NEWLINE# myopener . retrieve ( url , filename )