本文整理汇总了Python中amazonproduct.API.browse_node_lookup方法的典型用法代码示例。如果您正苦于以下问题:Python API.browse_node_lookup方法的具体用法?Python API.browse_node_lookup怎么用?Python API.browse_node_lookup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类amazonproduct.API
的用法示例。
在下文中一共展示了API.browse_node_lookup方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: explore_browse_sub_node
# 需要导入模块: from amazonproduct import API [as 别名]
# 或者: from amazonproduct.API import browse_node_lookup [as 别名]
#pprint.pprint(vars(api.browse_node_lookup(281407).BrowseNodes.BrowseNode.Children.BrowseNode))
def explore_browse_sub_node(node, parent_id, root_id, sub_root_id):
SUB_NODES[int(node.BrowseNodeId)] = (str(node.Name), parent_id, root_id, sub_root_id)
if sub_root_id == 0:
sub_root_id = int(node.BrowseNodeId)
print ('Found Sub BrowseNode {0} with id {1} and parent {2}'.format(node.Name, node.BrowseNodeId, parent_id))
try:
for sub_node in node.BrowseNodes.BrowseNode.Children:
browse_node = api.browse_node_lookup(sub_node.BrowseNodeId)
explore_browse_sub_node(sub_node, node.BrowseNodeId, root_id, sub_root_id)
except AttributeError, e:
print('Reached leaf node')
for id, name in BASE_NODES.items():
browse_node_lookup = api.browse_node_lookup(id)
BASE_NODES[int(browse_node_lookup.BrowseNodes.BrowseNode.BrowseNodeId)] = str(browse_node_lookup.BrowseNodes.BrowseNode.Name)
print ('Found Base BrowseNode {0} with id {1}'.format(browse_node_lookup.BrowseNodes.BrowseNode.Name, browse_node_lookup.BrowseNodes.BrowseNode.BrowseNodeId))
for browse_sub_node in browse_node_lookup.BrowseNodes.BrowseNode.Children.BrowseNode:
explore_browse_sub_node(browse_sub_node, id, id, 0)
def sub_node_generator():
for k, v in SUB_NODES.items():
yield (k, v[0], v[1], v[2], v[3])
conn = sqlite3.connect('tracker.db')
print('Connected to tracker.db')
c = conn.cursor()
c.execute('CREATE TABLE IF NOT EXISTS old_categories (id, name, parent, root, sub_root)')
c.executemany('INSERT INTO old_categories (id, name) VALUES (?,?)', BASE_NODES.items())
c.executemany('INSERT INTO old_categories (id, name, parent, root, sub_root) VALUES (?, ?, ?, ?, ?)', sub_node_generator())
示例2: BrowseNodeExplorer
# 需要导入模块: from amazonproduct import API [as 别名]
# 或者: from amazonproduct.API import browse_node_lookup [as 别名]
class BrowseNodeExplorer (gtk.Window):
"""
Gtk explorer for Amazon BrowseNodes.
"""
def on_delete(self, widget, event, data=None):
# closes the window and quits.
gtk.main_quit()
return False
def on_tree_click(self, widget, event, data=None):
# if double click
if event.type == gtk.gdk._2BUTTON_PRESS:
# get data from highlighted selection
treeselection = self.treeview.get_selection()
model, iter = treeselection.get_selected()
name_of_data = self.treestore.get_value(iter, 0)
# and fetch selected node
self.fetch_nodes(name_of_data)
def __init__(self, locale='de'):
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
self.set_title("BrowseNode Explorer")
self.set_size_request(400, 200)
self.connect("delete_event", self.on_delete)
self.locale = locale
self.api = API(AWS_KEY, SECRET_KEY, self.locale)
# create a TreeStore with one string column to use as the model
self.treestore = gtk.TreeStore(int, str)
# create the TreeView using treestore
self.treeview = gtk.TreeView(self.treestore)
# add column id
renderer = gtk.CellRendererText()
column = gtk.TreeViewColumn('id', renderer, text=0)
self.treeview.append_column(column)
# add column name
renderer = gtk.CellRendererText()
column = gtk.TreeViewColumn('name', renderer, text=1)
column.set_sort_column_id(1) # Allow sorting on the column
self.treeview.append_column(column)
# make it clickable
self.treeview.add_events(gtk.gdk.BUTTON_PRESS_MASK)
self.treeview.connect('button_press_event', self.on_tree_click)
scrolled = gtk.ScrolledWindow()
scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
scrolled.add(self.treeview)
self.add(scrolled)
self.show_all()
# populate with root nodes
# but avoid duplicated node ids
node_ids = set(NODE_IDS[self.locale].values())
for name, id in NODE_IDS[self.locale].items():
if id in node_ids:
self.treestore.append(None, [id, name])
node_ids.remove(id)
def _find_row(self, node_id):
def match_func(row, data):
# data is a tuple containing column number, key
column, key = data
return row[column] == key
def search(rows, func, data):
if not rows: return None
for row in rows:
if func(row, data):
return row
result = search(row.iterchildren(), func, data)
if result: return result
return None
return search(self.treestore, match_func, (0, node_id))
def fetch_nodes(self, node_id):
"""
Fetches a BrowseNode from Amazon.
"""
# fetch matching row from treestore
row = self._find_row(node_id)
# fetch Amazon data
node = self.api.browse_node_lookup(node_id).BrowseNodes.BrowseNode
id = node.BrowseNodeId.pyval
name = node.Name.pyval
is_root = hasattr(node, 'IsCategoryRoot') and node.IsCategoryRoot.pyval == 1
#~ from lxml import etree
#~ print etree.tostring(node, pretty_print=True)
#.........这里部分代码省略.........