def blogdb(sql): conn = db.MySQL().use_db('fox') cu = conn.cursor() cu.execute(sql) blogs = dict() row = cu.fetchone() while row: blogs[row[0]] = row row = cu.fetchone() return blogs
def count(ip): conn = db.MySQL().use_db('fox') #conn = MySQLdb.connect(user='******', passwd='QqsFwIkuh4zI', host='127.0.250.129', port=3306, db='fox') cu = conn.cursor() date = time.strftime('%Y-%m-%d') c = 1 #if re.match('192\.168|10\.|127\.0\.0\.1', ip): if re.match('10\.', ip): c = 0 cu.execute('select count from count where date=%s', (date, )) if not cu.fetchall(): cu.execute('insert into count values (%s, %s)', (date, c)) else: cu.execute('update count set count=count+%s where date=%s', (c, date)) cu.execute('select sum(count) from count') counts = cu.fetchall()[0][0] conn.commit() cu.close() conn.close() return counts
def start(self, page): d = db.MySQL() for i in range(0, page): print '开始获取第' + str(i + 1) + '页数据' content = self.getPageItems(str(i)) #返回值是list(数组) print '共获取到' + str(len(content)) + '数据' ##插入至数据库 item是字典 for item in content: check = d.query("select * from article where content = '" + item['content'] + "'") if not check: d.insert('article', item) else: print '已存在的数据' d.commit() print '插入到数据库成功' #延迟一秒加载下一页内容 print '----------------------sleep3秒------------------------' time.sleep(3)
def post(environ): ctype = 'text/plain' length = int(environ['CONTENT_LENGTH']) data = cgi.parse_qs(environ['wsgi.input'].read(length)) conn = db.MySQL().use_db('fox') cu = conn.cursor() post_time = time.strftime('%Y-%m-%d %H:%M:%S') id = os.path.basename(environ['PATH_INFO'].rstrip('/')) if not id.isdigit(): cu.execute('insert into blog (date, title, content, category, tags) \ values (%s, %s, %s, %s, %s)' , (post_time, \ data['title'][0], data['content'][0], \ data.get('category', [''])[0], data.get('tags', [''])[0])) else: cu.execute('update blog set date=%s, title=%s, content=%s, category=%s,\ tags=%s where id=%s' , (post_time, data['title'][0], \ data['content'][0], data.get('category', [''])[0], \ data.get('tags', [''])[0], id)) conn.commit() cu.close() conn.close() response_body = '\n'.join( ["%s => %s" % (key, value[0]) for (key, value) in data.items()]) return (ctype, response_body)
import LED import rfid_reader import db # Start setup pin1 = 18 pin2 = 19 pin3 = 21 pin4 = 22 pin5 = 23 pin6 = 24 pin7 = 26 checkpoint = LED.LEDs(pin1, pin2, pin3, pin4, pin5, pin6, pin7) # reader = rfid_reader.RFID_reader() db = db.MySQL() # End setup #Code for led in checkpoint.chain1: led.light() for led in reversed(checkpoint.chain1): led.light() db.MySQL.read_db() """ if reader.has_tag(): if reader.has_new_message(): print ("Tag:", reader.message())