本文整理汇总了Python中store.Store类的典型用法代码示例。如果您正苦于以下问题:Python Store类的具体用法?Python Store怎么用?Python Store使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Store类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AddYoutubeListThread
class AddYoutubeListThread(threading.Thread):
def __init__(self, jukebox, list_url, add_playlist):
threading.Thread.__init__(self)
self.jukebox = jukebox
self.list_url = list_url
self.add_playlist = add_playlist
self.store = Store()
def run(self):
infos = youtube.get_video_infos_from_list(self.list_url)
for info in infos:
print(info)
try:
song = Song()
song.url = info["url"]
song.uid = info["uid"]
song.title = info["title"]
song.img_url = info["image_url"]
song.duration = info['duration']
if song.title and song.duration:
# 데이터가 valid 할 때만 추가
self.store.update_or_new(song)
if self.add_playlist:
self.jukebox.append_song_playlist(song)
except Exception as e:
print(e)
示例2: Entry
class Entry(object):
def __init__(self):
self.store = Store()
def load_image(self, file_path, name):
if not os.path.exists(file_path):
print("Image file not existed")
return -1
image_hash = self.compute_hash(file_path)
if self.store.get_face_by_hash(image_hash):
print("Face already recorded.")
return -2
try:
image = face_recognition.load_image_file(file_path)
face_encoding = face_recognition.face_encodings(image)[0]
except Exception:
print("Failed to recognition face")
return -3
face = {
"name": name,
"hash": image_hash,
"face_encoding": list(face_encoding)
}
self.store.create_face(face)
def compute_hash(self, file_path):
with open(file_path, "r") as f:
data = f.read()
image_md5 = hashlib.md5(data)
return image_md5.hexdigest()
示例3: _jsonstr_other
def _jsonstr_other(self, thing):
'Do our best to make JSON out of a "normal" python object - the final "other" case'
ret = '{'
comma = ''
attrs = thing.__dict__.keys()
attrs.sort()
if Store.has_node(thing) and Store.id(thing) is not None:
ret += '"_id": %s' % str(Store.id(thing))
comma = ','
for attr in attrs:
skip = False
for prefix in self.filterprefixes:
if attr.startswith(prefix):
skip = True
continue
if skip:
continue
value = getattr(thing, attr)
if self.maxJSON > 0 and attr.startswith('JSON_') and len(value) > self.maxJSON:
continue
if self.expandJSON and attr.startswith('JSON_') and value.startswith('{'):
js = pyConfigContext(value)
if js is not None:
value = js
ret += '%s"%s":%s' % (comma, attr, self._jsonstr(value))
comma = ','
ret += '}'
return ret
示例4: main
def main(self):
""" set everything up, then invoke go() """
(options, args) = self.parser.parse_args()
log_level = logging.ERROR
if options.debug:
log_level = logging.DEBUG
elif options.verbose:
log_level = logging.INFO
logging.basicConfig(level=log_level) #, format='%(message)s')
if options.test:
self.store = DummyStore(self.name, self.doc_type)
else:
# load in config file for real run
config = ConfigParser.ConfigParser()
config.readfp(open(options.ini_file))
auth_user = config.get("DEFAULT",'user')
auth_pass = config.get("DEFAULT",'pass')
server = config.get("DEFAULT",'server')
self.store = Store(self.name, self.doc_type, auth_user=auth_user, auth_pass=auth_pass, server=server)
if options.cache:
logging.info("using .cache")
opener = urllib2.build_opener(CacheHandler(".cache"))
urllib2.install_opener(opener)
self.go(options)
示例5: total
def total():
result = ['<head/><body><table><tr><td>Name</td><td>Total</td></tr>']
s = Store('localhost:27017')
for record in s.find('test', 'total', {}):
result.append('<tr><td>%s</td><td>%d</td></tr>' % (record['_id'], record['value']))
result.append('</table><body>')
return '\n'.join(result)
示例6: setup
def setup(dbhost='localhost', dbport=7474, dburl=None, querypath=None):
'''
Program to set up for running our REST server.
We do these things:
- Attach to the database
- Initialize our type objects so things like ClientQuery will work...
- Load the queries into the database from flat files
Not sure if doing this here makes the best sense, but it
works, and currently we're the only one who cares about them
so it seems reasonable -- at the moment ;-)
Also we're most likely to iterate changing on those relating to the
REST server, so fixing them just by restarting the REST server seems
to make a lot of sense (at the moment)
- Remember the set of queries in the 'allqueries' hash table
'''
if dburl is None:
dburl = ('http://%s:%d/db/data/' % (dbhost, dbport))
print >> sys.stderr, 'CREATING Graph("%s")' % dburl
neodb = neo4j.Graph(dburl)
qstore = Store(neodb, None, None)
print GraphNode.classmap
for classname in GraphNode.classmap:
GraphNode.initclasstypeobj(qstore, classname)
print "LOADING TREE!"
if querypath is None:
querypath = "/home/alanr/monitor/src/queries"
queries = ClientQuery.load_tree(qstore, querypath)
for q in queries:
allqueries[q.queryname] = q
qstore.commit()
for q in allqueries:
allqueries[q].bind_store(qstore)
示例7: members_ring_order
def members_ring_order(self):
'Return all the Drones that are members of this ring - in ring order'
## FIXME - There's a cypher query that will return these all in one go
# START Drone=node:Drone(Drone="drone000001")
# MATCH Drone-[:RingNext_The_One_Ring*]->NextDrone
# RETURN NextDrone.designation, NextDrone
if self._insertpoint1 is None:
#print >> sys.stderr, 'NO INSERTPOINT1'
return
if Store.is_abstract(self._insertpoint1):
#print >> sys.stderr, ('YIELDING INSERTPOINT1:', self._insertpoint1
#, type(self._insertpoint1))
yield self._insertpoint1
return
startid = Store.id(self._insertpoint1)
# We can't pre-compile this, but we hopefully we won't use it much...
q = '''START Drone=node(%s)
MATCH p=Drone-[:%s*0..]->NextDrone
WHERE length(p) = 0 or Drone <> NextDrone
RETURN NextDrone''' % (startid, self.ournexttype)
query = neo4j.CypherQuery(CMAdb.cdb.db, q)
for elem in CMAdb.store.load_cypher_nodes(query, Drone):
yield elem
return
示例8: create_player
def create_player(cls, name):
"""
:type name: str
"""
if cls.get_player(name):
raise RuntimeError('Player already exists: %s' % name)
Store.get_store().set_player(Player(name, trueskill.Rating()))
示例9: initStigmergy
def initStigmergy(self):
# default travel time (sec) = length (m) / s(m/sec)
self.long_term_stigmergies = dict([(edge_id, stigmergy.Stigmergy(
netutil.freeFlowTravelTime(self.sumo_net, edge_id))) for edge_id in self.edge_ids])
self.short_term_stigmergies = copy.deepcopy(self.long_term_stigmergies)
# use stored data in long term stigmergy
if self.conf.short_cut != -1:
before_read_time = time.clock()
if self.conf.redis_use:
store = Store(self.conf.redis_host, self.network_file)
else:
store = StoreJSON(self.conf.short_cut_file, self.network_file, 'r')
past_stigmergy_list = store.getLongTermStigmergy(self.conf.weight_of_past_stigmergy, self.conf.short_cut)
for k in past_stigmergy_list:
key = k.replace(store.createFileNameWithoutKey(
self.conf.weight_of_past_stigmergy,
self.conf.short_cut), "")
data_list = [float(travel_time) for travel_time in store.getLongTermStigmergyWithKey(k)]
self.long_term_stigmergies[key].addStigmergy(data_list)
print("read long term stigmergy from redis(" + str(time.clock() - before_read_time) + "sec)")
示例10: domain_list
def domain_list():
store = Store()
domains = store.index()
if request.headers.get("Accept") == "text/plain":
return template("domains.text", domains=domains)
else:
return template("domains.html", domains=domains, url=url, flashed_messages=get_flashed_messages())
示例11: add_mac_ip
def add_mac_ip(self, drone, macaddr, IPlist):
'''We process all the IP addresses that go with a given MAC address (NICNode)
The parameters are expected to be canonical address strings like str(pyNetAddr(...)).
'''
nicnode = self.store.load_or_create(NICNode, domain=drone.domain, macaddr=macaddr)
if not Store.is_abstract(nicnode):
# This NIC already existed - let's see what IPs it already owned
currips = {}
oldiplist = self.store.load_related(nicnode, CMAconsts.REL_ipowner, IPaddrNode)
for ipnode in oldiplist:
currips[ipnode.ipaddr] = ipnode
#print >> sys.stderr, ('IP %s already related to NIC %s'
#% (str(ipnode.ipaddr), str(nicnode.macaddr)))
# See what IPs still need to be added
ips_to_add = []
for ip in IPlist:
if ip not in currips:
ips_to_add.append(ip)
# Replace the original list of IPs with those not already there...
IPlist = ips_to_add
# Now we have a NIC and IPs which aren't already related to it
for ip in IPlist:
ipnode = self.store.load_or_create(IPaddrNode, domain=drone.domain
, ipaddr=ip)
#print >> sys.stderr, ('CREATING IP %s for NIC %s'
#% (str(ipnode.ipaddr), str(nicnode.macaddr)))
if not Store.is_abstract(ipnode):
# Then this IP address already existed,
# but it wasn't related to our NIC...
# Make sure it isn't related to a different NIC
for oldnicnode in self.store.load_in_related(ipnode, CMAconsts.REL_ipowner
, GraphNode.factory):
self.store.separate(oldnicnode, CMAconsts.REL_ipowner, ipnode)
self.store.relate(nicnode, CMAconsts.REL_ipowner, ipnode)
示例12: performTask
def performTask(self, task):
self.performing_task = task
# Creating new store
store = Store(task.index_fields)
# Reading data
self.state = 'reading data from log %s' % task.log
data = self.filekeeper.read(task.log)
logging.debug("[worker %s] read %d bytes from %s" % (task.collector_name, len(data), task.log))
# Parsing and pushing data
self.state = 'parsing data from log %s' % task.log
total = 0
parsed = 0
t1 = time.time()
for line in data.split('\n'):
record = task.parser.parseLine(line+'\n')
if task.parser.successful:
parsed += 1
# after_parse_callbacks
for callback in task.after_parse_callbacks:
func = callback[0]
args = [record] + callback[1:]
try:
func(*args)
except Exception, e:
logging.debug('[%s.%s] %s' % (func.__module__, func.__name__, repr(e)))
store.push(record)
total += 1
示例13: insert
def insert(name, data):
global connection
doc = {'time': datetime.utcnow(), 'name': name, 'data': data}
print doc
s = Store('localhost:27017')
s.store('test', 'doc', doc)
connection.push('stats', doc)
return 'Inserted [%s:%d]' % (name, data)
示例14: create_domain
def create_domain():
domain = request.forms.domain
if domain:
store = Store()
store.create(domain)
flash("%s added" % domain)
fanout.update()
return redirect(url("domains"))
示例15: __init__
def __init__(self, file_path):
if Store.is_usable:
Store.file_name = file_path
print "\nFound Your File!\n\n"
else:
Store.file_name = file_path
Store.create_file()
print "Your file has been created!\n\n"