简体   繁体   中英

Telebot: How do I make my telegram bot to read new messages during a for loop?

I have this for loop:

 for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
    
    image = frame.array

    gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, 1.1, 5)
    for (x,y,w,h) in faces:
        cv2.rectangle(image,(x,y),(x+w,y+h),(255,0,0),2)

    cv2.imshow("Vigilancia", image)
    key = cv2.waitKey(1) & 0xFF
    rawCapture.truncate(0)

    if faces != ():
        cv2.imwrite('/home/pi/imagen.jpg',image)
        break
    elif key == ord("q"):
        break
    #elif user_input[userid]['Desactivar vigilancia']:
        #break

I want to get out of the loop if the user types "Desactivar vigilancia". How do I do it?

If I didn't misunderstand

elif (user_id := input("Enter a user id value:")) == "Desactivar vigilancia":
    break

You can later use the "user_id" variable,

Important reminder This code works on Python 3.8 and later versions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM