grapplerulrich commited on
Commit
a604031
1 Parent(s): 67c42e7

Limit search results to english

Browse files

Only get required information from search API

Files changed (1) hide show
  1. app.py +4 -2
app.py CHANGED
@@ -28,6 +28,8 @@ def google_search_api_request( query ):
28
  q=query,
29
  cx=cx,
30
  num=5,
 
 
31
  ).execute()
32
 
33
  def search_results( query ):
@@ -40,12 +42,12 @@ def search_results( query ):
40
  results = json.load( results_file )
41
  else:
42
  search_result = google_search_api_request( query )
43
- if ( int( search_result['searchInformation']['totalResults'] ) > 0 ):
44
  results = search_result['items']
45
  with open( file_path, 'w' ) as results_file:
46
  json.dump( results, results_file )
47
 
48
- if ( len( results ) == 0 ) :
49
  raise Exception('No results found.')
50
 
51
  return results
 
28
  q=query,
29
  cx=cx,
30
  num=5,
31
+ lr='lang_en', # lang_de
32
+ fields='items(title,link),searchInformation(totalResults)'
33
  ).execute()
34
 
35
  def search_results( query ):
 
42
  results = json.load( results_file )
43
  else:
44
  search_result = google_search_api_request( query )
45
+ if int( search_result['searchInformation']['totalResults'] ) > 0:
46
  results = search_result['items']
47
  with open( file_path, 'w' ) as results_file:
48
  json.dump( results, results_file )
49
 
50
+ if len( results ) == 0:
51
  raise Exception('No results found.')
52
 
53
  return results