raspberry pi – usb qrcode reader acting as HiD device with python

I would like the input from qrcode reader to constantly input when a qrcode is presented and the following code to run.

my usb qrcode reader is connected to a rpi3 and reads all qrcodes presented and inputs data correctly to notepad.

I am having trouble with getting the reader to populate the input data.

see my code below:

def main(): #define the main function
     while True: # loop until the program encounters an error
        #ser = open ****disabled for test*****
        qrdata = input()
        print ("qrdata :",qrdata)
         
        json_checkexpiry=json.dumps({
                 "MemberID" : qrdata
             }, default=str)
        r = requests.post(url="https://prod-19.uksouth.logic.azure.com:443",
                          data=json_checkexpiry, headers={"Content-Type":"application/json"})
        
        
             #Extract date string from http response
        print("status: ", r.status_code)
        Expiry_Data = r.json()
        Expiry_Date = (Expiry_Data['ResultSets']['Table1'][0]['Expiry_Date'])
        ExpiryDate = datetime.fromisoformat (Expiry_Date)
        print(ExpiryDate)

    
        if ExpiryDate < datetime.now():
           
          
            #create json file with default encoding
            json_str1=json.dumps({
                    "MemberID" : qrdata,
                    "DoorName" : doorname,
                    "Result" : denied,
                    "Date" : d,
                    "Time" : t_str
                    }, default=str)
             #Make a post to the API#
            s = requests.post(url="https://prod-30.uksouth.logic.azure.com:443",
                                data=json_str1, headers={"Content-Type":"application/json"})
          
                #Print status of Request
                #Print status of request
            print("status: ", r.status_code)
            print("Membership Expired: ", qrdata)
            print("Date :",d)
            print("Time :",t)
        
        else:
             
                #create json file with default encoding string  
            json_str2=json.dumps({
                          "MemberID" : qrdata,
                          "DoorName" : doorname,
                          "Result" : success,
                          "Date" : d,
                          "Time" : t_str
                                    }, default=str)  
             
            #Make a POST request to the API -- url = logic app url, iclude json header and json body
            t = requests.post(url="https://prod-",
                              data=json_str2, headers={"Content-Type":"application/json"})
            
                #Print status of request
            print("status: ", r.status_code)
            print ("Access Granted: ", qrdata)
            print ("Date :",d)
            print ("Time :",t)
            
                #to unlock the door
            GPIO.output(RELAY, GPIO.HIGH)
            preTime = time1.time()
            doorUnlock = True
            print("Door Open")
            
    #lock the door after set amount of seconds
if doorUnlock == True and time1.time() - preTime > 3 :
            doorUnlock = False
            GPIO.output(RELAY, GPIO.LOW)
            print ("Door Locked")

main()

Read more here: Source link