Ejemplo n.º 1
0
def runner(console: Console, shutdownEvent: Event, headless: bool, user: dict,
           proxy: dict, playlist: str, vnc: bool, sqsEndpoint: str,
           screenshotDir: str, runnerStats: Array, processStates: Array):
    tid = current_process().pid
    console.log('#%d Start' % tid)
    driver = None
    vdisplay = None
    x11vnc = None
    userDataDir = None
    spotify = None
    try:
        if headless == False:
            width = 1280
            height = 1024
            if 'windowSize' in user:
                [width, height] = user['windowSize'].split(',')
            vdisplay = Xvfb(width=width,
                            height=height,
                            colordepth=24,
                            tempdir=None,
                            noreset='+render')
            vdisplay.start()
            if vnc:
                x11vnc = X11vnc(vdisplay)
                x11vnc.start()

        driverManager = DriverManager(console, shutdownEvent)
        driverData = driverManager.getDriver(type='chrome',
                                             uid=tid,
                                             user=user,
                                             proxy=proxy,
                                             headless=headless)
        del driverManager
        collect()
        if not driverData or not driverData['driver']:
            if vdisplay:
                vdisplay.stop()
            if x11vnc:
                x11vnc.stop()
            raise Exception('No driver was returned from adapter')

        driver = driverData['driver']
        userDataDir = driverData['userDataDir']
    except Exception as e:
        runnerStats[STAT_DRIVER_NONE] += 1
        console.exception('Driver unavailable')
    else:
        try:
            spotify = Adapter(driver, console, shutdownEvent)
            console.log('#%d Start create account for %s' %
                        (tid, user['email']))
            spotify.register(user)
            try:
                boto3.client('sqs').send_message(
                    QueueUrl=sqsEndpoint,
                    MessageBody=dumps({
                        'user': user,
                        'playlist': playlist
                    }),
                    DelaySeconds=1,
                )
            except:
                console.exception('#%d Failed to send message to the queue' %
                                  tid)
            else:
                console.log('#%d Account created for %s' %
                            (tid, user['email']))
                runnerStats[STAT_ACCOUNT_CREATED] += 1
        except Exception as e:
            runnerStats[STAT_ERROR] += 1
            try:
                id = randint(10000, 99999)
                with open(screenshotDir + ('%d.log' % id), 'w') as f:
                    f.write(str(e))
                driver.save_screenshot(screenshotDir + ('%d.png' % id))
            except:
                console.exception()
    if driver:
        try:
            driver.quit()
            del driver
        except:
            pass
    if spotify:
        try:
            del spotify
        except:
            pass
    if userDataDir:
        try:
            rmtree(path=userDataDir, ignore_errors=True)
        except:
            pass
    if x11vnc:  #Terminate vnc server if any
        try:
            x11vnc.stop()
            del x11vnc
        except:
            pass
    if vdisplay:
        try:
            vdisplay.stop()
            del vdisplay
        except:
            pass
    console.log('#%d Stop' % tid)
    collect()
Ejemplo n.º 2
0
    lock = Lock()
    config.LISTENER_MAX_PROCESS = 1
    config.LISTENER_MAX_THREAD = 1
    config.LISTENER_SPAWN_INTERVAL = 1
    shutdownEvent = Event()

    lpc = ListenerContext(
        messagesCount=messagesCount,
        threadsCount=threadsCount,
        channel=0,
        config = config,
        maxThread=1,
        shutdownEvent=shutdownEvent,
        console=console,
        lock=lock,
        vnc=True,
        headless=False,
        batchId= 1
    )

    lp = Listener(lpc)
    lp.start()
    
    while lp.is_alive():
        try:
            sleep(1)
        except KeyboardInterrupt:
            shutdownEvent.set()
        except:
            console.exception()
Ejemplo n.º 3
0
def run(console: Console, shutdownEvent: Event, headless: bool, user: dict,
        proxy: dict, playlist: str, vnc: bool, screenshotDir, stats: Array,
        states: Array):

    tid = current_process().pid
    console.log('#%d Start' % tid)

    driver = None
    try:
        if shutdownEvent.is_set():
            return
        vdisplay = None
        x11vnc = None
        if headless == False:
            width = 1280
            height = 1024
            if 'windowSize' in user:
                [width, height] = user['windowSize'].split(',')
            vdisplay = Xvfb(width=width,
                            height=height,
                            colordepth=24,
                            tempdir=None,
                            noreset='+render')
            vdisplay.start()
            if vnc:
                x11vnc = X11vnc(vdisplay)
                x11vnc.start()

        driverManager = DriverManager(console, shutdownEvent)
        driverData = driverManager.getDriver(type='chrome',
                                             uid=tid,
                                             user=user,
                                             proxy=proxy,
                                             headless=headless)
        if not driverData:
            raise Exception('No driverData was returned from adapter')
        driver = driverData['driver']
        userDataDir = driverData['userDataDir']
        if not driver:
            raise Exception('No driver was returned from adapter')

    except:
        stats[STAT_DRIVER_NONE] += 1
        console.exception('Driver unavailable')
    else:
        try:
            spotify = Adapter(driver, console, shutdownEvent)
            spotify.login(user['email'], user['password'])
            stats[STAT_LOGGED_IN] += 1
            console.log('#%d Logged In' % tid)
            spotify.playPlaylist(playlist, shutdownEvent, 80, 100)
            console.log('#%d Played' % tid)
            stats[STAT_PLAYED] += 1
        except Exception as e:
            stats[STAT_ERROR] += 1
            try:
                id = randint(10000, 99999)

                with open(screenshotDir + ('%d.log' % id), 'w') as f:
                    f.write(str(e))
                driver.save_screenshot(screenshotDir + ('%d.png' % id))
            except:
                console.exception()

    if driver:
        try:
            driver.quit()
            del driver
        except:
            pass
    if userDataDir:
        try:
            rmtree(path=userDataDir, ignore_errors=True)
        except:
            pass
    if x11vnc:  #Terminate vnc server if any
        try:
            x11vnc.stop()
            del x11vnc
        except:
            pass
    if vdisplay:
        try:
            vdisplay.stop()
            del vdisplay
        except:
            pass
    collect()