Max Taylor
Max Taylor

Reputation: 129

Python/SQlite3 'str' object is not callable

So I would like to do a database with the date and some binary datum. Want I want to do is every 5 minutes, take the data of my sensor, and put it in a database with the exact time.

here is my script

import serial  # import the serial library
from time import sleep  # import the sleep command from the time library
import sqlite3
import datetime


ser = serial.Serial("/dev/tty.usbserial-A400DUTI", 4800)  # load into a variable 'ser' the information about the usb you are listening. /dev/tty.usbserial.... is the port after plugging in the hygrometer
conn=sqlite3.connect('porjectait.db') #connection with the data base
databa=conn.cursor()
databa.execute('''CREATE TABLE porjectait (date string, temphydro bin)''')
test_file=open("temphydro",'w+b')# creation and/or writing in my binary file

while 1 :
    i = 0
    date=(datetime.datetime.now()) #My way to get the date

    while i < 300 : #300 because it will take at least 2 round of datum

        test_file.write(ser.read(size=1)) #write into my bynary file

        i=i+1

    databa.execute("INSERT INTO porjectait VALUES"('date','test_file')) #insert the datum in my database
    conn.commit()
    sleep(300) #wait 5 minutes

my first problem but I found a way to resolve it, is I that I get a:

databa.execute('''CREATE TABLE stocks (date string, temphydro bin)''') sqlite3.OperationalError: table stocks already exists

To avoid that I just put a #, in front of the create line of the SQL. But I would like to find a way that just checks if the database exists, and if it does not exist create it, otherwise just had more datum.

Then my second and MAIN problem is when I execute my script I get:

databa.execute("INSERT INTO stocks VALUES"('date','test_file')) TypeError: 'str' object is not callable

Here is, if you need what is in my bynary file:

@
I01010100B00725030178
V0109EB01
I02020100B00725030148
V0215FBD9
I035300B5
V030225B8
I04550065
V040294AE
$
@
I01010100B00725030178
V0109EB01
I02020100B00725030148
V02160264
I035300B5
V03022704
I04550065
V040295F0
$
@

Thank you! see you soon

Upvotes: 0

Views: 1346

Answers (1)

grungero
grungero

Reputation: 81

Your INSERT string is wrong. The closing double quotes should be at the end, like "INSERT INTO stocks VALUES('date','test_file')"

Upvotes: 1

Related Questions