Exemple #1
0
def run():
    while True:
        try:
            logger.info(f'Начало')

            assigned_open_issues_per_project = get_assigned_open_issues_per_project(
            )
            logger.info('Всего задач: %s\n\n%s\n',
                        sum(assigned_open_issues_per_project.values()),
                        get_table(assigned_open_issues_per_project))

            ok = db.add(assigned_open_issues_per_project)
            if ok is None:
                logger.info(
                    "Количество открытых задач в проектах не поменялось. Пропускаю..."
                )
            elif ok:
                logger.info("Добавляю запись")
            else:
                logger.info("Сегодня запись уже была добавлена. Пропускаю...")

            logger.info('\n' + '-' * 100 + '\n')
            break

        except Exception:
            logger.exception('Ошибка:')

            logger.info('Через 15 минут попробую снова...')
            wait(minutes=15)
Exemple #2
0
def load_cookies(flag=2):
    '''选择载入cookies方式,默认为本地载入'''
    assert flag in [
        0, 1, 2
    ], u'flag=0表示从本地载入cookies,flag=1表示从网络载入cookies,flag=2表示用户选择从网络还是本地载入cookies'

    if flag == 2:

        message = u'load cookies from internet please input any key\nfrom location please click ENTER key:'
        p = wait(timeout=5, message=message)

        if p:
            cookies = login()
            d = cookies_to_dict(cookies)
            write_cookies(cookies=d)
        else:
            cookies = read_cookies()

    elif flag == 1:
        cookies = login()
        d = cookies_to_dict(cookies)
        write_cookies(cookies=d)

    elif flag == 0:
        d = read_cookies()

    assert isinstance(
        d, dict), u'cookies must be dict,now cookies is :%s' % (type(d))

    return d
Exemple #3
0
def load_cookies(flag=2):
    '''选择载入cookies方式,默认为本地载入'''
    assert flag in [
        0, 1, 2
    ], u'flag=0表示从本地载入cookies,flag=1表示从网络载入cookies,flag=3表示用户选择从网络还是本地载入cookies'

    if flag == 2:

        message = u'load cookies from internet please input any key\nfrom location please click ENTER key:'
        p = wait(timeout=5, message=message)

        if p:
            cookies = login()
            write_cookies(cookies=cookies)
        else:
            cookies = read_cookies()

    elif flag == 1:
        cookies = login()
        write_cookies(cookies=cookies)

    elif flag == 0:
        cookies = read_cookies()

    return cookies
Exemple #4
0
def load_cookies(flag=2, cookiesjar=None):
    '''选择载入cookies方式,默认为本地载入'''

    assert flag in [
        0, 1, 2
    ], u'flag=0表示从本地载入cookies,flag=1表示从网络载入cookies,flag=2表示用户选择从网络还是本地载入cookies'

    if flag == 2:

        message = u'load cookies from internet please input any key\nfrom location please click ENTER key:'
        p = wait(timeout=5, message=message)

        if p:
            cookies = cookiesjar_to_dict(cookiesjar=cookiesjar)
            write_cookies(cookies=cookies)
        else:
            cookies = read_cookies()

    elif flag == 1:

        cookies = cookiesjar_to_dict(cookiesjar=cookiesjar)
        write_cookies(cookies=cookiesjar)

    elif flag == 0:
        cookies = read_cookies()

    assert isinstance(
        cookies, dict
    ), u'cookies must be dict.now get type(cookies) is:' % type(cookies)
    print cookies
    return cookies
