本文整理汇总了Python中product.Product.insert_json方法的典型用法代码示例。如果您正苦于以下问题:Python Product.insert_json方法的具体用法?Python Product.insert_json怎么用?Python Product.insert_json使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类product.Product
的用法示例。
在下文中一共展示了Product.insert_json方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fetch
# 需要导入模块: from product import Product [as 别名]
# 或者: from product.Product import insert_json [as 别名]
def fetch(self, handle, id):
from product import Product
from artist import Artist
jtrack = qobuz.api.get_track(id)
if not jtrack:
print "Cannot fetch data"
return False
print pprint.pformat(jtrack)
where = {}
if 'album' in jtrack:
P = Product()
album = P.get(handle, jtrack['album']['id'])
if not album:
P.insert_json(handle, jtrack['album'])
for field in self.fields_name.keys():
f = self.fields_name[field]
if not f['jsonmap']: continue
value = self.get_property(jtrack, f['jsonmap'])
if not value: continue
where[field] = value
if 'interpreter' in jtrack:
I = Artist()
interpreter = I.get(handle, jtrack['interpreter'])
if not interpreter:
I.insert(handle, jtrack['interpreter'])
if 'performer' in jtrack:
I = Artist()
interpreter = I.get(handle, jtrack['performer'])
if not interpreter:
I.insert(handle, jtrack['performer'])
artist = None
artist_type = ('artist', 'interpreter', 'composer', 'performer')
for a in artist_type:
if a in jtrack and jtrack[a]['name'] and jtrack[a]['name'] != 'None':
artist = jtrack[a]
break
self.insert(handle, where)
return False
示例2: insert_json
# 需要导入模块: from product import Product [as 别名]
# 或者: from product.Product import insert_json [as 别名]
def insert_json(self, handle, json):
print "JSON: " + pprint.pformat(json)
from product import Product
from artist import Artist
where = {}
subtype = ['album', 'interpreter', 'composer', 'performer']
for type in subtype:
if type in json:
db = None
if type == 'album': db = Product()
elif type in ['interpreter', 'composer', 'performer']:
db = Artist()
if not 'id' in json[type] or not json[type]['id']: continue
if not db.get(handle, int(json[type]['id'])):
db.insert_json(handle, json[type])
for field in self.fields_name.keys():
f = self.fields_name[field]
if not f['jsonmap']: continue
value = self.get_property(json, f['jsonmap'])
if not value: continue
where[field] = value
print "Where %s" % (pprint.pformat(where))
return self.insert(handle, where)