本文整理汇总了Python中model.Node.add_tag方法的典型用法代码示例。如果您正苦于以下问题:Python Node.add_tag方法的具体用法?Python Node.add_tag怎么用?Python Node.add_tag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.Node
的用法示例。
在下文中一共展示了Node.add_tag方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Cruncher
# 需要导入模块: from model import Node [as 别名]
# 或者: from model.Node import add_tag [as 别名]
class Cruncher(object):
"""XML Cruncher!!!"""
current_node = None
nodes = []
def start(self, tag, attrib):
"""parser enters tag"""
if tag == "node":
self.current_node = Node(attrib["id"], attrib["lat"], attrib["lon"])
elif tag == "tag" and self.current_node:
self.current_node.add_tag(attrib["k"], attrib["v"])
def end(self, tag):
"""parses end tags"""
if tag == "node" and self.current_node:
if self.current_node.tags.has_key("name"):
self.nodes.append(self.current_node)
self.current_node = None
def close(self):
"""parser closes"""
nodes, self.nodes = self.nodes, []
return nodes
示例2: MongoLoader
# 需要导入模块: from model import Node [as 别名]
# 或者: from model.Node import add_tag [as 别名]
class MongoLoader(object):
"""Parses xml nodes and inserts appropriate ones to db"""
def __init__(self, collection_name, named_only, tag_names):
"""C'tor sets tag wich we'll count"""
self._named_only = named_only
if isinstance(tag_names, list):
self._tag_names = set(tag_names)
else:
self._tag_names = set([tag_names])
self._current_node = None
self._count = 0
conn = Connection('localhost', 27017)
db = conn['openstreet']
self._ca = db[collection_name]
def start(self, tag, attrib):
"""parser enters tag"""
if tag == "node":
# Start node writing
self._current_node = Node( float(attrib["lat"]),
float(attrib["lon"]),
id = int(attrib["id"]) )
elif tag == "tag" and self._current_node:
# Add tag to node
self._current_node.add_tag(attrib["k"], attrib["v"])
def end(self, tag):
"""parser reached end of tag"""
if tag == "node" and self._current_node:
# tags_set = set(self._current_node.tags)
# if not self._named_only or "name" in tags_set:
# if len(tags_set & self._tag_names):
# self._save_node()
if "name" in self._current_node.tags:
self._save_node()
self._current_node = None
def close(self):
"""parser closes"""
count, self._count = self._count, 0
return count
def _save_node(self):
"""Save current_node to list"""
self._ca.insert(self._current_node)
self._count += 1
示例3: MongoLoader
# 需要导入模块: from model import Node [as 别名]
# 或者: from model.Node import add_tag [as 别名]
class MongoLoader(object):
"""Parses xml nodes and inserts appropriate ones to db"""
def __init__(self, collection_name):
"""C'tor sets tag wich we'll count"""
from pymongo import Connection
conn = Connection('localhost', 27017)
db = conn['openstreetmaps']
self._ca = db[collection_name]
self._current_node = None
self._count = 0
def start(self, tag, attrib):
"""parser enters tag"""
from model import Node
if tag == "node":
# Start node writing
self._current_node = Node( float(attrib["lat"]),
float(attrib["lon"]),
id = int(attrib["id"]) )
elif tag == "tag" and self._current_node:
# Add tag to node
self._current_node.add_tag(attrib["k"], attrib["v"])
def end(self, tag):
"""parser reached end of tag"""
if tag == "node" and self._current_node:
self.__save_node()
self._current_node = None
def close(self):
"""parser closes"""
count, self._count = self._count, 0
return count
def __save_node(self):
"""Save current_node to list"""
self._ca.insert(self._current_node)
self._count += 1
示例4: JSONLoader
# 需要导入模块: from model import Node [as 别名]
# 或者: from model.Node import add_tag [as 别名]
class JSONLoader(object):
"""Parses xml nodes and inserts appropriate ones to db"""
def __init__(self):
"""C'tor sets tag wich we'll count"""
from json import JSONEncoder
self._encoder = JSONEncoder()
self._current_node = None
self._count = 0
def start(self, tag, attrib):
"""parser enters tag"""
from model import Node
if tag == "node":
# Start node writing
self._current_node = Node( float(attrib["lat"]),
float(attrib["lon"]),
id = int(attrib["id"]) )
elif tag == "tag" and self._current_node:
# Add tag to node
self._current_node.add_tag(attrib["k"], attrib["v"])
def end(self, tag):
"""parser reached end of tag"""
if tag == "node" and self._current_node:
self.__save_node()
self._current_node = None
def close(self):
"""parser closes"""
count, self._count = self._count, 0
return count
def __save_node(self):
"""Save current_node to list"""
print(self._encoder.encode(self._current_node))
self._count += 1