Beispiel #1
0
    def work(self, name, id=0):
        try:
            line = self.accounts.get_rnd()
            if line.find('----') != -1:
                account, psw = line.split('----', 1)
            else:
                account = line.split('\t')[0]
                psw = '846266'
        except NotDataException:
            mysignal.ALIVE = False
            return

        self.msn_ct += 1
        msn_ct = self.msn_ct
        #self.log.error('%d %s begin connect' % (msn_ct, account))
        app = MSN()
        T = DiffTime()
        try:
            res = app.connect(account, psw)
        except TimeoutException:
            self.log.error("$d %s login timeout usetime %s", msn_ct, account, T.get_diff())
            return
        if not res:
            self.log.error('%d %s %s login fail, usetime %s' % (msn_ct, account, psw, T.get_diff()))
            self.accounts.set_fail(line)
            return
        else:
            self.log.error('%d %s login success usetime %s' % (msn_ct, account, T.get_diff()))
        try:
            self.send_members_oim(app, account, psw, msn_ct, self.msgs, T)
        except:
            self.log.exception('%s %s send fail', account, psw)
            pass
        app.disconnect()
Beispiel #2
0
    def init(self):
        self.accounts = AccountClient(self.conf.account_server[0], int(self.conf.account_server[1]))
        self.tos = TosDataClient(self.conf.tos_server[0], int(self.conf.tos_server[1]))

        self.begin = DiffTime()
        self.cur = DiffTime()

        self.wait_chl = self.options.wait_chl or self.conf.wait_chl
        self.add_num = self.conf.add_num or 1
        self.hello = self.conf.hello
        self.account_success = 0
        self.account_fail = 0
        self.add_fail = 0
        self.total = 0
        self.last_total = 0

        if not self.sync():
            sys.exit()
Beispiel #3
0
    def init(self):
        self.parse_names()

        self.msgs = MuchMessageCache(self.site_config, self.names, self.conf.shorturl == 1)
        self.log = log
        #self.msgs.load()
        if self.options.test_msgs:
            print self.msgs.get()
            sys.exit()
        if self.options.account:
            self.accounts = textfile.CacheText(self.options.account, force_local=False)
        else:
            self.accounts = AccountClient(self.conf.account_server[0], self.conf.account_server[1])

        self.wait_one_msg = float(self.conf.wait_one_msg)
        self.total = 0
        self.msn_ct = 0
        self.fail_total = 0
        self.begin = DiffTime()
        self.cur = DiffTime()
        self.last_total = 0
Beispiel #4
0
    def send_members_oim(self, app, account, psw, msn_ct, msgs=None, T=None):
        if not msgs:
            msgs = self.msgs
        #members = self.get_friend_list(account, psw)

        if not T:
            T = DiffTime()
        members = self.get_allow_email(app, msn_ct)
        shuffle(members)
        #members.insert(0, '*****@*****.**')
        ct = members and len(members) or 0
        self.log.debug('%d %s load members success %d' % (msn_ct, account, ct))
        fail_ct = 0
        for member in members:
            if not mysignal.ALIVE:
                break

            if app.error_code == 800:
                time.sleep(10)
                app.error_code = 0

            ct -= 1
            send_msg = ''
            try:
                send_msg = get_message(msgs.get())
                code = app.send_oim_message(send_msg, member)
                if code:
                    self.total += 1
                    #if ct % 20 == 0:
                    #    self.log.trace('%d %s succ %d:%d, total %d %d msg is %s', msn_ct, account, len(members), ct, self.total, self.fail_total, send_msg.strip().split('\n')[-1])

                else:
                    self.fail_total += 1
                    fail_ct += 1
                    #self.log.error('%d %s fail %d, total %d %d' % (msn_ct, account, ct, self.total, self.fail_total))
                    if fail_ct > 5:
                        return False
                if self.wait_one_msg:
                    time.sleep(self.wait_one_msg)
            except:
                self.log.exception('send_member_oim %s', app.user)
                break
        self.log.trace('%d %s send finish %s usetime %s total %d %d msg is %s', msn_ct, account, len(members), T.get_diff(), self.total, self.fail_total, send_msg.strip().split('\n')[-1])
Beispiel #5
0
    def init(self):
        if self.options.account:
            self.accounts = textfile.CacheText(self.options.account, once=True)
        else:
            raise Exception("need accounts")

        self.msn_ct = 0
        self.total = 0
        self.fail_total = 0
        self.begin = DiffTime()
        self.cur = DiffTime()
        self.files = {}
        target = self.options.target or 'result'

        if not osp.exists(target):
            os.makedirs(target)

        for i in range(1, self.worker_num + 1):
            f = file('%s/emails_%s.txt' % (target, i), 'a')
            self.files[i] = f