Exemple #5
0
def login(flag='pc'):
    '''selenium 模拟登陆'''

    assert flag in ['pc', 'm']

    options = webdriver.ChromeOptions()
    # 设置中文
    options.add_argument('lang=zh_CN.UTF-8')
    # 更换头部
    options.add_argument(
        'user-agent=Mozilla/5.0 (Windows; U; Windows NT 5.2) Gecko/2008070208 Firefox/3.0.1'
    )
    driver = webdriver.Chrome(chrome_options=options)

    if flag == 'm':
        login_url = 'https://passport.weibo.cn/signin/login'

    elif flag == 'pc':
        login_url = 'https://login.sina.com.cn/signup/signin.php'

    driver.get(login_url)
    print u'sleep 2 second wait frame load successfully'
    time.sleep(2)

    if flag == 'm':

        email = driver.find_element_by_id('loginName')
        password = driver.find_element_by_id('loginPassword')
        button = driver.find_element_by_id('loginAction')

    elif flag == 'pc':

        email = driver.find_element_by_xpath('//*[@id="username"]')
        password = driver.find_element_by_xpath('//*[@id="password"]')
        button = driver.find_element_by_xpath(
            '//*[@id="vForm"]/div[2]/div/ul/li[7]/div[1]/input')

    email.send_keys(username)
    password.send_keys(pwd)

    button.click()

    # r=raw_input(u'if login success,please type any word:')
    message = u'wait 5 second for user choice:'
    p = wait(timeout=5, message=message)
    cookies = driver.get_cookies()

    driver.quit()

    return cookies
Exemple #6
0
def is_element_present(self, element_name, just_in_dom=False, timeout=0):
    def _get_driver():
        try:
            driver = getattr(self, '_driver')
        except AttributeError:
            driver = getattr(self, 'parent', None)
        if driver:
            return driver
        return get_driver()

    _get_driver().implicitly_wait(timeout)
    try:

        def is_displayed():
            try:
                element = getattr(self, element_name)
            except AttributeError:
                raise WebiumException(
                    'No element "{0}" within container {1}'.format(
                        element_name, self))
            if isinstance(element, list):
                if element:
                    return all(ele.is_displayed() for ele in element)
                else:
                    return False
            return element.is_displayed()

        is_displayed() if just_in_dom else wait(lambda: is_displayed(),
                                                timeout_seconds=timeout)
        return True
    except WebDriverException:
        return False
    except TimeoutExpired:
        return False
    finally:
        _get_driver().implicitly_wait(settings.implicit_timeout)
def run_notification_job(
    log__or__log_name: Union['logging.Logger', str],
    file_name_items: str,
    get_new_items: Callable[[], List[str]],
    notified_by_sms=True,
    timeout={'weeks': 1},
    timeout_exception_seconds=5 * 60,
    format_first_start_detected='Обнаружен первый запуск',
    format_current_items='Текущий список (%s): %s',
    format_get_items='Запрос списка',
    format_items='Список (%s): %s',
    format_new_item='Появился новый элемент "%s"',
    format_no_new_items='Новых элементов нет',
    format_on_exception='Ошибка:',
    format_on_exception_next_attempt='Через 5 минут попробую снова...',
):
    log = log__or__log_name
    if isinstance(log, str):
        log = get_logger(log)

    def save_items(items: List[str]):
        with open(file_name_items, mode='w', encoding='utf-8') as f:
            import json
            json.dump(items, f, ensure_ascii=False, indent=4)

    def read_items() -> List[str]:
        try:
            with open(file_name_items, encoding='utf-8') as f:
                import json
                obj = json.load(f)

                # Должен быть список, но если в файле будет что-то другое -- это будет неправильно
                if not isinstance(obj, list):
                    return []

                return obj

        except:
            return []

    FILE_NAME_SKIP = Path('skip')

    # Загрузка текущего списка из файла
    current_items = read_items()
    log.debug(format_current_items, len(current_items), current_items)

    while True:
        if FILE_NAME_SKIP.exists():
            log.info('Обнаружен файл "%s", пропускаю проверку.', FILE_NAME_SKIP.name)
            wait(**timeout)
            continue

        try:
            log.debug(format_get_items)

            items = get_new_items()
            log.debug(format_items, len(items), items)

            # Если текущих список пустой
            if not current_items:
                log.debug(format_first_start_detected)

                current_items = items
                save_items(current_items)

            else:
                new_items = set(items) - set(current_items)
                if new_items:
                    current_items = items
                    save_items(current_items)

                    for item in new_items:
                        text = format_new_item % item
                        log.debug(text)

                        if notified_by_sms:
                            simple_send_sms(text, log)

                else:
                    log.debug(format_no_new_items)

            wait(**timeout)

        except:
            log.exception(format_on_exception)
            log.debug(format_on_exception_next_attempt)

            # Wait <timeout_exception_seconds> before next attempt
            import time
            time.sleep(timeout_exception_seconds)
                        to=TO,
                        text="Вышла новая серия '{}'".format(torrent['info']['name'])
                    )
                    rs = requests.get(url)
                    print(rs.text)

                    # Даем 5 секунд на добавление торрента в клиент
                    import time
                    time.sleep(5)

                    remove_previous_torrent_from_qbittorrent(qb, info_hash)

                else:
                    print('Изменений нет')

            print()

            # Every 3 hours
            wait(hours=3)

        except Exception:
            import traceback
            print('Ошибка:')
            print(traceback.format_exc())

            print('Через 5 минут попробую снова...')

            # Wait 1 minute before next attempt
            import time
            time.sleep(60)
