Beispiel #1
0
def answer_worker():
    while environment.enable_answer and time.time() < exit_tm:
        flag = False
        tm = time.time()
        for u in us:
            if u['userinfo'] == '': continue
            if not checkLevel(u):
                if u['to_ans'] != '' and u['ans_time'] < tm:
                    try:
                        answer.run_lb(u['http'], u['to_ans'])
                        answer.run_lst(u['http'])
                    except:
                        log.log('answer part 2 error', 'Main')
                    u['to_ans'] = ''
                    u['lst_chk_login'] = 0
                    flag = True
                    break
                if tm - u['lst_answer'] > answer_interval:
                    log.log('%s low level' % u['uid'], 'Main')
                    res = False
                    try:
                        res = answer.run(u['http'], proxy_pool)
                    except:
                        log.log('answer part 1 error', 'Main')
                    if type(res) is dict:
                        if res['lst']:
                            answer.run_lst(u['http'])
                            u['lst_chk_login'] = 0
                        else:
                            u['to_ans'] = res['data']
                            u['ans_time'] = tm + answer_wait_time
                    u['lst_answer'] = tm
                    saveUser(u)
                    flag = True
                    break
                else:
                    continue
        if flag:
            time.sleep(1)
        else:
            log.log('Answer Worker: nothing to do', 'Main')
            time.sleep(10)
Beispiel #2
0
 def test_self_prepared_1(self):
     output = ['Case #1: IMPOSSIBLE']
     self.assertEqual(run('inp/case1.inp'), output)
Beispiel #3
0
 def test_sample(self):
     output = ['Case #1: 1 0 0 0 0', 'Case #2: IMPOSSIBLE']
     self.assertEqual(run('inp/sample.inp'), output)
Beispiel #4
0
 def test_self_prepared_4(self):
     output = ['Case #1: 0 1 0 1 0 0 1 0 0 0']
     self.assertEqual(run('inp/case4.inp'), output)
Beispiel #5
0
 def test_self_prepared_3(self):
     output = ['Case #1: 1 1 0', 'Case #2: 1 1 1 1']
     self.assertEqual(run('inp/case3.inp'), output)
Beispiel #6
0
 def test_self_prepared_2(self):
     output = ['Case #1: 0 0 1 1 0']
     self.assertEqual(run('inp/case2.inp'), output)