Пример #1
0
 def generate_mask(self, train=True):
     n = len(self.biases)
     if not train:  # when not training, don't do anything
         return tile(1, n)
     mask = tile(0, n)
     for i in range(n):
         if rfloat() > self.dropout:
             mask[i] = 1 / (1 - self.dropout)
     return mask
Пример #2
0
def get_soup_from_url(url):
    """ Return BeautifulSoup data from a URL using URLLib.
    """

    log = getLogger(__name__)
    soup = None

    log.debug('Getting BS4 from: %s', url)
    try:
        with urllib.request.urlopen(url) as response:
            soup = BeautifulSoup(response.read(), 'html5lib')

    except (urllib.error.HTTPError, urllib.error.URLError) as ex:
        log.debug('URLLib Error, no data collected: %s', ex)

    sleep(rfloat(SLEEP_MIN, SLEEP_MAX))
    return soup
Пример #3
0
def get_soup_from_selenium(url, driver, wait_for_captcha=False):
    """ Return BeautifulSoup data from a URL using Selenium.
    """

    log = getLogger(__name__)

    log.debug('Getting BS4 via Selenium from: %s', url)
    driver.get(url)

    # Check for CAPTCHA
    if wait_for_captcha and '/sorry/' in driver.current_url:
        log.error('CAPTCHA detected! Waiting for human...')
        while '/sorry/' in driver.current_url:
            sleep(SLEEP_SHORT)
        log.info('CAPTCHA cleared.')

    soup = BeautifulSoup(driver.page_source, 'html5lib')
    sleep(rfloat(SLEEP_MIN, SLEEP_MAX))
    return soup
Пример #4
0
def get_json_from_url(url):
    """ Return JSON data from a URL using URLLib.
    """

    log = getLogger(__name__)
    json_data = None

    log.debug('Getting JSON from: %s', url)
    try:
        with urllib.request.urlopen(url) as response:
            json_data = json.loads(response.read())

    except (urllib.error.HTTPError, urllib.error.URLError) as ex:
        log.debug('URLLib Error, no data collected: %s', ex)
    except (json.decoder.JSONDecodeError) as ex:
        log.warning('JSON Error, no data collected: %s', ex)

    sleep(rfloat(SLEEP_MIN, SLEEP_MAX))
    return json_data
Пример #5
0
 def __init__(self):  # __init__: 생성자 / self: 해당 인스턴스가 불려온 것
     self.x, self.y = rint(100, 700), rint(100, 500)
     self.img = load_image('./Resources/Images/run_animation.png')
     self.dx = rfloat()
     self.fidx = rint(0, 7)
Пример #6
0
 def __init__(self):#생성자
     #self.x, self.y = get_canvas_width() // 2, 85
     self.x,self.y = rint(100,700),rint(100,500)
     self.image=load_image('../res/run_animation.png')
     self.dx = rfloat()
     self.frame = rint(0,7)
Пример #7
0
 def __init__(self):
     self.x = rint(100, 600)
     self.y = rint(100, 600)
     self.image = load_image('../res/run_animation.png')
     self.dx = rfloat()
     self.frame = rfloat(0, 7)
Пример #8
0
                print(tur.name, "win the race!")
                tur.turtlesize(2.5, 2.5)
        print("The winning score is", max_score)
        return True
    return False


def run():
    if check_winner():
        t.update()
        return
    for tur in NinjaTurtle.all_ninjas:
        tur.move()
    t.update()
    t.ontimer(run, 10)


t.title("Teenage Mutant Ninja Turtles Race for Pizza!")
t.addshape("pizza.gif")
t.tracer(False)

for i in range(50):
    PizzaTurtle("pizza.gif")
for i in range(100):
    NinjaTurtle(f"#{i+1}", color=(rfloat(), rfloat(), rfloat()))

t.onkeypress(t.bye)
t.listen()
run()
t.mainloop()