Example #1
0
def notify_game(match, game_notified):
    print(f'GAME NOTIFY {match["match_id"]}')
    email = BaseEmail(
        '*****@*****.**',
        RECIPIENTS,
        f'{match["match_id"]} GAME FINISHED',
        json.dumps(match, indent=2),
    )
    try:
        email.send()
    except smtplib.SMTPSenderRefused:
        BaseEmail.connect()
        BaseEmail._server.login('*****@*****.**', 'Tennis2020')
        email.send()
    game_notified.append([match['match_id'], datetime.datetime.now()])
    write_csv('game_notified.csv', game_notified)
Example #2
0
def notify_onebox(match_id, onebox_notified):
    print(f'ONEBOX NOTIFY {match_id}')
    email = BaseEmail(
        '*****@*****.**',
        RECIPIENTS,
        f'{match_id} ONEBOX UP',
        f'{match_id} just appeared on one box: {TENNIS_URL}',
    )
    try:
        email.send()
    except smtplib.SMTPSenderRefused:
        BaseEmail.connect()
        BaseEmail._server.login('*****@*****.**', 'Tennis2020')
        email.send()
    onebox_notified.append([match_id, datetime.datetime.now()])
    write_csv('onebox_notified.csv', onebox_notified)
def main():
    day = input('Day: ')
    driver = Driver()
    driver.login('flangton', 'jcQX3boISY9h')

    data = read_day_csv(day)[1:]
    data = read_csv(f'Output/Clipro day {day}.csv')[1:]

    files = os.listdir(f'Output/Day {day}')
    for (a1, a2, a3, a4, a5, match_id, t1_p1_l, t1_p1_f, a6, t1_p2_f, t1_p2_l,
         a7, t2_p1_l, t2_p1_f, a8, t2_p2_f, t2_p2_l, a9, a11, a12, photo_link,
         wp_link) in data:
        if wp_link or not photo_link:
            output_data.append([
                a1, a2, a3, a4, a5, match_id, t1_p1_l, t1_p1_f, a6, t1_p2_f,
                t1_p2_l, a7, t2_p1_l, t2_p1_f, a8, t2_p2_f, t2_p2_l, a9, a11,
                a12, photo_link, wp_link
            ])
            continue

        file = f'{match_id}.png'
        filepath = f'Output/Day {day}/{file}'
        r = requests.get(photo_link)
        with open(filepath, 'wb') as f:
            f.write(r.content)
            print(f'{match_id}.png downloaded')

        r = requests.get(f'https://www.tennis.com.au/doc/ao2021-{match_id}')
        if r.status_code == 200:
            driver.update_doc(match_id, filepath, day)
        elif r.status_code == 404:
            driver.new_doc(match_id, filepath, day)
        link = driver.get_link()

        output_data.append([
            a1, a2, a3, a4, a5, match_id, t1_p1_l, t1_p1_f, a6, t1_p2_f,
            t1_p2_l, a7, t2_p1_l, t2_p1_f, a8, t2_p2_f, t2_p2_l, a9, a11, a12,
            photo_link, link
        ])

    write_csv(f'Output/Wordpress day {day}.csv', output_data)
def exit_handler():
    write_csv('output_wp_crashed.csv', output_data)
        filepath = os.path.abspath(filepath)
        file_input = self.driver.find_element_by_id('ta_uploaded_document')
        file_input.send_keys(filepath)
        time.sleep(1)

        self.publish()

    def publish(self):
        button = self.find_element_by_xpath('//*[@id="publish"]')
        button.click()
        time.sleep(10)

    def get_link(self):
        link_elem = self.find_element_by_xpath('//*[@id="sample-permalink"]/a')
        link = link_elem.get_attribute('href')
        return str(link)


def exit_handler():
    write_csv('output_wp_crashed.csv', output_data)


if __name__ == '__main__':
    atexit.register(exit_handler)
    try:
        new_main()
    except Exception as e:
        print(e, file=sys.stderr)
        write_csv('output_wp_crashed.csv', output_data)
        raise (e)
