鏁版嵁搴?fmldb.py
数据库保存 fml,似乎有待提高
#!/usr/bin/python
# coding:cp936
# CopyRights 2012 Adou XD , All Rights Reserved .
import sqlite3
def createDb():
'''create the blog datebase'''
con = sqlite3.connect('fmldb.db')
cur = con.cursor()
cur.execute('create table if not exists fmls (id integer primary key autoincrement,content text)')
con.commit()
cur.close()
con.close()
def getFmls():
'''get all the fmls'''
con = sqlite3.connect('fmldb.db')
cur = con.cursor()
cur.execute('select * from fmls')
allfmls = cur.fetchall()
cur.close()
con.close()
return allfmls
def getFml(id):
'''get fml by id'''
con = sqlite3.connect('fmldb.db')
cur = con.cursor()
cur.execute( "select * from fmls where id=%d" % id )
blogbyid = cur.fetchone()
cur.close()
con.close()
return blogbyid
def inFmldb(story):
'''get fml by id'''
con = sqlite3.connect('fmldb.db')
cur = con.cursor()
cur.execute( "select count(*) from fmls where content='%s'" % (story) )
isthere = cur.fetchone()
cur.close()
con.close()
if isthere[0]==0 :
return False
else :
return True
def newFml(newstory):
'''add a new fml'''
con = sqlite3.connect('fmldb.db')
cur = con.cursor()
result = cur.execute( "insert into fmls (content) values ('%s')" % (newstory) )
con.commit()
cur.close()
con.close()
return result
def delById(idnum):
'''delete fml by id'''
con = sqlite3.connect('fmldb.db')
cur = con.cursor()
result = cur.execute( "delete from fmls where id=%d" % idnum )
con.commit()
cur.close()
con.close()
return result
def delByContent(story):
'''delete fml by id'''
con = sqlite3.connect('fmldb.db')
cur = con.cursor()
result = cur.execute( "delete from fmls where content=%s" % story )
con.commit()
cur.close()
con.close()
return result
if __name__ == "__main__" :
'''test the database'''
#createDb()
allfmls = getFmls()
for onefml in allfmls :
print
print '%3d. %s' % onefml
'''
if onefml[0]>60 :
delById(onefml[0])
$c = raw_input()
if c == 'q' :
import sys
sys.exit()
'''