-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimages.py
36 lines (27 loc) · 968 Bytes
/
images.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
from .data import DataDict
from .wget import Downloadable
class Image(Downloadable):
def __init__(self, opus_id, path, img):
Downloadable.__init__(self, path + img)
self.opus_id = opus_id
self.path = path
self.img = img
def __repr__(self):
return 'OPUS API Image object: {}'.format(self.opus_id)
def __str__(self):
return self.opus_id
class Images(DataDict):
def __init__(self, json, size):
DataDict.__init__(self)
self._json = json
self.size = size
for img in json['data']:
el = Image(img['opus_id'], img['path'], img['img'])
self._data[str(el)] = el
def __repr__(self):
return 'OPUS API Image objects (with {} {} images):\n'.format(len(self), self.size) + \
'\n'.join(' - {}'.format(key) for key, _ in self.items())
@property
def order(self):
return self._json['order']