本文整理汇总了Python中torndb.Connection方法的典型用法代码示例。如果您正苦于以下问题:Python torndb.Connection方法的具体用法?Python torndb.Connection怎么用?Python torndb.Connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类torndb
的用法示例。
在下文中一共展示了torndb.Connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import torndb [as 别名]
# 或者: from torndb import Connection [as 别名]
def __init__(self):
threading.Thread.__init__(self)
self.db_conn = torndb.Connection(options.dbhost, options.dbname,
options.dbuser, options.dbpass,
time_zone=options.dbtimezone)
today = datetime.date.today()
self._user_classifier = dict()
self.k_value = 0
self.lsi = None
self.MAX_INTEREST = 10
self.THRESH_HOLD_MINI = 0.2 #?????
self.dumpfile = "dumpdir/recsvd_dump.%d_%d" %(today.month, today.day)
if os.path.exists(self.dumpfile):
print("dumpfile %s exists, just load it!" %(self.dumpfile))
with open(self.dumpfile,'rb') as fp:
dump_data = pickle.load(fp)
self._user_classifier = dump_data[0]
self.k_value = dump_data[1]
self.lsi = dump_data[2]
del dump_data
return
示例2: __init__
# 需要导入模块: import torndb [as 别名]
# 或者: from torndb import Connection [as 别名]
def __init__(self):
threading.Thread.__init__(self)
self.db_conn = torndb.Connection(options.dbhost, options.dbname,
options.dbuser, options.dbpass,
time_zone=options.dbtimezone)
today = datetime.date.today()
self.dumpfile = "dumpdir/recmaxent_dump.%d_%d" %(today.month, today.day)
self._user_classifier = dict()
if os.path.exists(self.dumpfile):
print("dumpfile %s exists, just load it!" %(self.dumpfile))
with open(self.dumpfile,'rb') as fp:
dump_data = pickle.load(fp)
self._user_classifier = dump_data[0]
return
示例3: main
# 需要导入模块: import torndb [as 别名]
# 或者: from torndb import Connection [as 别名]
def main():
db1 = Connection(options.database_host, options.database_user, options.database_password)
#grab all shared files in order
sfs = db1.query("""SELECT id FROM sharedfile ORDER BY created_at""")
#for each, get counts
for sf in sfs:
likes = 0
saves = 0
like_counts = db1.query("SELECT count(id) as like_count from favorite where sharedfile_id = %s and deleted=0", (sf.id))
if like_counts:
likes = like_counts[0]['like_count']
save_counts = db1.query("SELECT count(id) AS save_count FROM sharedfile WHERE original_id = %s and deleted = 0", sf.id)
if save_counts[0]['save_count'] > 0:
saves = save_counts[0]['save_count']
else:
save_counts = db1.query("SELECT count(id) AS save_count FROM sharedfile WHERE parent_id = %s and deleted = 0", sf.id)
saves = save_counts[0]['save_count']
if likes > 0 or saves > 0:
print "UPDATE sharedfile SET like_count = %s, save_count = %s WHERE id = %s" % (likes, saves, sf.id)
print db1.execute("UPDATE sharedfile SET like_count = %s, save_count = %s WHERE id = %s", likes, saves, sf.id)
示例4: __init__
# 需要导入模块: import torndb [as 别名]
# 或者: from torndb import Connection [as 别名]
def __init__(self):
global db_conn
threading.Thread.__init__(self)
db_conn = torndb.Connection(options.dbhost, options.dbname,
options.dbuser, options.dbpass,
time_zone=options.dbtimezone)
return
示例5: __init__
# 需要导入模块: import torndb [as 别名]
# 或者: from torndb import Connection [as 别名]
def __init__(self):
threading.Thread.__init__(self)
self.db_conn = torndb.Connection(options.dbhost, options.dbname,
options.dbuser, options.dbpass,
time_zone=options.dbtimezone)
return
示例6: __init__
# 需要导入模块: import torndb [as 别名]
# 或者: from torndb import Connection [as 别名]
def __init__(self):
today = datetime.date.today()
self.stopfile = "stopwords.txt"
self.dumpfile = "dumpdir/nlpmaster_dump.%d_%d" %(today.month, today.day)
self.dictionary = None
self._stop_words = set()
self._id_docs = dict()
self._cached_today = dict() #???????
self.db_conn = torndb.Connection(options.dbhost, options.dbname,
options.dbuser, options.dbpass,
time_zone=options.dbtimezone)
if os.path.exists(self.dumpfile):
print("dumpfile %s exists, just load it!" %(self.dumpfile))
with open(self.dumpfile,'rb') as fp:
dump_data = pickle.load(fp)
self.dictionary = dump_data[0]
self._stop_words = dump_data[1]
self._id_docs = dump_data[2]
else:
print("Do the fresh nlp master!")
self.build_wordcorpus()
return
示例7: __init__
# 需要导入模块: import torndb [as 别名]
# 或者: from torndb import Connection [as 别名]
def __init__(self):
handlers = [
(r"/", HomeHandler),
(r"/archive", ArchiveHandler),
(r"/feed", FeedHandler),
(r"/entry/([^/]+)", EntryHandler),
(r"/compose", ComposeHandler),
(r"/auth/login", AuthLoginHandler),
(r"/auth/logout", AuthLogoutHandler),
]
settings = dict(
blog_title=u"Tornado Blog",
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
ui_modules={"Entry": EntryModule},
xsrf_cookies=True,
cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
login_url="/auth/login",
debug=True,
)
tornado.web.Application.__init__(self, handlers, **settings)
# Have one global connection to the blog DB across all handlers
self.db = torndb.Connection(
host=options.mysql_host, database=options.mysql_database,
user=options.mysql_user, password=options.mysql_password)
示例8: __init__
# 需要导入模块: import torndb [as 别名]
# 或者: from torndb import Connection [as 别名]
def __init__(self):
handlers = [
(r"/", HomeHandler),
(r"/archive", ArchiveHandler),
(r"/feed", FeedHandler),
(r"/entry/([^/]+)", EntryHandler),
(r"/compose", ComposeHandler),
(r"/auth/create", AuthCreateHandler),
(r"/auth/login", AuthLoginHandler),
(r"/auth/logout", AuthLogoutHandler),
]
settings = dict(
blog_title=u"Tornado Blog",
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
ui_modules={"Entry": EntryModule},
xsrf_cookies=True,
cookie_secret="__TODO:_GENERATE_YOUR_OWN_RANDOM_VALUE_HERE__",
login_url="/auth/login",
debug=True,
)
super(Application, self).__init__(handlers, **settings)
# Have one global connection to the blog DB across all handlers
self.db = torndb.Connection(
host=options.mysql_host, database=options.mysql_database,
user=options.mysql_user, password=options.mysql_password)
self.maybe_create_tables()
示例9: __init__
# 需要导入模块: import torndb [as 别名]
# 或者: from torndb import Connection [as 别名]
def __init__(self):
handlers = [
# ????
(r"/", HomeHandler),
# ??datatable ?????????
(r"/stock/api_data", dataTableHandler.GetStockDataHandler),
(r"/stock/data", dataTableHandler.GetStockHtmlHandler),
# chart ???
(r"/stock/chart", chartHandler.GetChartHtmlHandler),
(r"/stock/chart/image1", chartHandler.ImageHandler),
# ????dataEditor?
(r"/data/editor", dataEditorHandler.GetEditorHtmlHandler),
(r"/data/editor/save", dataEditorHandler.SaveEditorHandler),
# ?????????
(r"/data/indicators", dataIndicatorsHandler.GetDataIndicatorsHandler),
# ????dataEditor?
(r"/minst_serving", minstServingHandler.GetMinstServingHtmlHandler),
(r"/minst_serving/prediction", minstServingHandler.GetPredictionDataHandler),
(r"/minst_serving/prediction2", minstServingHandler.GetPrediction2DataHandler),
]
settings = dict( # ??
template_path=os.path.join(os.path.dirname(__file__), "templates"),
static_path=os.path.join(os.path.dirname(__file__), "static"),
xsrf_cookies=False, # True,
# cookie??
cookie_secret="027bb1b670eddf0392cdda8709268a17b58b7",
debug=True,
)
super(Application, self).__init__(handlers, **settings)
# Have one global connection to the blog DB across all handlers
self.db = torndb.Connection(
host=common.MYSQL_HOST, database=common.MYSQL_DB,
user=common.MYSQL_USER, password=common.MYSQL_PWD)
# ??handler?
示例10: __init__
# 需要导入模块: import torndb [as 别名]
# 或者: from torndb import Connection [as 别名]
def __init__(self, handlers, settings):
super(Application, self).__init__(handlers, **settings)
# Have one global connection to the blog DB across all handlers
self.db = torndb.Connection(
host='127.0.0.1:3306',
database='bestchat',
user='bestChat',
password='a5e625568329d8c2216631da90efc030121400bde3bde2300fd089b738568717'
)
示例11: main
# 需要导入模块: import torndb [as 别名]
# 或者: from torndb import Connection [as 别名]
def main():
db1 = Connection(options.database_host, options.database_user, options.database_password)
db1.execute("DELETE FROM post WHERE 1")
ssfs = db1.query("""SELECT shake_id, sharedfile_id from shakesharedfile order by created_at""")
for shakesharedfile in ssfs:
sf = db1.get("""SELECT id, source_id, name, deleted, created_at FROM sharedfile WHERE id = %s""", shakesharedfile['sharedfile_id'])
print "%s. Adding posts for sharedfile: %s created at %s." % (sf.id, sf.name, sf.created_at)
add_posts(shake_id=shakesharedfile['shake_id'], sharedfile_id=sf['id'], sourcefile_id=sf['source_id'], deleted=sf['deleted'], created_at=sf['created_at'])
示例12: main
# 需要导入模块: import torndb [as 别名]
# 或者: from torndb import Connection [as 别名]
def main():
db1 = Connection(options.database_host, options.database_user, options.database_password)
#grab all group shakes
shakes = db1.query("""SELECT id, user_id FROM shake WHERE type=%s""", "group")
for shake in shakes:
db1.execute("""INSERT IGNORE INTO subscription (user_id, shake_id, deleted, created_at, updated_at)
VALUES (%s, %s, 0, NOW(), NOW())""", shake['user_id'], shake['id'])
#print """INSERT INTO subscription (user_id, shake_id, deleted, created_at, updated_at)
# VALUES (%s, %s, 0, NOW(), NOW())""" % (shake['user_id'], shake['id'])
示例13: main
# 需要导入模块: import torndb [as 别名]
# 或者: from torndb import Connection [as 别名]
def main():
db1 = Connection(options.database_host, options.database_user, options.database_password)
db1.execute("UPDATE shakesharedfile SET deleted = 1 WHERE deleted = 0 AND sharedfile_id IN (SELECT id FROM sharedfile WHERE deleted = 1)")
示例14: register
# 需要导入模块: import torndb [as 别名]
# 或者: from torndb import Connection [as 别名]
def register(self, host='localhost', name=None, user=None, password=None, charset="utf8"):
self._connection = torndb.Connection(host, name, user, password, charset=charset)
return self._connection
示例15: calculate_saves
# 需要导入模块: import torndb [as 别名]
# 或者: from torndb import Connection [as 别名]
def calculate_saves(sharedfile_id, **kwargs):
"""
Take the id of a sharedfile that just got saved by another user.
If this file is an original, meaning it has no original_id set, we can safely calculate the save count by how
many sharedfiles have the file's id as their original_id.
However if the file has an original, we also need to recalculate the original's count, as well as this file's save count.
"""
db = Connection(options.database_host, options.database_name, options.database_user, options.database_password)
sharedfile = db.get("select original_id from sharedfile where id = %s", sharedfile_id)
original_id = sharedfile['original_id']
# If this file is original, calculate it's save count by all sharedfile where this file is the original_id.
if original_id == 0:
original_saves = db.get("SELECT count(id) AS count FROM sharedfile where original_id = %s and deleted = 0", sharedfile_id)
db.execute("UPDATE sharedfile set save_count = %s WHERE id = %s", original_saves['count'], sharedfile_id)
# Otherwise, we need to update the original's save count and this file's save count.
else:
original_saves = db.get("SELECT count(id) AS count FROM sharedfile where original_id = %s and deleted = 0", original_id)
db.execute("UPDATE sharedfile set save_count = %s WHERE id = %s", original_saves['count'], original_id)
# Calc this files new save count, only based on parent since its not original.
parent_saves = db.get("SELECT count(id) AS count FROM sharedfile where parent_id = %s and deleted = 0", sharedfile_id)
db.execute("UPDATE sharedfile set save_count = %s WHERE id = %s", parent_saves['count'], sharedfile_id)
db.close()