Example #6
0
def main():
    day = input("Day: ")

    driver = Driver()
    driver.login('TAadmin', 'TA2020_x4t')

    # day = 2
    # round_ = (int(day) + 1) // 2

    with open('mappings.json') as f:
        mappings = json.load(f)

    files = [str(f) for f in os.listdir('imgs')]
    try:
        os.mkdir(f'Output/Day {day}')
    except FileExistsError:
        pass

    data = read_day_csv(day)[1:]
    for (a1, a2, a3, a4, a5, match_id, t1_p1_l, t1_p1_f, a6, t1_p2_f, t1_p2_l,
         a7, t2_p1_l, t2_p1_f, a8, t2_p2_f, t2_p2_l, a9, a11, a12, photo_link,
         wp_link) in data:
        t1, t2 = (t1_p1_l, t1_p1_f, t1_p2_l, t1_p2_f), (t2_p1_l, t2_p1_f,
                                                        t2_p2_l, t2_p2_f)
        if photo_link or wp_link:
            output_data.append([
                a1, a2, a3, a4, a5, match_id, t1_p1_l, t1_p1_f, a6, t1_p2_f,
                t1_p2_l, a7, t2_p1_l, t2_p1_f, a8, t2_p2_f, t2_p2_l, a9, a11,
                a12, photo_link, wp_link
            ])
            continue
            # continue
        try:
            driver.create_graphic()
            ask = False
            t1_img_name = get_image_by_name(t1, files, mappings, ask=ask)
            t2_img_name = get_image_by_name(t2, files, mappings, ask=ask)
            time.sleep(5)

            if t1_img_name is None or t2_img_name is None:
                output_data.append([
                    a1, a2, a3, a4, a5, match_id, t1_p1_l, t1_p1_f, a6,
                    t1_p2_f, t1_p2_l, a7, t2_p1_l, t2_p1_f, a8, t2_p2_f,
                    t2_p2_l, a9, a11, a12,
                    'https://www.tennis.com.au/doc/ao2021-placeholder', None
                ])
                continue

            driver.input_by_xpath(
                '//*[@id="App"]/div[2]/div/div[5]/div/div[2]/div/div[1]/input',
                t1_p1_l)

            driver.input_by_xpath(
                '//*[@id="App"]/div[2]/div/div[5]/div/div[2]/div/div[2]/input',
                t2_p1_l)

            round_ = match_id[2]
            driver.input_by_xpath(
                '//*[@id="App"]/div[2]/div/div[5]/div/div[2]/div/div[3]/input',
                f'Round {round_}')

            driver.input_file_by_xpath(
                '//*[@id="App"]/div[2]/div/div[6]/div[1]/div/div[2]/div/div[1]/div[2]/button',
                t1_img_name)
            driver.input_file_by_xpath(
                '//*[@id="App"]/div[2]/div/div[6]/div[1]/div/div[2]/div/div[2]/div[2]/button',
                t2_img_name)
            time.sleep(20)

            driver.click_by_xpath(
                '//*[@id="App"]/div[2]/div/div[6]/div[2]/button[2]')
            time.sleep(20)

            elem = driver.find_element_by_xpath(
                '//*[@id="App"]/div[2]/div/div[2]/div[2]/div/div[2]/div[1]/div/img'
            )
            url = elem.get_attribute('src')

        except selenium.common.exceptions.TimeoutException as e:
            url = None
            print(e, file=sys.stderr)

        output_data.append([
            a1, a2, a3, a4, a5, match_id, t1_p1_l, t1_p1_f, a6, t1_p2_f,
            t1_p2_l, a7, t2_p1_l, t2_p1_f, a8, t2_p2_f, t2_p2_l, a9, a11, a12,
            url, None
        ])

    write_csv(f'Output/Clipro day {day}.csv', output_data)

    with open('mappings.json', 'w') as f:
        json.dump(mappings, f)
