"""
Bot for pbo
"""
import sys
from time import time
import pyautogui
import numpy as np
from get_name import get_name


if __name__ == '__main__':
    searched = input('Enter the name of pokemon: ')

    while True:
        # Press d for some random time
        duration = 0.2 + np.random.rand()*0.8
        t0 = time()
        pyautogui.keyDown("d")
        while time() - t0 < duration:
            pass
        pyautogui.keyUp("d")

        current = get_name()
        print('Current:', current)
        if searched in current:
            sys.exit()
        else:
            pyautogui.press('r')

        # Press a for some random time
        duration = 0.2 + np.random.rand()*0.8
        t0 = time()
        pyautogui.keyDown("a")
        while time() - t0 < duration:
            pass
        pyautogui.keyUp("a")

        current = get_name()
        print('Current:', current)
        if searched in current:
            sys.exit()
        else:
            pyautogui.press('r')