Exemple #9
0
from wait import wait

DEVICE = '00:0C:8A:67:96:90'
DEVICE = DEVICE.replace(':', '_')

index = 0

bus = SystemBus()

proxy_power = bus.get_object('org.bluez', '/org/bluez/hci0')
interface_power = Interface(proxy_power, dbus_interface='org.freedesktop.DBus.Properties')

while not interface_power.Get('org.bluez.Adapter1', 'Powered'):
    interface_power.Set('org.bluez.Adapter1', 'Powered', True)
    index = wait(index, text='powering')
else:
    print('\nInterface powered')

proxy_connected = bus.get_object('org.bluez', '/org/bluez/hci0/dev_{}'.format(DEVICE))
interface_connected = Interface(proxy_connected, dbus_interface='org.freedesktop.DBus.Properties')

while not interface_connected.Get('org.bluez.Device1', 'Connected'):
    interface_connect = Interface(proxy_connected, dbus_interface='org.bluez.Device1')
    try:
        interface_connect.Connect()
        index = wait(index, text='connecting')
    except DBusException as e:
        index = wait(index, text=e.get_dbus_message())
else:
    print('\nDevice connected')
    from common import *
    init_db()

    while True:
        try:
            news_from_games = get_news_from_rss(
                'https://news.yandex.ru/games.rss')
            print('games', news_from_games)
            append_list_news(news_from_games, interest='games')

            news_from_movies = get_news_from_rss(
                'https://news.yandex.ru/movies.rss')
            print('movies', news_from_movies)
            append_list_news(news_from_movies, interest='movies')

            wait(minutes=4)

        except Exception:
            import traceback
            print('Ошибка:')
            print(traceback.format_exc())

            print('Через 5 минут попробую снова...')

            # Wait 5 minutes before next attempt
            import time
            time.sleep(5 * 60)

    # news_list = get_news_list_and_mark_as_read(interest='games')
    # print(news_list)
    #
Exemple #11
0
from wait import wait
from get_stackoverflow_people_reached import get_stackoverflow_people_reached

from db import PeopleReached, db_create_backup

URL = 'https://ru.stackoverflow.com/users/201445/gil9red'

while True:
    print(f'Started at {DT.datetime.now():%d/%m/%Y %H:%M:%S}\n')

    db_create_backup()

    try:
        value = get_stackoverflow_people_reached(URL)
        print(f'URL: {URL}\n     {value}\n')

        PeopleReached.append(URL, value)

        wait(weeks=1)

    except Exception as e:
        # Выводим ошибку в консоль
        import traceback
        tb = traceback.format_exc()
        print(tb)

        print('Wait 15 minutes')
        wait(minutes=15)

    print()
                paused = False
                print("Resuming...")
                time.sleep(1)
                print("")
            else:
                print("Pausing...")
                paused = True
                time.sleep(1)

        if "G" in keys:
            save_training_batch(training_data, batch_number)
            break


