本文整理汇总了Python中mysql.Mysql.insert方法的典型用法代码示例。如果您正苦于以下问题:Python Mysql.insert方法的具体用法?Python Mysql.insert怎么用?Python Mysql.insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mysql.Mysql
的用法示例。
在下文中一共展示了Mysql.insert方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getFileData
# 需要导入模块: from mysql import Mysql [as 别名]
# 或者: from mysql.Mysql import insert [as 别名]
def getFileData(file):
try:
f = open(file,'r')
except IOError as e:
print e
exit()
else:
datalist = list()
for line in f:
datalist.append(line.split())
return datalist
for i in getFileData("""%s/%s_StatusCode.txt"""%(Dir,db_yesterday)):
sql = """insert into StatisticsStatus(StatisticsDate,StatusCode,StatusNum) values('%s',%s,%s)"""%(db_yesterday,i[1],i[0])
mysql.insert(sql)
for i in getFileData("""%s/%s.MMGlobal.txt"""%(Dir,db_yesterday)):
sql = """insert into StatisticsHour(StaticsticsDate,Hour,Channel,ReqNum,ResTime) values('%s',%s,'%s',%s,%s)"""%(db_yesterday,i[1],i[0],i[2],i[3])
mysql.insert(sql)
for i in getFileData("""%s/%s_time_and_revalue.txt"""%(Dir,db_yesterday)):
sql = """
insert into PageStatistics(
StaticsticsDate,
Channel,
RequestNum,
TimeAvg,
LessOneSecNum,
LessOneSecPercent,
BetweenOneThreeSecNum,
示例2: Mysql
# 需要导入模块: from mysql import Mysql [as 别名]
# 或者: from mysql.Mysql import insert [as 别名]
if __name__ == '__main__':
import time,json
config = {'host':'127.0.0.1','user':'root','passwd':'123456'}
database = 'babel'
db = Mysql(config,database)
tableName = 'bb_crawl_infos'
with open('../../log.insert.sql','r+') as f:
d = f.read()
d = json.loads(d)
# print d
db.insert(tableName,d)
# infos = json.dumps(dict(insertData))
# sql = 'select * from bb_spider_rules'
# print db.findOne(sql)
# for i in db.findAll(sql):
# print i
# print "*"*88
# tableName = 'bb_crawl_infos'
# insertData = {
# 'source_url' : 'www.baidu.com',
# 'unique_code' : 'eesaaaaa',