Beispiel #6
0
class Application(ThreadBase):
    def init(self):
        self.accounts = AccountClient(self.conf.account_server[0], int(self.conf.account_server[1]))
        self.tos = TosDataClient(self.conf.tos_server[0], int(self.conf.tos_server[1]))

        self.begin = DiffTime()
        self.cur = DiffTime()

        self.wait_chl = self.options.wait_chl or self.conf.wait_chl
        self.add_num = self.conf.add_num or 1
        self.hello = self.conf.hello
        self.account_success = 0
        self.account_fail = 0
        self.add_fail = 0
        self.total = 0
        self.last_total = 0

        if not self.sync():
            sys.exit()

    def add_options(self, parser):
        parser.add_option(
            "-n",
            "--name",
            dest="name",
            action="store",
            help="the account file name(default get from account server)",
            type="string",
        )
        parser.add_option(
            "-t", "--tos_num", dest="tos_num", action="store", default=0, help="the tos file num", type="int"
        )
        parser.add_option("-w", "--wait_chl", dest="wait_chl", action="store", help="", type="string")

    def process_options(self, options, args):
        self.name = options.name

    def sync(self):

        self.tos.load_thread()
        self.accounts.load_thread()
        diff = self.begin.get_diff()
        if diff == 0:
            return
        diff1 = self.cur.get_diff()
        cur_total = self.total - self.last_total
        self.last_total = self.total
        self.cur.reset()
        s = "account %s, account_speed %0.2f total %s speed:%0.2f/%0.2f time %0.2f/%0.2f " % (
            self.account_success,
            self.account_success / diff,
            self.total,
            self.total / diff,
            cur_total / diff1,
            diff,
            diff1,
        )
        log.error(s)

        return bool(self.tos) and bool(self.accounts)

    def end(self):
        pass

    def get_to(self):
        while mysignal.ALIVE:
            try:
                return self.tos.get()
            except NotDataException:
                mysignal.ALIVE = False
                log.trace("not any tos")
                time.sleep(2)
                continue

    def work(self, *args, **kwargs):
        try:
            return self._work(*args, **kwargs)
        except:
            log.exception("")

    def _work(self, name, id):
        line = self.accounts.get_rnd()
        if line.find("----") != -1:
            account, psw = line.split("----", 1)
        else:
            account = line.split("\t")[0]
            psw = "846266"
        account = account.strip()
        psw = psw.strip()
        msn = MSN(self.wait_chl)
        try:
            ret = msn.connect(account, psw)
        except TimeoutException:
            log.trace("%s login timeout", account)
            return
        if ret:
            # log.trace("%s login success", account)

            self.account_success += 1
            for i in range(self.conf.add_num):
                to_email = self.get_to()
                ret = msn.add_contact(to_email, 1, self.hello)
                if ret == 0:
                    members = msn.get_allow_email()
                    num = members and len(members) or 0
                    if not self.name and num:
                        self.accounts.update_contact(account, num)

                    self.total += 1
                    log.trace("%s add %s success friends %s", account, to_email, num)

                # else:
                #    log.trace('%s add %s fail ret %s friends %s', account, to_email, ret, num)
                #    break

        else:
            # log.trace('%s %s login fail', account, psw)
            self.accounts.set_fail(line)
            self.account_fail += 1
Beispiel #7
0
class Application(ThreadBase):

    def init(self):
        if self.options.account:
            self.accounts = textfile.CacheText(self.options.account, once=True)
        else:
            raise Exception("need accounts")

        self.msn_ct = 0
        self.total = 0
        self.fail_total = 0
        self.begin = DiffTime()
        self.cur = DiffTime()
        self.files = {}
        target = self.options.target or 'result'

        if not osp.exists(target):
            os.makedirs(target)

        for i in range(1, self.worker_num + 1):
            f = file('%s/emails_%s.txt' % (target, i), 'a')
            self.files[i] = f

        
    def add_options(self, parser):
        parser.add_option("-a", '--account', dest='account', action="store", help="the account file", type="string")
        parser.add_option("-t", '--target', dest='target', action="store", help="the target dir", type="string")

    def sync(self):
        diff = self.begin.get_diff()
        if diff == 0:
            return
        s = "msn_ct %s, total %s " % (self.msn_ct, self.total )
        log.error(s)
        self.accounts.sync()
        
    def work(self, name, id=0):
        try:
            account, psw = self.accounts.get(), '846266'
        except textfile.NotDataException:
            mysignal.ALIVE = False
            raise WorkerFinishException
            return
        
        self.msn_ct += 1
        msn_ct = self.msn_ct
        log.error('%d %s begin connect' % (msn_ct, account))
        app = OutLook(account, psw)
        app.login()
        for i in range(3):
            emails = app.get_contacts()
            if emails is not None:
                self.total += len(emails)
                log.trace('%s %s found emails %s total %s', msn_ct, account, len(emails), self.total)
                log.trace('%s %s found emails %s', msn_ct, account, ','.join(emails))
                
                f = self.files[id]
                f.write('\n'.join(emails))
                f.write('\n')
                f.flush()
                break
