本文整理匯總了Python中amazonproduct.api.API.browse_node_lookup方法的典型用法代碼示例。如果您正苦於以下問題:Python API.browse_node_lookup方法的具體用法?Python API.browse_node_lookup怎麽用?Python API.browse_node_lookup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類amazonproduct.api.API
的用法示例。
在下文中一共展示了API.browse_node_lookup方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: BrowseNodeExplorer
# 需要導入模塊: from amazonproduct.api import API [as 別名]
# 或者: from amazonproduct.api.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)
#.........這裏部分代碼省略.........