pycrossword  0.4
Pure-Python implementation of a crossword puzzle generator and editor
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
pycross.utils.onlineservices.GoogleSearch Class Reference

Google search interface. More...

Public Member Functions

def __init__ (self, settings, search_phrase='', exact_match=False, file_types=None, lang=None, country=None, interface_lang=None, link_site=None, related_site=None, in_site=None, nresults=-1, safe_search=False, timeout=5000)
 
def init (self, search_phrase='', exact_match=False, file_types=None, lang=None, country=None, interface_lang=None, link_site=None, related_site=None, in_site=None, nresults=-1, safe_search=False, timeout=5000)
 Initializes members with params passed to constructor. More...
 
def encode_search (self)
 Constructs a search query string from the member parameters. More...
 
def decode_result (self, txt)
 Decodes an URL-encoded string (e.g. More...
 
def search (self, method='json')
 Returns full Google search results for GoogleSearch::search_phrase. More...
 
def search_lite (self)
 Retrieves search results for GoogleSearch::search_phrase as a list. More...
 

Static Public Member Functions

def get_interface_languages ()
 
def get_document_languages ()
 
def get_document_countries ()
 
def get_user_countries ()
 

Public Attributes

 settings
 dict stored pointer to app global settings More...
 
 search_phrase
 str search phrase to search in Google More...
 
 exact_match
 bool whether to treat the search phrase verbatim More...
 
 file_types
 iterable file types (extensions) to include in search results More...
 
 lang
 iterable search documents restricted only to these languages More...
 
 country
 iterable only return documents found in these countries More...
 
 interface_lang
 iterable search using only selected interface languages More...
 
 link_site
 str link site URL More...
 
 related_site
 str related (parent) site URL More...
 
 in_site
 str URL of a website to search in More...
 
 nresults
 int limit number of returned results (-1 = no limit) More...
 
 safe_search
 bool turn on Google safe search filter More...
 
 timeout
 int network request timeout (in msec.) More...
 

Detailed Description

Google search interface.

Executes search with custom parameters using Google's JSON (REST) API and returns the results in a Python dictionary.

Constructor & Destructor Documentation

◆ __init__()

def pycross.utils.onlineservices.GoogleSearch.__init__ (   self,
  settings,
  search_phrase = '',
  exact_match = False,
  file_types = None,
  lang = None,
  country = None,
  interface_lang = None,
  link_site = None,
  related_site = None,
  in_site = None,
  nresults = -1,
  safe_search = False,
  timeout = 5000 
)
Parameters
settingsdict pointer to the app settings dictionary (pycross::guisettings::CWSettings::settings)
search_phrasestr search phrase to search in Google
exact_matchbool whether to treat the search phrase verbatim (True) or fuzzily (False)
file_typesiterable | None if not None, Google will present results (documents) only having the indicated file types (extensions), e.g. ‘['pdf’, 'doc', 'docx'] @param langiterable|None` search documents restricted only to these languages, as listed by GoogleSearch::get_document_languages()
countryiterable | None only return documents found in these countries, as listed by GoogleSearch::get_document_countries()
interface_langiterable | None search using only selected interface languages, as listed by GoogleSearch::get_interface_languages()
link_sitestr | None link site URL
related_sitestr | None related (parent) site URL
in_sitestr | None URL of a website to search in
nresultsint limit number of returned results (-1 = no limit)
safe_searchbool turn on Google safe search filter
timeoutint network request timeout (in msec.)

Member Function Documentation

◆ decode_result()

def pycross.utils.onlineservices.GoogleSearch.decode_result (   self,
  txt 
)

Decodes an URL-encoded string (e.g.

converts '%20' to spaces etc.)

Parameters
textstr URL-encoded text
Returns
str decoded text

◆ encode_search()

def pycross.utils.onlineservices.GoogleSearch.encode_search (   self)

Constructs a search query string from the member parameters.

Returns
str parametrized search URL

◆ get_document_countries()

def pycross.utils.onlineservices.GoogleSearch.get_document_countries ( )
static
Returns
list list of Google result countries

◆ get_document_languages()

def pycross.utils.onlineservices.GoogleSearch.get_document_languages ( )
static
Returns
list list of Google document languages

◆ get_interface_languages()

def pycross.utils.onlineservices.GoogleSearch.get_interface_languages ( )
static
Returns
list list of Google interface languages

◆ get_user_countries()

def pycross.utils.onlineservices.GoogleSearch.get_user_countries ( )
static
Returns
list list of Google search countries

◆ init()

def pycross.utils.onlineservices.GoogleSearch.init (   self,
  search_phrase = '',
  exact_match = False,
  file_types = None,
  lang = None,
  country = None,
  interface_lang = None,
  link_site = None,
  related_site = None,
  in_site = None,
  nresults = -1,
  safe_search = False,
  timeout = 5000 
)

Initializes members with params passed to constructor.

Parameters
search_phrasestr search phrase to search in Google
exact_matchbool whether to treat the search phrase verbatim (True) or fuzzily (False)
file_typesiterable | None if not None, Google will present results (documents) only having the indicated file types (extensions), e.g. ‘['pdf’, 'doc', 'docx'] @param langiterable|None` search documents restricted only to these languages, as listed by GoogleSearch::get_document_languages()
countryiterable | None only return documents found in these countries, as listed by GoogleSearch::get_document_countries()
interface_langiterable | None search using only selected interface languages, as listed by GoogleSearch::get_interface_languages()
link_sitestr | None link site URL
related_sitestr | None related (parent) site URL
in_sitestr | None URL of a website to search in
nresultsint limit number of returned results (-1 = no limit)
safe_searchbool turn on Google safe search filter
timeoutint network request timeout (in msec.)

◆ search()

def pycross.utils.onlineservices.GoogleSearch.search (   self,
  method = 'json' 
)

Returns full Google search results for GoogleSearch::search_phrase.

Parameters
methodstr parsing method to parse the results
Returns
dict | str search results; if method == 'json' (default), the results are parsed as a JSON-formatted string into a Python dictionary object. Otherwise, the raw result string is returned.

◆ search_lite()

def pycross.utils.onlineservices.GoogleSearch.search_lite (   self)

Retrieves search results for GoogleSearch::search_phrase as a list.

Returns
list search results as a list of dict objects:
[{'url': 'URL', 'title': 'TITLE', 'summary': 'SNIPPET'}, ...]
See also
https://developers.google.com/custom-search/v1/cse/list
Retrieves search results for 'self.search_phrase' as a list in the following format:
[{'url': 'URL', 'title': 'TITLE', 'summary': 'SNIPPET'}, ...]
See https://developers.google.com/custom-search/v1/cse/list

Member Data Documentation

◆ country

pycross.utils.onlineservices.GoogleSearch.country

iterable only return documents found in these countries

◆ exact_match

pycross.utils.onlineservices.GoogleSearch.exact_match

bool whether to treat the search phrase verbatim

◆ file_types

pycross.utils.onlineservices.GoogleSearch.file_types

iterable file types (extensions) to include in search results

◆ in_site

pycross.utils.onlineservices.GoogleSearch.in_site

str URL of a website to search in

◆ interface_lang

pycross.utils.onlineservices.GoogleSearch.interface_lang

iterable search using only selected interface languages

◆ lang

pycross.utils.onlineservices.GoogleSearch.lang

iterable search documents restricted only to these languages

◆ link_site

pycross.utils.onlineservices.GoogleSearch.link_site

str link site URL

◆ nresults

pycross.utils.onlineservices.GoogleSearch.nresults

int limit number of returned results (-1 = no limit)

◆ related_site

pycross.utils.onlineservices.GoogleSearch.related_site

str related (parent) site URL

◆ safe_search

pycross.utils.onlineservices.GoogleSearch.safe_search

bool turn on Google safe search filter

◆ search_phrase

pycross.utils.onlineservices.GoogleSearch.search_phrase

str search phrase to search in Google

◆ settings

pycross.utils.onlineservices.GoogleSearch.settings

dict stored pointer to app global settings

◆ timeout

pycross.utils.onlineservices.GoogleSearch.timeout

int network request timeout (in msec.)


The documentation for this class was generated from the following file: