Exemplo n.º 1
0
async def main(signal):
    # Process setup
    manager = multiprocessing.Manager()
    dic = manager.dict()
    dic["angle"] = 2
    dic["move"] = 1.5
    dic["max"] = 120
    dic["min"] = 60
    dic["updated"] = True
    bot_process = multiprocessing.Process(target=robot, args=(dic,))
    PROCESSES.append(bot_process)

    # Thread setup
    cam = threading.Thread(target=camera, args=(signal,))
    THREADS.append(cam)
    
    # Start all processes and threads
    for t in THREADS:
        t.start()
    for p in PROCESSES:
        p.start()

    nap(5)
    # Add our tasks to the event loop and run them concurrerntly
    await asyncio.gather(paramAsy(dic, signal), camAsy(signal))
Exemplo n.º 2
0
    def post_new_tweet(self,message = "",image_path = None):
        # post new tweet 
        '''type message: string'''
        self.driver.get(self.new_tweet)

        # input field
        text_field = '//div[@class="public-DraftStyleDefault-block public-DraftStyleDefault-ltr"]'
        media_field = '//*[@accept="image/jpeg,image/png,image/webp,image/gif,video/mp4,video/quicktime,video/webm"]'
        post_btn = '//*[@aria-labelledby="modal-header"]//*[contains(text(),"Tweet")]'
        if message:
            print("Adding new message - ",message)
            self.execute_when_element_on_screen(text_field)
            text = self.driver.find_element_by_xpath(text_field)
            text.send_keys(message)
            nap_time = 1
        
        if image_path:
            nap(1) # to load the page 
            print("Adding new image - ",image_path)
            add_image = self.driver.find_element_by_xpath(media_field)
            add_image.send_keys(image_path)
            nap_time = 3

        # send post
        if message or image_path:
            self.execute_when_element_on_screen(post_btn)
            post_it = self.driver.find_element_by_xpath(post_btn)
            post_it.click()
            print("New Tweet posted.")
            nap(nap_time) # to post the message or image successfully
 def number_gen(self, clas):
     # wait for 2sec before painting
     nap(2)
     for i in clas.start_playing_gui():
         clas.update_tiles(i)
         play(f'sounds/{i}.mp3')  #################un comment it
         # print(self.napTime)
         nap(self.napTime)
    def clock(self):
        # update every second
        while True:
            # update the value here till the window exits it will run
            try:
                # time_value.set(datetime.datetime.now().strftime('%I:%M:%S %p'))
                self.time_value['text'] = datetime.datetime.now().strftime(
                    '%I:%M:%S %p')
                nap(1)

            except:
                # no exception to show
                print('clock Ends')
                quit()
                break
Exemplo n.º 5
0
 def wrapper(*args, **kwargs):
     try:
         start = time.perf_counter()
         return_data = function(*args, **kwargs)
         if show:
             time_taken = time.perf_counter() - start
             in_mins = divmod(time_taken, 60)
             nap(1)
             print(
                 "Time taken --> ", ":".join(
                     map(lambda x: str(int(x)), [
                         in_mins[1], *divmod(in_mins[0], 60)[::-1]
                     ][::-1])), "Hours")
         return return_data
     except Exception as e:
         print(e)
    def start_playing_gui(self):
        num = [i for i in range(1, 91)]
        for i in range(1, 91):
            # continiously waitly for the space key to pause the program
            while self.need_to_stop:
                # waiting for the user to press the hot key
                nap(0.1)

            if self.restart_thread and i != 90:
                self.restart_thread = False
                self.th = threading.Thread(target=lambda: self.key_waiting(),
                                           daemon=True)
                self.th.start()

            a = random.choice(num)
            num.remove(a)
            yield a

            if i == 90 and self.th.is_alive():
                # this break cause complete of the first thread and that cause end of all demon thread
                break
Exemplo n.º 7
0
    def bg_thread(self):
        # run the Thread for bg blink collecter
        blink_time, blinks = [], []
        last_notification_sent_time = time()
        min_interval_in_each_notification = 20 * 60  # notification after every 20 mins
        self.show_notification(f'Stating Blink Recording in 3 sec')
        nap(3)

        # collect all time spent and blink_count
        while not self.kill_thread:
            # first save the data in list
            blink_time.append(self.time_spent)
            blinks.append(self.blink_count)

            # clearing some space in list by checking the list elements
            while sum(blink_time) > 5:
                if sum(blink_time) - blink_time[0] >= 5:
                    blink_time.pop(0)
                    blinks.pop(0)
                else:
                    break

            # taking actions for the program
            # take actions - send notification to the user
            if sum(blink_time) >= 5:
                # if sum of blink time is 5 sec
                if (sum(blinks)
                        == 0) and (time() - last_notification_sent_time >=
                                   min_interval_in_each_notification):
                    # if sum of blinks is 0 in last 5s and prevent to send notification repeatedly
                    # this indent will run only with min intervals of 'min_interval_in_each_notification'
                    self.show_notification(
                        f'Blink, You didn\'t blink for about last {round(sum(blink_time))} seconds\nAlso stretch and straight your posture'
                    )
                    last_notification_sent_time = time(
                    )  # update last_notification_sent_time value to current time of notification send
                    # sleep for next 15 mins to save some processing power
                    print(
                        f'user notified blinks - {sum(blinks)} in last {round(sum(blink_time))}sec sleep for next 10 min'
                    )
                    blink_time, blinks = [], []
                    nap(10 * 60)

                elif (sum(blinks) >
                      0) and (time() - last_notification_sent_time >=
                              min_interval_in_each_notification):
                    print(
                        f'user working properly blinks - {sum(blinks)} in last {round(sum(blink_time))}sec'
                    )
                    # user blink 1 in 5 secs then just sleep for next 1 min and clear previous data
                    blink_time, blinks = [], []
                    nap(
                        1
                    )  # sleeping for next 1 min here and come with clean slate`
Exemplo n.º 8
0
    def blink_collector(self):
        while True:
            _, img = self.cam.read()
            coordinates = self.face_coordinates(img)
            self.data_saved = False

            # work on only one face
            if len(coordinates) == 1:
                # ploting the cordinates if there is only one face is there
                x, y, w, h = coordinates[0]
                # drow rectangle on screen
                if self.debug:
                    cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
                # cut the image only face to ninimise the processing
                just_face = img[y:y + h, x:x + w]
                # detect eye possitions
                eye = self.eye_cascade.detectMultiScale(just_face, 1.3, 5)

                # eye will only detected when eye is open
                # only if both eye are detected
                # if ele is blink then one frame have no eye in it that mean eye blink
                # this method works good but if there is any interference between eye program can see it as no eye (ex- sometimes glasses)
                if len(eye) == 2:
                    # print('eyes dete  cted')
                    for (ex, ey, ew, eh) in eye:
                        # because eye is in face then the possiton can be face + eye_relative to face
                        self.eye_in_last_frame = True
                        if self.debug:
                            cv2.rectangle(img, (x + ex, y + ey),
                                          (x + ex + ew, y + ey + eh),
                                          (255, 0, 0), 2)
                            cv2.putText(img, f"blinks:{self.blink_count}",
                                        (50, 50), cv2.FONT_HERSHEY_PLAIN, 3,
                                        (0, 255, 0), 2)
                            cv2.putText(img, f"time:{self.time_spent}",
                                        (300, 50), cv2.FONT_HERSHEY_PLAIN, 3,
                                        (0, 255, 0), 2)
                else:
                    # if less or no eye found then consider it closed
                    # print('eye not found')
                    if self.eye_in_last_frame:
                        self.blink_count += 1
                        self.eye_in_last_frame = False

            else:
                self.save_data(self.time_spent, self.blink_count)
                self.data_saved = True
                # if no person or nore then 1 preson found -> sleep and restart the clock
                if not self.debug:
                    nap(0.3)
                self.start = time()
                self.blink_count = 0
                # save the results here

            # show image in cv2 take 2 arrg =window name , image
            if self.debug:
                cv2.imshow('stream', img)
                key = cv2.waitKey(1)
                if key == 81 or key == 27:
                    cv2.destroyAllWindows()
                    self.closed = True
                    break

            # close the program after self.time_limit if running in background
            if ((time() - self.run_time) >= self.time_limit) and (
                    not self.debug) and (not self.run_from_bg_function):
                # break the program if it runs more then 20 min
                # print(not self.run_from_bg_function)
                print(
                    f'program run for last {round(time() - self.run_time)} seconds sufficiant data collected 😉'
                )
                break
    def start_playing_cmd(self):
        num = [i for i in range(1, 91)]
        done = []
        l10 = []
        l20 = []
        l30 = []
        l40 = []
        l50 = []
        l60 = []
        l70 = []
        l80 = []
        l90 = []

        for i in range(1, 91):
            if self.method == 'input':
                input("press enter to get num")
            else:
                # waiting for naptime
                nap(self.napTime)
                # continiously waitly for the space key to pause the program
                while self.need_to_stop:
                    # waiting for the user to press the hot key
                    nap(1)

                if self.restart_thread and i != 90:
                    self.restart_thread = False
                    self.th = threading.Thread(target=self.key_waiting,
                                               daemon=True)
                    self.th.start()

            if num != []:
                print(i)

                a = random.choice(num)
                num.remove(a)
                # threading.Thread(target=play,args=(f'sounds/{a}.mp3',)).start()
                # print(a)
                # print('\033[93m' + str(a) + '\033[0m')
                print()
                print(a)
                print()
                done.insert(0, a)
                done.sort()

                if a <= 10:
                    l10.append(a)
                    l10.sort()

                elif a <= 20:
                    l20.append(a)
                    l20.sort()

                elif a <= 30:
                    l30.append(a)
                    l30.sort()

                elif a <= 40:
                    l40.append(a)
                    l40.sort()

                elif a <= 50:
                    l50.append(a)
                    l50.sort()

                elif a <= 60:
                    l60.append(a)
                    l60.sort()

                elif a <= 70:
                    l70.append(a)
                    l70.sort()

                elif a <= 80:
                    l80.append(a)
                    l80.sort()

                elif a <= 90:
                    l90.append(a)
                    l90.sort()

                # print(done)
                print('line 0-1  ', l10)
                print('line 11-20', l20)
                print('line 21-30', l30)
                print('line 31-40', l40)
                print('line 41-50', l50)
                print('line 51-60', l60)
                print('line 61-70', l70)
                print('line 71-80', l80)
                print('line 81-90', l90)
                print()
                play(f'sounds/{a}.mp3')  #######################

                if i == 90:
                    # '''to sea all the all number ^__^'''
                    nap(5)

            else:
                print('no num left')

            if self.method != 'input' and i == 90 and self.th.is_alive():
                # this break cause complete of the first thread and that cause end of all demon thread
                break
Exemplo n.º 10
0
 def __exit__(self,a,b,c):
     nap(3) # to complete any pending message
     self.logout()