if __name__ == "__main__":
    wait(4)
    train_ai()
    print(get_latest_batch())
    # file_name = TRAINING_DATA_PATH
    #
    # if os.path.isfile(file_name):
    #     print('File already exists, loading previous data')
    #     training_data = list(np.load(file_name))
    #     print(len(training_data))
    # else:
    #     print('Creating a new file ' + file_name)
    #     training_data = list()
    # batch_number = get_latest_batch()
    # for i in range(5):
    #     save_training_batch(training_data[:1000], batch_number)
    #     batch_number += 1
Exemple #13
0
def start():
    global g_stop_loop
    console.log.info("application started...")
    # tasks
    capacity = 90
    queue_name = "ATI"
    tm = task_manager(capacity, queue_name)
    thread_gap = wait(1, 8)
    task_gap = wait(1, 8)
    task_ready = False
    # pptp
    pm = pptp_manager("default")
    pptp_account_gap = wait(1, 8)
    pptp_account_ready = False
    pptp_link_gap = wait(1, 8)
    pptp_link_ready = False
    pptp_route_gap = wait(1, 8)
    pptp_route_ready = False
    while not g_stop_loop:
        if len(tm.threads) > 0:
            console.log.debug(
                "there has running task not finished, waiting...")
            thread_gap.wait()
            continue
        thread_gap.reset()
        if not task_ready:
            tm.receive_tasks()
            if len(tm.tasks) == 0:
                console.log.debug("no task right now, waiting...")
                task_gap.wait()
                continue
            task_ready = True
            pm.stop_pptp_link()
            pptp_account_ready = False
            task_gap.reset()
        if not pptp_account_ready:
            ok = pm.update_pptp_account()
            if not ok:
                console.log.debug("no pptp account, waiting...")
                pptp_account_gap.wait()
                continue
            pptp_account_ready = True
            pptp_link_ready = False
            pptp_account_gap.reset()
        if not pptp_link_ready:
            ok = pm.start_pptp_link()
            if not ok:
                console.log.debug("no pptp link, waiting...")
                pptp_link_gap.wait()
                if pptp_link_gap.count > 3:
                    pptp_account_ready = False
                continue
            pptp_link_ready = True
            pptp_route_ready = False
            pptp_link_gap.reset()
        if not pptp_route_ready:
            ok = pm.set_route()
            if ok:
                ok = pm.check_route()
                if not ok:
                    console.log.debug("no route via pptp, waiting...")
                    pptp_route_gap.wait()
                    continue
            pptp_route_ready = True
            pptp_route_gap.reset()
        tm.execute_tasks()
        task_ready = False
    console.log.info("application stopped...")
Exemple #14
0
                    text += 'First price'
                else:
                    if is_change_dns and is_change_technopoint:
                        text += 'DNS and Technopoint'
                    elif is_change_dns:
                        text += 'DNS'
                    else:
                        text += 'Technopoint'
                print(text)

                product.append_price(current_url_price_dns, current_url_price_technopoint)

            print()

            checked_products.append(product_data)

            time.sleep(5)  # 5 seconds

        wait(days=1)

    except Exception as e:
        # Выводим ошибку в консоль
        import traceback
        tb = traceback.format_exc()
        print(tb)

        print('Wait 15 minutes')
        time.sleep(15 * 60)  # 15 minutes

    print()
Exemple #15
0
                    number += 1

                    print(number)

                message = "Cycle commit #{}".format(number)

            # Обновление значения
            with open(new_file_name, 'w') as f:
                f.write(str(number))

            print(message)
            repo.index.add([new_file_name])
            repo.index.commit(message)

        except Exception as e:
            print(e)
            time.sleep(30)

        while True:
            try:
                repo.remotes.origin.push()
                print('Finish push')
                break

            except Exception as e:
                print(e)
                time.sleep(30)

        # Every 1 hour
        wait(hours=1)