1 year ago

#383883

test-img

Gábor Szalma

Python open file with subprocess.call, which filename and path is stored in sqlite database

I'm making a QR code scanner with Python. I have a database where the primary key ID is stored in the QR code. If I scan the QR code, I want to open the file whose path+filename is stored in database column called Audiofile. If the QR code contains the path+filename, the audio file is to start playing. I made a GUI for it where I can upload several types of audio files and all the uploaded filenames and paths are stored in Audiofile in the database.

Here is my record in the database:

DATABASE URL LINK FOR IMAGE

So my QR code contains the testid, which is 73a380e8-b5d1-11ec-8de8-b827eb5d6f55 and if I read this QR code, I want to open the audiofile, which is /home/pi/Desktop/audiotodb/rocky1.mp3. How is it possible that from the ID I can open the audiofile with subprocess.call(['open', a])?

Here is the Python code, which is working with the QR code, which contains the URL:

import cv2
import time
import os, subprocess

cap = cv2.VideoCapture(0)
detector = cv2.QRCodeDetector()
prevData = " "

while True:
    check, img = cap.read()
    data, bbox, _ = detector.detectAndDecode(img)

    if data:
        a=data
        if data == prevData:
            continue

        if data == a:
            subprocess.call(['open', a])
            print(a)
        prevData = data
    cv2.imshow("QR Code detector", img)

    if(cv2.waitKey(1) == ord("q")):
        break

python

sql

sqlite

file

subprocess

0 Answers

Your Answer

Accepted video resources