in following example, have managed print sql values insert in mysql table. how execute statement?
import re import mysqldb s = "jul 15 12:12:51 whitelist logger: 1|999999999999|id:d9faff7c-4016-4343-b494-37028763bb66 submit date:1307130919 done date:1307130919 stat:delivrd err:0|l_vb3_nm_k_p|1373687445|vivnel2|l_vb3_gh_k_p|promo_camp1-bd153424349bc647|1" logger_re = re.compile( "logger: ([^ ]+)\ submit date:(\d+)\ done date:(\d+)\ stat:(.+)\ err:(.+)$") myvalues = logger_re.search(s).groups() db = mysqldb.connect(host="localhost", # host, localhost user="root", # username passwd="passwd", # password db="test") # name of data base # must create cursor object. let # execute query need cur = db.cursor() # cur.execute(insert test.weblogs (output of myvalues))
the values needs extracted text file. typically /var/log/messages
this example should help
after reading question, it's hard problem (formatting query, commit process?)
try: cur.execute("insert mytable (id,somerow) values (%s, %s)" % ("someid", "somerow")) db.commit() except mysqldb.error, e: print e[0], e[1] db.rollback()
Comments
Post a Comment