Beispiel #1
0
 def __init__(self, shutDownEvent, lock, console: Console, nbrProcess=0, processStartInterval=3, dryRun=False):
     self.shutdownEvent = shutDownEvent
     self.processStartInterval = processStartInterval
     self.console = console
     self.lock = lock
     procCount = multiprocessing.cpu_count()
     if nbrProcess == 0:
         nbrProcess = procCount
     self.tasks = TasksQueue()
     self.nbrProcess = nbrProcess
     self.taskCount = 0
     self.processes = []
     manager = multiprocessing.Manager()
     self.states = manager.dict()
     self.stats = manager.dict()
     self.dryRun = dryRun
     self.startTime = 0.0
     
     console.log('Worker manager found %d cores' % procCount, True, True)
Beispiel #2
0
from multiprocessing import Array, Event, Lock
from src.services.config import Config
from src.services.console import Console
from src.application.spotify.listener import Listener, ListenerContext, TaskContext
from src.services.drivers import DriverManager
from src.services.proxies import ProxyManager, PROXY_FILE_LISTENER
from time import sleep
from sp-listener import runner



if __name__ == '__main__':
    threadsCount = Array('i', 1)
    messagesCount = Array('i', 1)
    console = Console()
    config = Config()
    dm = DriverManager(console, Event())
    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,
Beispiel #3
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()
Beispiel #4
0
        if arg == '--vnc':
            vnc = True

    #Manage log
    logDir = (os.path.dirname(__file__)
              or '.') + '/temp/register/' + datetime.now().strftime(
                  "%m-%d-%Y-%H-%M-%S") + '/'
    logfile = logDir + 'all.log'
    os.makedirs(logDir, exist_ok=True)
    screenshotDir = logDir + 'screenshot/'
    os.makedirs(screenshotDir, exist_ok=True)

    #Util
    shutdownEvent = Event()
    config = Config()
    console = Console(ouput=not noOutput, logfile=logfile)
    proxyRegisterManager = ProxyManager(proxyFile=PROXY_FILE_REGISTER)
    proxyListenerManager = ProxyManager(proxyFile=PROXY_FILE_LISTENER)
    userManager = UserManager(console)
    userAgentManager = UserAgentManager()
    client = boto3.client('sqs')
    systemStats = Stats()
    processes = []
    users = []

    maxProcess = config.REGISTER_MAX_PROCESS
    if maxProcess < 0:
        maxProcess = psutil.cpu_count(logical=True)

    #Process communication
    runnerStats = Array('i', 4)
Beispiel #5
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()
Beispiel #6
0
    headless = False
    vnc = False
    for arg in argv:
        if arg == '--info':
            showInfo = True
        if arg == '--nooutput':
            noOutput = True
        if arg == '--headless':
            headless = True
        if arg == '--vnc':
            vnc = True

    shutdownEvent = Event()
    config = Config()
    processes = []
    console = Console(ouput=not noOutput)
    driverManager = DriverManager(console, shutdownEvent)
    driverVersion = driverManager.getDriverVersion('chrome')
    browserVersion = driverManager.getBrowserVersion('chrome')
    client = boto3.client('sqs')

    totalMessageReceived = 0
    stats = Stats()
    messages = []
    lastProcessStart = 0
    lockThreadsCount = Lock()

    def _showStats():
        showStats(
            {
                'totalProcess': len(processes),
Beispiel #7
0
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from tempfile import mkdtemp
from src.application.spotify import Spotify
from src.services.console import Console
import proxy
import time
from xvfbwrapper import Xvfb
from src.services.x11vncwrapper import X11vnc
from src.services.drivers import DriverManager

import fcntl
import os
import selectors

if __name__ == '__main__':
    console = Console()
    runTest = True
    if runTest:
        pm = ProxyManager(PROXY_FILE_LISTENER)
        proxy = pm.getRandomProxy()
        dm = DriverManager(Console(), Event())
        vdisplay = Xvfb()
        vdisplay.start()
        x11vnc = X11vnc(vdisplay)
        x11vnc.start()
        driverData = dm.getDriver('chrome', 1, {}, proxy, False)
        driver = driverData['driver']

        spotify = Spotify.Adapter(driver, console, Event())
        ip = spotify.getMyIp()
        console.success('%s' % ip)
Beispiel #8
0
from boto3 import client
from time import sleep
from src.services.console import Console
from sys import stdout, argv
from colorama import Fore, Back, Style
from os import get_terminal_size
from traceback import format_exc
from src.services.stats import Stats
console = Console(3, False)


def showStats(data, queueUrl, stats: Stats):
    width, height = get_terminal_size()

    separator = '_' * width
    lines = []
    lines.append(Fore.YELLOW + 'AMAZON SQS SERVICE STATS')
    lines.append('\n')
    lines = lines + stats.getConsoleLines(width)
    lines.append(Fore.CYAN + 'Queue: %s:' % queueUrl)
    lines.append(Fore.BLUE + separator)
    lines.append(Fore.WHITE + 'Available messages: %6d' %
                 int(data['ApproximateNumberOfMessages']))
    lines.append(Fore.WHITE + 'Message in use    : %6d' %
                 int(data['ApproximateNumberOfMessagesNotVisible']))
    lines.append(Fore.BLUE + separator)
    console.clearScreen()
    index = 1
    for line in lines:
        console.printAt(1, index, line)
        index += 1