7 from .image
import image
8 from .video
import video
26 return self.
info[
'totalHits']
38 if 'videos' in self.
params.host:
47 def _inCache(self, index):
48 return len(self.
cache) > index
and self.
cache[index] !=
None 54 def _cacheInsert(self, index, data):
56 for i
in range(len(self.
cache) - 1, index - 1):
57 self.
cache.insert(i,
None)
59 self.
cache.insert(index, data)
64 def _getPage(self, page):
65 uri =
"{host}?key={api}&q={query}&lang={lang}&orientation={orient}&per_page={per}&page={page}&order={order}&safesearch={safe}&min_width={width}&min_height={height}&editors_choice={editors}&category={cat}&colors={colors}&image_type={image_type}".format(
67 query = urllib.parse.quote(self.
params.query, safe=
''),
70 orient = self.
params.orientation,
74 safe = self.
params.safeSearch,
75 width = self.
params.minWidth,
76 height = self.
params.minHeight,
77 editors = self.
params.editorsChoice,
78 cat = self.
params.category,
79 colors = self.
params.colors,
80 image_type = self.
params.image_type
85 if (r.status_code != 200):
86 raise ValueError(
'Pixabay return status code != 200 for uri', uri,
'Invalid parameters?')
92 self.
info[
'total'] = data[
'total']
93 self.
info[
'totalHits'] = data[
'totalHits']
96 for i
in range(len(data[
'hits'])):
102 def _addToChache(self, index):
103 page = index // self.
params.perPage
def __init__(self, params)
Init query on API params params of query instance of class params.
def _cacheInsert(self, index, data)
Insert image in cache.
def __getitem__(self, index)
Get item on index from result index index of item return image object of item.
def _inCache(self, index)
Check if is image with index in chace.
def __len__(self)
Get lenght of fonded images.
def _addToChache(self, index)
Download image with index to cache.
def _getPage(self, page)
Download page from API and save to cache.