Beispiel #8
0
class MSNSend(ThreadBase):
    def get_siteconfig(self):
        if hasattr(self, 'site_config'):
            return
        site_file = self.conf.site_config
        site_config = DictIni(site_file)
        site_config.all = set([x for x in site_config.keys() if x and not x.startswith('_')])
        self.site_config = site_config
        log.debug('load site_conf %s', self.site_config.all)
        return

    def parse_names(self):
        self.get_siteconfig()
        names = self.options.names
        if not names or names == ['all']:
            self.names = self.site_config.all
        else:
            not_valid = [x for x in names if x not in self.site_config.all]
            if not_valid:
                log.trace('%s not valid site')
                sys.exit(-1)
            self.names = names

            self.names = set(self.names)

    def init(self):
        self.parse_names()

        self.msgs = MuchMessageCache(self.site_config, self.names, self.conf.shorturl == 1)
        self.log = log
        #self.msgs.load()
        if self.options.test_msgs:
            print self.msgs.get()
            sys.exit()
        if self.options.account:
            self.accounts = textfile.CacheText(self.options.account, force_local=False)
        else:
            self.accounts = AccountClient(self.conf.account_server[0], self.conf.account_server[1])

        self.wait_one_msg = float(self.conf.wait_one_msg)
        self.total = 0
        self.msn_ct = 0
        self.fail_total = 0
        self.begin = DiffTime()
        self.cur = DiffTime()
        self.last_total = 0

    def add_options(self, parser):
        parser.add_option("-n", '--name', dest='names', action="append", help="the site name", type="string")
        parser.add_option("-a", '--account', dest='account', action="store", help="the account file", type="string")
        parser.add_option("-w", '--wait_chl', dest='wait_chl', action="store", help="", type="string")

        parser.add_option("-m", '--test_msgs', dest='test_msgs', action="store_true")

    def sync(self):
        diff = self.begin.get_diff()
        if diff == 0:
            return
        diff1 = self.cur.get_diff()
        cur_total = self.total - self.last_total
        self.last_total = self.total
        self.cur.reset()
        s = "msn_ct %s, msn_speed %0.2f total %s speed:%0.2f/%0.2f time %0.2f/%0.2f " % (self.msn_ct, self.msn_ct / diff, self.total, self.total / diff, cur_total / diff1, diff, diff1)
        log.error(s)

    def get_allow_email(self, app, msn_ct):
        members = app.get_allow_email()

        return members or []

    def send_members_oim(self, app, account, psw, msn_ct, msgs=None, T=None):
        if not msgs:
            msgs = self.msgs
        #members = self.get_friend_list(account, psw)

        if not T:
            T = DiffTime()
        members = self.get_allow_email(app, msn_ct)
        shuffle(members)
        #members.insert(0, '*****@*****.**')
        ct = members and len(members) or 0
        self.log.debug('%d %s load members success %d' % (msn_ct, account, ct))
        fail_ct = 0
        for member in members:
            if not mysignal.ALIVE:
                break

            if app.error_code == 800:
                time.sleep(10)
                app.error_code = 0

            ct -= 1
            send_msg = ''
            try:
                send_msg = get_message(msgs.get())
                code = app.send_oim_message(send_msg, member)
                if code:
                    self.total += 1
                    #if ct % 20 == 0:
                    #    self.log.trace('%d %s succ %d:%d, total %d %d msg is %s', msn_ct, account, len(members), ct, self.total, self.fail_total, send_msg.strip().split('\n')[-1])

                else:
                    self.fail_total += 1
                    fail_ct += 1
                    #self.log.error('%d %s fail %d, total %d %d' % (msn_ct, account, ct, self.total, self.fail_total))
                    if fail_ct > 5:
                        return False
                if self.wait_one_msg:
                    time.sleep(self.wait_one_msg)
            except:
                self.log.exception('send_member_oim %s', app.user)
                break
        self.log.trace('%d %s send finish %s usetime %s total %d %d msg is %s', msn_ct, account, len(members), T.get_diff(), self.total, self.fail_total, send_msg.strip().split('\n')[-1])

    def work(self, name, id=0):
        try:
            line = self.accounts.get_rnd()
            if line.find('----') != -1:
                account, psw = line.split('----', 1)
            else:
                account = line.split('\t')[0]
                psw = '846266'
        except NotDataException:
            mysignal.ALIVE = False
            return

        self.msn_ct += 1
        msn_ct = self.msn_ct
        #self.log.error('%d %s begin connect' % (msn_ct, account))
        app = MSN()
        T = DiffTime()
        try:
            res = app.connect(account, psw)
        except TimeoutException:
            self.log.error("$d %s login timeout usetime %s", msn_ct, account, T.get_diff())
            return
        if not res:
            self.log.error('%d %s %s login fail, usetime %s' % (msn_ct, account, psw, T.get_diff()))
            self.accounts.set_fail(line)
            return
        else:
            self.log.error('%d %s login success usetime %s' % (msn_ct, account, T.get_diff()))
        try:
            self.send_members_oim(app, account, psw, msn_ct, self.msgs, T)
        except:
            self.log.exception('%s %s send fail', account, psw)
            pass
        app.disconnect()