Example #1
0
def get_new_msg():
	try:
		conn = db.myconnect()
		cur = db.getCur()

		count = cur.execute('select id,content from new_xh where status = 0 order by add_time limit 1')
		result = cur.fetchone()
		value = [1,result[0]]
		cur.execute('update new_xh set status = %s where id = %s',value)
		conn.commit()
		cur.close()
		conn.close()
		return result[1]
	except MySQLdb.Error,e:
		print "Mysql Error %d: %s" % (e.args[0],e.args[1])
Example #2
0
def get_user_list():
	try:
		conn = db.myconnect()
		cur = db.getCur()

		count = cur.execute('select distinct tel from xh_user')

		results = cur.fetchall()
		list = []
		for tel in results:
			list.append(tel[0])
		conn.commit()
		cur.close()
		conn.close()
		return list
	except MySQLdb.Error,e:
		print "Mysql Error %d: %s" % (e.args[0],e.args[1])
Example #3
0
def save_xiaohua(img,nickname,cont,voteCount,commentCount,now):
	try:
		conn = db.myconnect()
		cur = db.getCur(conn)
		# 根据md5查询该消息是否已存在
		md5 = hashlib.md5(cont.encode(chars)).hexdigest()
		condition=[md5]
		cur.execute('select count(1) from xh_text where md5 = %s',condition)
		count = cur.fetchone()
		if count[0] <= 0:
			value=[nickname,img,cont,time.strftime(ISOTIMEFORMAT, time.localtime()),commentCount,voteCount,0,md5,now]
			# pirnt value
			cur.execute('insert into xh_text(author,avatar,content,add_time,comment_count,hx_count,status,md5,last_modify) values(%s,%s,%s,%s,%s,%s,%s,%s,%s)',value)
		conn.commit()
		cur.close()
		conn.close()
	except MySQLdb.Error,e:
		print "Mysql Error %d: %s" % (e.args[0],e.args[1])
Example #4
0
def save_xiaohua(avatar,nickname,cont,image,voteNumber,commentNumber,md5,path,now):
	try:
		conn = db.myconnect()
		cur = db.getCur(conn)
		# 根据md5查询该消息是否已存在
		condition=[md5]
		cur.execute('select count(1) from xh_image where md5 = %s',condition)
		count = cur.fetchone()
		if count[0] <= 0:
			value=[nickname,avatar,cont,image,commentNumber,voteNumber,0,time.strftime(ISOTIMEFORMAT, time.localtime()),0,md5,now]
			cur.execute('insert into xh_image(author,avatar,title,url,comment_count,hx_count,share_count,add_time,status,md5,last_modify) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)',value)
		else:
			if os.path.exists(path):
				os.remove(path)
		conn.commit()
		cur.close()
		conn.close()
	except MySQLdb.Error,e:
		print "Mysql Error %d: %s" % (e.args[0],e.args[1])