當前位置: 首頁>>代碼示例>>Python>>正文


Python API.browse_node_lookup方法代碼示例

本文整理匯總了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())
開發者ID:amohan95,項目名稱:quantity-tracker,代碼行數:32,代碼來源:scrape_categories.py

示例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)
#.........這裏部分代碼省略.........
開發者ID:mutaku,項目名稱:python-amazon-product-api,代碼行數:103,代碼來源:node-browser.py


注:本文中的amazonproduct.API.browse_node_lookup方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。