Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

I want to save python variable result to a mysql database

shanedesilvashanedesilva colomboPosts: 1

when this files run gives corresponding output values as;

test BLE Scanning software

jcs 6/8/2014

import MySQLdb as my
import blescan
import sys

import bluetooth._bluetooth as bluez

dev_id = 0

db = my.connect(host="localhost",
user="root",
passwd="root",
db="test"
)

cursor = db.cursor()

try:
sock = bluez.hci_open_dev(dev_id)
print "ble thread started"

except:
print "error accessing bluetooth device..."
sys.exit(1)

blescan.hci_le_set_scan_parameters(sock)
blescan.hci_enable_le_scan(sock)

while True:
returnedList = blescan.parse_events(sock, 10)
print "----------"
for beacon in returnedList:

    print beacon

sql = "insert into beacon VALUES(null, '%s')" % \
(beacon)

number_of_rows = cursor.execute(sql)
db.commit()
db.close()

db.close()

I want output stored in a mysql dtatabase

f:68:cc:c7:33:10,b9407f30f5f8466eaff925556b57fe6d,13072,52423,-74,-78
cf:68:cc:c7:33:10,74696d6f74650e160a181033c7cc68cf,46608,13255,-52,-77
da:f4:2e:a0:70:b1,b9407f30f5f8466eaff925556b57fe6d,28849,11936,-74,-79
da:f4:2e:a0:70:b1,74696d6f74650e160a18b170a02ef4da,46769,28832,46,-78
dd:5d:d3:35:09:dd,8aefb0316c32486f825be26fa193487d,1,1,-64,-78
c3:11:48:9b:cf:fa,8aefb0316c32486f825be26fa193487d,0,0,-64,-73
fd:5b:12:7f:02:e4,b9407f30f5f8466eaff925556b57fe6d,740,4735,-74,-79
fd:5b:12:7f:02:e4,74696d6f74650e160a18e4027f125bfd,46820,639,18,-80
dd:5d:d3:35:09:dd,8aefb0316c32486f825be26fa193487d,1,1,-64,-77
so on... and then write store these values in a mysql database. is it possible to insert these values as a part of script? Thanks.

Sign In or Register to comment.