65 lines
1.5 KiB
Python
65 lines
1.5 KiB
Python
|
# standard imports
|
||
|
import os
|
||
|
import json
|
||
|
from urllib.request import urlopen
|
||
|
#import binascii.error
|
||
|
|
||
|
# external imports
|
||
|
from jsonschema import validate as json_validate
|
||
|
|
||
|
# local imports
|
||
|
from .error import InvalidCertificationError
|
||
|
|
||
|
|
||
|
script_dir = os.path.realpath(os.path.dirname(__file__))
|
||
|
data_dir = os.path.join(script_dir, 'data')
|
||
|
__f = open(os.path.join(data_dir, 'cic.json'), 'r')
|
||
|
schema = __f.read()
|
||
|
__f.close()
|
||
|
|
||
|
|
||
|
class NFT:
|
||
|
|
||
|
def __init__(self):
|
||
|
self.name = None
|
||
|
self.description = None
|
||
|
self.image = None
|
||
|
self.attachments = []
|
||
|
self.attributes = {}
|
||
|
self.certifications = []
|
||
|
|
||
|
|
||
|
@classmethod
|
||
|
def from_path(cls, path):
|
||
|
f = open(path, 'r')
|
||
|
o = json.load(f)
|
||
|
f.close()
|
||
|
json_validate(schema, o)
|
||
|
c = cls()
|
||
|
c.name = o['name']
|
||
|
c.description = o['description']
|
||
|
c.image = o['image']
|
||
|
c.attributes = o['attributes']
|
||
|
c.attachments = o['attachments']
|
||
|
c.certifications = o['certifications']
|
||
|
|
||
|
|
||
|
def __decode_certification(self):
|
||
|
for v in self.certiciations:
|
||
|
try:
|
||
|
r = self.__try_data_uri(v)
|
||
|
except:
|
||
|
pass
|
||
|
|
||
|
|
||
|
def __try_data_uri(self, data):
|
||
|
r = None
|
||
|
try:
|
||
|
r = urllib.request.urlopen(data)
|
||
|
#except binascii.error:
|
||
|
# raise InvalidCertificationError()
|
||
|
except Exception:
|
||
|
raise InvalidCertificationError()
|
||
|
#return None
|
||
|
return r
|