本文整理汇总了Python中kyotocabinet.DB.set方法的典型用法代码示例。如果您正苦于以下问题:Python DB.set方法的具体用法?Python DB.set怎么用?Python DB.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kyotocabinet.DB
的用法示例。
在下文中一共展示了DB.set方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: insert_item
# 需要导入模块: from kyotocabinet import DB [as 别名]
# 或者: from kyotocabinet.DB import set [as 别名]
def insert_item(url, person, db_file, submitted_title=''):
mimetype = "application/json"
db = DB()
if not db.open("{0}".format(db_file),
DB.OWRITER | DB.OCREATE):
response = {}
response['What happened?'] = "Couldn't open the damn database. Error: {0}".format(db.error())
return Response(dumps(response), mimetype=mimetype)
if is_url_in_db(db, url):
return Response('{"What happened?": "Someone '\
'tried to submit a duplicate URL."}',
mimetype=mimetype)
title = url
summary = "~?~"
try:
thing = urlopen(url, timeout=10)
soup = BeautifulSoup(thing)
title = ''
if len(submitted_title) > 0:
title = submitted_title
else:
title = soup.title.string
# Do some dumb summarizing if we can
func = lambda a,v: a + " " + v.strip()
visible_stuff = filter(visible, soup.findAll(text=True))
summary = reduce(func, visible_stuff, "")[:900] + "..."
except:
pass
#return Response('{"What happened?": '\
# 'I dunno bs4 messed up somehow."}',
# mimetype=mimetype)
created_at = int(mktime(datetime.now().utctimetuple()))
is_image = url.lower().endswith(("jpg", "jpeg", "gif", "png"))
thumbnail = gen_thumbnail_for_url(url, str(created_at))
record = {
"created_at": created_at,
"title": title,
"url": url,
"person": person,
"summary": summary,
"person_color": PERSON_COLORS[random.randint(0, len(PERSON_COLORS)-1)],
"is_image": is_image,
"thumbnail": thumbnail
}
db.set(created_at, dumps(record))
db.close()
return Response('{"What happened?": "MUDADA"}',
mimetype=mimetype)
示例2: decorated_function
# 需要导入模块: from kyotocabinet import DB [as 别名]
# 或者: from kyotocabinet.DB import set [as 别名]
def decorated_function(*args, **kwargs):
# Debug
if not current_app.config['CACHE']:
return f(*args, **kwargs)
db = DB()
db.open("/tmp/page_cache.kch")
res = None
fancy = hash("{}{}{}".format(db_meta_info()['count'], request.url, f.func_name))
res = db.get(fancy)
if not res:
res = f(*args, **kwargs)
db.set(fancy, res)
db.close()
return res
示例3: purge
# 需要导入模块: from kyotocabinet import DB [as 别名]
# 或者: from kyotocabinet.DB import set [as 别名]
def purge(domain, genid):
if request.remote_addr not in settings.ALLOW:
return text_response("Not permitted.\n", 403)
db = DB()
if not db.open(settings.GENID_DATABASE, DB.OWRITER | DB.OCREATE):
return text_response("Failed to purge: cannot open database.\n", 501)
set_ok = db.set(domain, genid)
db.close()
if not set_ok:
return text_response("Failed to purge: cannot set genid.\n", 501)
else:
return text_response("Purged <%s>\n" % (domain,))
示例4: format_datetime
# 需要导入模块: from kyotocabinet import DB [as 别名]
# 或者: from kyotocabinet.DB import set [as 别名]
#format datetime
def format_datetime(timestamp):
return time.strftime('%Y.%m.%d @ %H:%M',time.localtime(timestamp))
#创建数据库对象
db=DB()
# open the database
if not db.open("../data/db.kch", DB.OWRITER | DB.OCREATE):
print >>sys.stderr, "open error: " + str(db.error())
cid='1'
#build for marks form
if not db.set("mark:"+cid+":markid", "1") or\
not db.set("mark:"+cid+":userid", "1") or\
not db.set("mark:"+cid+":boardid", "1") or\
not db.set("mark:"+cid+":fileid", "1") or\
not db.set("mark:"+cid+":description", "mark的内容描述") or\
not db.set("mark:"+cid+":content", "哇。。阳光暖暖的,好惬意的。") or\
not db.set("mark:"+cid+":ups", "100") or\
not db.set("mark:"+cid+":downs", "10") or\
not db.set("mark:"+cid+":hits", "110") or\
not db.set("mark:"+cid+":order", "1") or\
not db.set("maks:"+cid+":createdata", int(time.time())) or\
not db.set("maks:"+cid+":commentcount", "8") or\
not db.set("mark:count", "3"):
print >>sys.stderr, "set error: " + str(db.error())
#build for comments form