コード例 #1
0
ファイル: hintbot.py プロジェクト: spnow/OverTheWire-hintbot
    def db_getHint(self, hintid): #{{{
	cu = self.db.cursor()
	cu.execute("select hint from hints where rowid=%d" % hintid)
	row = cu.fetchone()
	if row:
	    hint = str(row[0])
	    log("# Getting hint %d: %s" % (hintid, hint))
	    return True, hint
	else:
	    return False, 0
コード例 #2
0
 def db_getHint(self, hintid):  #{{{
     cu = self.db.cursor()
     cu.execute("select hint from hints where rowid=%d" % hintid)
     row = cu.fetchone()
     if row:
         hint = str(row[0])
         log("# Getting hint %d: %s" % (hintid, hint))
         return True, hint
     else:
         return False, 0
コード例 #3
0
ファイル: hintbot.py プロジェクト: spnow/OverTheWire-hintbot
    def db_getAllHints(self, keys=[]): #{{{
	cu = self.db.cursor()
	key = "%" + "%".join(keys) + "%"
	cu.execute("select rowid from hints where hint like ?", (key,))
	rows = cu.fetchall()
	if rows:
	    hintids = [int(x[0]) for x in rows]
	    log("# Getting all hint ids for [%s]: %s" % (key, ",".join([str(x) for x in hintids])))
	    return True, hintids
	else:
	    return False, []
コード例 #4
0
ファイル: hintbot.py プロジェクト: spnow/OverTheWire-hintbot
    def db_getRandomHint(self, keys=[]): #{{{
	cu = self.db.cursor()
	key = "%" + "%".join(keys) + "%"
	cu.execute("select rowid, hint from hints where hint like ? order by random() limit 1", (key,))
	row = cu.fetchone()
	if row:
	    hintid = int(row[0])
	    hint = str(row[1])
	    log("# Getting random hint for %s: [%d] %s" % (key, hintid, hint))
	    return True, hintid, hint
	else:
	    return False, 0, 0
コード例 #5
0
 def db_getAllHints(self, keys=[]):  #{{{
     cu = self.db.cursor()
     key = "%" + "%".join(keys) + "%"
     cu.execute("select rowid from hints where hint like ?", (key, ))
     rows = cu.fetchall()
     if rows:
         hintids = [int(x[0]) for x in rows]
         log("# Getting all hint ids for [%s]: %s" %
             (key, ",".join([str(x) for x in hintids])))
         return True, hintids
     else:
         return False, []
コード例 #6
0
 def db_getRandomHint(self, keys=[]):  #{{{
     cu = self.db.cursor()
     key = "%" + "%".join(keys) + "%"
     cu.execute(
         "select rowid, hint from hints where hint like ? order by random() limit 1",
         (key, ))
     row = cu.fetchone()
     if row:
         hintid = int(row[0])
         hint = str(row[1])
         log("# Getting random hint for %s: [%d] %s" % (key, hintid, hint))
         return True, hintid, hint
     else:
         return False, 0, 0
コード例 #7
0
ファイル: hintbot.py プロジェクト: spnow/OverTheWire-hintbot
    def db_delHint(self, hintid): #{{{
	cu = self.db.cursor()
	cu.execute("delete from hints where rowid=%d" % hintid)
	log("# Deleted hint %d" % hintid)
	self.db.commit()
コード例 #8
0
ファイル: hintbot.py プロジェクト: spnow/OverTheWire-hintbot
    def db_addHint(self, hint): #{{{
	cu = self.db.cursor()
	cu.execute("insert into hints values(?)", (hint,))
	log("# Added hint %d" % cu.lastrowid)
	self.db.commit()
	return cu.lastrowid
コード例 #9
0
 def db_delHint(self, hintid):  #{{{
     cu = self.db.cursor()
     cu.execute("delete from hints where rowid=%d" % hintid)
     log("# Deleted hint %d" % hintid)
     self.db.commit()
コード例 #10
0
 def db_addHint(self, hint):  #{{{
     cu = self.db.cursor()
     cu.execute("insert into hints values(?)", (hint, ))
     log("# Added hint %d" % cu.lastrowid)
     self.db.commit()
     return cu.lastrowid