Example #1
0
async def visit(config):
    service = services.Geckodriver()
    browser = browsers.Firefox(
        **{"moz:firefoxOptions": {
            "args": ["-headless"]
        }})

    logging.info("Hitting url " + config["url"])
    try:
        async with get_session(service, browser) as session:
            await session.delete_all_cookies()
            await session.get(config["url"])

            for k, c in config.get("cookies", {}).items():
                value = c.get("value", "")
                domain = c.get("domain", None)
                path = c.get("path", "/")
                secure = c.get("secure", False)
                await session.add_cookie(k,
                                         value,
                                         path=path,
                                         domain=domain,
                                         secure=secure)

            await session.get(config["url"])
    except Exception as e:
        logging.info("Exception hitting url " + str(config) +
                     " with exception " + e.message)
Example #2
0
class base_jobsite():
    """  Абстрактный базовый класс для классов сайтов с вакансиями.

    Назначение: определить набор методов, которые должны быть созданы в любых дочерних классах

    """

    __metaclass__ = ABCMeta

    if sys.platform.startswith('win'):
        GECKODRIVER = './geckodriver.exe'
    else:
        GECKODRIVER = './geckodriver'

    service = services.Geckodriver(binary=GECKODRIVER)
    browser = browsers.Firefox(firefoxOptions={'args': ['-headless']})

    @abstractmethod
    async def get_links(self):
        """Корутина, получающая ссылки на страницы с вакансиями"""
        pass

    @abstractmethod
    async def get_content(self):
        """Корутина, получающая данные с страницы с вакансиями"""
        pass
async def session(request):
    global time_wait
    config = load_config(request.config.getoption('--config-file'))
    if 'db_path' in config:
        temp_dir = tempfile.gettempdir()
        temp_path = os.path.join(temp_dir, 'tmp_pythonz_db')
        db_path = os.path.abspath(
            os.path.join(os.path.dirname(__file__), config['db_path']))
        if not os.path.isfile(temp_path):
            shutil.copy2(db_path, temp_path)
    if config['browser'] == 'firefox':
        service = services.Geckodriver()
        browser = browsers.Firefox()
    elif config['browser'] == 'chrome':
        service = services.Chromedriver()
        browser = browsers.Chrome()
    else:
        raise ValueError(f"Unrecognized browser {config['browser']}")
    session = await start_session(service, browser, bind=config['base_url'])
    # настройка времени ожидания для каждого потока
    slaveinput = getattr(request.config, 'slaveinput', None)
    if slaveinput is None:  # запуск в 1 поток
        session.time_wait = 0
    else:
        session.time_wait = slaveinput['time_wait']
    try:
        yield session
    finally:
        await stop_session(session)
        if 'db_path' in config:
            if os.path.isfile(temp_path):
                shutil.copy2(temp_path, db_path)
                os.remove(temp_path)
Example #4
0
async def session(app):
    session = await start_session(services.Geckodriver(),
                                  browsers.Firefox(),
                                  bind=app)
    try:
        yield session
    finally:
        await stop_session(session)
Example #5
0
async def hello_world():
    service = services.Geckodriver(binary=GECKODRIVER)
    browser = browsers.Firefox()
    async with get_session(service, browser) as session:
        await session.get("https://images.google.com/")
        search_box = await session.wait_for_element(5, "input[name=q]")
        await search_box.send_keys("Cats")
        await search_box.send_keys(keys.ENTER)
        await asyncio.sleep(10)
    async def link(self, ctx):
        try:
            embed = discord.Embed(description="(1/5) **Starting Process** ...",
                                  color=self.color)
            status = await ctx.send(embed=embed)
            arsenic_session = await start_session(
                services.Geckodriver(),
                browsers.Firefox(),
            )
            embed = discord.Embed(description="(2/5) **Spawned Instance** ...",
                                  color=self.color)
            await status.edit(embed=embed)
            await arsenic_session.get(self.url)
            make_team_btn = await arsenic_session.get_element(
                '#btn-create-team')
            embed = discord.Embed(description="(3/5) **Locating target** ...",
                                  color=self.color)
            await status.edit(embed=embed)
            await make_team_btn.click()
            embed = discord.Embed(
                description="(4/5) **Retrieving Party Link** ...",
                color=self.color)
            await status.edit(embed=embed)
            await asyncio.sleep(
                2
            )  # add a small sleep delay for the party link to load up (a bit risky)
            party_url = await arsenic_session.get_url()
            embed = discord.Embed(
                description=
                f"**Party Link**: {party_url}\nLink Generator will leave in 7 seconds.",
                color=self.color)
            await status.edit(embed=embed)
            await asyncio.sleep(4)  # waits 7 seconds before leaving
            await status.edit(embed=discord.Embed(
                description=
                f"**Party Link**: {party_url}\nLink Generator is leaving soon ...",
                color=self.color))

            await asyncio.sleep(6)  # add more than 3 for extra time
            embed = discord.Embed(
                description=f"**Link Generator left.**\nOld Link: {party_url}",
                color=self.color)
            embed.set_footer(
                text=f"{self.name} requested by {ctx.message.author}",
                icon_url=ctx.author.avatar_url)
            await status.edit(embed=embed)
            StreamLogger.log(
                f'{ctx.message.author} ran {self.name} Command successfully.')
            await stop_session(arsenic_session)
        except Exception as e:
            try:
                await stop_session(arsenic_session)
            except:
                pass
            WarningLogger.log(
                f'{ctx.message.author} ran {self.name} Command unsuccessfully. Raised {e}'
            )
            error_embed = discord.Embed(
                description=
                f"**{self.name}** command did not run as expected.\nPlease log an issue with `{ctx.prefix}issue`",
                color=self.color)
            await ctx.send(embed=error_embed)
Example #7
0
 async def wrapper():
     gecko = services.Geckodriver()
     ff = browsers.Firefox()
     async with RunApp() as base_url, get_session(gecko, ff,
                                                  base_url) as session:
         return await coro(session)