Example #7
0
def new_main():
    day = input("Day: ")

    driver = Driver()
    driver.login('TAadmin', 'TA2020_x4t')

    # day = 2
    # round_ = (int(day) + 1) // 2

    with open('mappings.json') as f:
        mappings = json.load(f)

    with open('clipro_links.json') as f:
        clipro_links = json.load(f)

    with open('wp_links.json') as f:
        wp_links = json.load(f)

    files = [str(f) for f in os.listdir('imgs')]
    try:
        os.mkdir(f'Output/Day {day}')
    except FileExistsError:
        pass

    data = get_matches(day)
    for match in data.values():
        if not ('WS' in match['match_id'] or 'MS' in match['match_id']):
            continue

        t1_p1_l, t1_p1_f = match['players'][0][0]['last_name'], match[
            'players'][0][0]['first_name']
        try:
            t1_p2_l, t1_p2_f = match['players'][0][1]['last_name'], match[
                'players'][0][1]['first_name']
        except IndexError:
            t1_p2_l, t1_p2_f = None, None
        t2_p1_l, t2_p1_f = match['players'][1][0]['last_name'], match[
            'players'][1][0]['first_name']
        try:
            t2_p2_l, t2_p2_f = match['players'][1][1]['last_name'], match[
                'players'][1][1]['first_name']
        except IndexError:
            t2_p2_l, t2_p2_f = None, None

        t1, t2 = (t1_p1_l, t1_p1_f, t1_p2_l, t1_p2_f), (t2_p1_l, t2_p1_f,
                                                        t2_p2_l, t2_p2_f)

        photo_link = clipro_links.get(match['match_id'], None)
        wp_link = wp_links.get(match['match_id'], None)

        if photo_link or wp_link:
            output_data.append([
                match['match_id'], t1_p1_l, t1_p1_f, t1_p2_f, t1_p2_l, t2_p1_l,
                t2_p1_f, t2_p2_f, t2_p2_l, photo_link, wp_link
            ])
            continue
        try:
            driver.create_graphic()
            ask = False
            t1_img_name = get_image_by_name(t1, files, mappings, ask=ask)
            t2_img_name = get_image_by_name(t2, files, mappings, ask=ask)
            time.sleep(5)

            if t1_img_name is None or t2_img_name is None:
                output_data.append([
                    match['match_id'], t1_p1_l, t1_p1_f, t1_p2_f, t1_p2_l,
                    t2_p1_l, t2_p1_f, t2_p2_f, t2_p2_l,
                    'https://www.tennis.com.au/doc/ao2021-placeholder', None
                ])
                continue

            # Left name
            driver.input_by_xpath(
                '//*[@id="App"]/div[2]/div/div[5]/div/div[2]/div/div[1]/input',
                t1_p1_l)

            # Right name
            driver.input_by_xpath(
                '//*[@id="App"]/div[2]/div/div[5]/div/div[2]/div/div[2]/input',
                t2_p1_l)

            # Round
            round_ = get_round(match['match_id'])
            driver.input_by_xpath(
                '//*[@id="App"]/div[2]/div/div[5]/div/div[2]/div/div[3]/input',
                f'{round_}')

            # Left player image
            driver.click_by_xpath(
                '//*[@id="App"]/div[2]/div/div[6]/div[1]/div/div[2]/div/div[1]/div[2]/span/button'
            )
            driver.input_by_xpath(
                '//*[@id="poppers"]/div/div/input',
                f"https://raw.githubusercontent.com/fraser-langton/ausopen_thumbnails/master/imgs/{urllib.parse.quote(t1_img_name)}"
            )
            driver.click_by_xpath('//*[@id="poppers"]/div/div/button')
            time.sleep(7)
            driver.click_by_xpath(
                '//*[@id="App"]/div[2]/div/div[1]/div/div/div[2]/div[3]/button[2]'
            )

            # Right player image
            driver.click_by_xpath(
                '//*[@id="App"]/div[2]/div/div[6]/div[1]/div/div[2]/div/div[2]/div[2]/span/button'
            )
            driver.input_by_xpath(
                '//*[@id="poppers"]/div/div/input',
                f"https://raw.githubusercontent.com/fraser-langton/ausopen_thumbnails/master/imgs/{urllib.parse.quote(t2_img_name)}"
            )
            driver.click_by_xpath('//*[@id="poppers"]/div/div/button')
            time.sleep(7)
            driver.click_by_xpath(
                '//*[@id="App"]/div[2]/div/div[1]/div/div/div[2]/div[3]/button[2]'
            )

            # driver.input_file_by_xpath(
            #     '//*[@id="App"]/div[2]/div/div[6]/div[1]/div/div[2]/div/div[1]/div[2]/button', t1_img_name)
            # driver.input_file_by_xpath(
            #     '//*[@id="App"]/div[2]/div/div[6]/div[1]/div/div[2]/div/div[2]/div[2]/button', t2_img_name)
            # time.sleep(20)

            time.sleep(4)
            driver.click_by_xpath(
                '//*[@id="App"]/div[2]/div/div[6]/div[2]/button[2]')
            time.sleep(20)

            elem = driver.find_element_by_xpath(
                '//*[@id="App"]/div[2]/div/div[2]/div[2]/div/div[2]/div[1]/div/img'
            )
            url = elem.get_attribute('src')

        except selenium.common.exceptions.TimeoutException as e:
            url = None
            print(e, file=sys.stderr)

        clipro_links[match['match_id']] = url
        with open('clipro_links.json', 'w') as f:
            json.dump(clipro_links, f)

        output_data.append([
            match['match_id'], t1_p1_l, t1_p1_f, t1_p2_f, t1_p2_l, t2_p1_l,
            t2_p1_f, t2_p2_f, t2_p2_l, url, wp_link
        ])

    write_csv(f'Output/Clipro day {day}.csv', output_data)

    with open('mappings.json', 'w') as f:
        json.dump(mappings, f)