Skip to content

Commit fea9019

Browse files
author
shaowei
committed
2 parents 7cdf81e + e2c06ff commit fea9019

File tree

7 files changed

+196
-45
lines changed

7 files changed

+196
-45
lines changed

task_service/executor/facebook/exception.py

Lines changed: 106 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class FacebookExceptionProcessor(BaseException, WebActions):
4747
-1: {'name': 'unknown'},
4848
0: {'name': 'home',
4949
'key_words': {'mobile': {"css": ['div[id="MComposer"]'], "xpath": []},
50-
"pc": {"css": ['div[id="MComposerPC"]']}}},
50+
"pc": {"css": ['input[data-testid="search_input"]']}}},
5151
1: {'name': 'remember_password',
5252
'key_words': {"mobile": {"css": ['a[href^="/login/save-device/cancel/?"]', 'button[type="submit"]']},
5353
"pc": {"css": []}}},
@@ -62,7 +62,7 @@ class FacebookExceptionProcessor(BaseException, WebActions):
6262
"pc": {"css": []}}},
6363
5: {'name': 'account_invalid',
6464
'key_words': {"mobile": {"css": ['div[class^="mvm uiP fsm"]']},
65-
"pc": {"css": ['div[class^="mvm uiP fsm"]']}},
65+
"pc": {"css": ['button[name="submit[Download Your Information]"]']}},
6666
'account_status': 'invalid'},
6767
6: {'name': 'auth_button_two_verify',
6868
'key_words': {"mobile": {"css": ('button[name="submit[Continue]', 'div[id="checkpoint_subtitle"]')},
@@ -74,23 +74,23 @@ class FacebookExceptionProcessor(BaseException, WebActions):
7474
'account_status': 'verifying_sms'},
7575
8: {'name': 'photo_verify',
7676
'key_words': {"mobile": {"css": ['input[name="photo-input"]', 'input[id="photo-input"]']},
77-
"pc": {"css": []}},
77+
"pc": {"css": ['input[name="photo-input"]', 'input[id="photo-input"]']}},
7878
'account_status': 'verifying_photo'},
7979
9: {'name': 'auth_button_one_verify',
8080
'key_words': {"mobile": {"css": ['button[name="submit[Secure Account]"]']},
8181
"pc": {"css": []}},
8282
'account_status': 'verifying_auth_button_one'},
8383
10: {'name': 'email_verify',
8484
'key_words': {"mobile": {"css": ['input[placeholder="######"]']},
85-
"pc": {"css": []}},
85+
"pc": {"css": ['input[placeholder="######"]']}},
8686
'account_status': 'verifying_email_code'},
8787
11: {'name': 'sms_verify',
8888
'key_words': {"mobile": {"css": ['input[name="p_c"]']},
8989
"pc": {"css": []}},
9090
'account_status': 'verifying_sms_code'},
9191
12: {'name': 'wrong_password',
9292
'key_words': {"mobile": {"css": ['a[href^="/recover/initiate/?ars=facebook_login_pw_error&lwv"]']},
93-
"pc": {"css": []}},
93+
"pc": {"css": ['a[class="accessible_elem layer_close_elem"]']}},
9494
'account_status': 'verifying_wrong_password'},
9595
13: {'name': 'shared_login',
9696
'key_words': {"mobile": {"css": ['a[href^="https://facebook.com/mobile/click/?redir_url=https"]']},
@@ -242,7 +242,7 @@ def check_func(self, key_words, wait=3):
242242
if iframe:
243243
for ifa in iframe:
244244
self.driver.switch_to.frame(ifa)
245-
time.sleep(1)
245+
self.sleep(1,1)
246246

247247
WebDriverWait(self.driver, wait).until(
248248
EC.presence_of_element_located((key_words_type, key)))
@@ -291,7 +291,7 @@ def process_save_phone_number_mobile_mobile(self):
291291
tel_number = WebDriverWait(self.driver, 6).until(
292292
EC.presence_of_element_located((By.CSS_SELECTOR, self.get_key_words(2))))
293293
self.click(tel_number)
294-
time.sleep(3)
294+
self.sleep()
295295
except Exception as e:
296296
logger.exception("忽略输入电话号码处理异常, e={}".format(e))
297297
return False, 2
@@ -322,7 +322,7 @@ def process_download_app_mobile(self):
322322
:return: 成功返回 True, 失败返回 False
323323
"""
324324

325-
time.sleep(3)
325+
self.sleep()
326326
try:
327327
logger.info('忽略下载app处理中')
328328
never_save_number = WebDriverWait(self.driver, 6).until(
@@ -351,6 +351,23 @@ def process_account_invalid_mobile(self):
351351
logger.info("账号被封杀")
352352
return False, 5
353353

354+
def process_account_invalid_pc(self):
355+
"""
356+
# 账号被封杀
357+
:param kwargs:
358+
:return: 成功返回 True, 失败返回 False
359+
"""
360+
try:
361+
logger.info('账号被封杀处理中')
362+
never_save_number = WebDriverWait(self.driver, 6).until(
363+
EC.presence_of_element_located((By.CSS_SELECTOR, self.get_key_words(5))))
364+
self.click(never_save_number)
365+
except Exception as e:
366+
logger.exception("账号被封杀处理异常, e={}".format(e))
367+
return False, 5
368+
logger.info("账号被封杀")
369+
return False, 5
370+
354371
def process_auth_button_two_verify_mobile(self):
355372
"""
356373
身份验证类型二,跳转按钮
@@ -416,7 +433,7 @@ def process_phone_sms_verify_pc(self):
416433
self.click(sub_button)
417434
except:
418435
pass
419-
rtime = random.randint(2, 4)
436+
420437
try:
421438
tel_button = self.driver.find_elements_by_css_selector('i[class^="img sp_"]')
422439
if not tel_button:
@@ -427,11 +444,11 @@ def process_phone_sms_verify_pc(self):
427444
tel_stutas = self.driver.find_elements_by_css_selector('a[role="menuitemcheckbox"]')
428445
self.click(tel_stutas[45])
429446

430-
time.sleep(rtime)
447+
self.sleep()
431448
send_tel = self.driver.find_element_by_css_selector('input[type="tel"]')
432449
self.send_keys(send_tel, "16500000000")
433450

434-
time.sleep(rtime)
451+
self.sleep()
435452
submit_button = self.driver.find_element_by_css_selector('button[id="checkpointSubmitButton"]')
436453
self.click(submit_button)
437454

@@ -445,11 +462,11 @@ def process_phone_sms_verify_pc(self):
445462
except:
446463
pass
447464
# 短信验证码
448-
time.sleep(rtime)
465+
self.sleep()
449466
tel_code = self.driver.find_element_by_css_selector('input[name="p_c"]')
450467
self.send_keys(tel_code, "414141")
451468

452-
time.sleep(rtime)
469+
self.sleep()
453470
submit_button = self.driver.find_element_by_css_selector('button[id="checkpointSubmitButton"]')
454471
self.click(submit_button)
455472

@@ -500,6 +517,47 @@ def process_photo_verify_mobile(self):
500517
logger.info("处理上传图片验证的完成")
501518
return True, 8
502519

520+
def process_photo_verify_pc(self):
521+
"""
522+
# 上传图片验证
523+
:param kwargs:
524+
:return: 成功返回 True, 失败返回 False
525+
"""
526+
try:
527+
logger.info("处理上传图片验证处理中")
528+
photo_upload = WebDriverWait(self.driver, 6).until(
529+
EC.presence_of_element_located((By.CSS_SELECTOR, self.get_key_words(8))))
530+
531+
photo_path = get_photo(self.account, self.gender)
532+
logger.info('process_photo_verify photo path={}'.format(photo_path))
533+
if not photo_path:
534+
return False, 8
535+
# photo_path = 'E:\\IMG_3563.JPG'
536+
# 上传图片
537+
self.send_keys(photo_upload, photo_path)
538+
# photo_upload.send_keys(photo_path)
539+
# 点击继续
540+
phone_button = WebDriverWait(self.driver, 6).until(
541+
EC.presence_of_element_located((By.CSS_SELECTOR, 'button[id="checkpointSubmitButton-actual-button"]')))
542+
self.click(phone_button)
543+
# 重新检查页面
544+
photo_btn = WebDriverWait(self.driver, 6).until(
545+
EC.presence_of_element_located((By.CSS_SELECTOR, 'button[name="submit[OK]"]')))
546+
if photo_btn:
547+
logger.info("photo uploaded successfully!")
548+
account_photo_path = os.path.join(os.path.dirname(os.path.dirname(photo_path)),
549+
"{}.jpg".format(self.account))
550+
shutil.move(photo_path, account_photo_path)
551+
logger.info("process photo verify succeed, photo path={}".format(account_photo_path))
552+
else:
553+
logger.warning("process photo verify unfinished, photo path={}".format(photo_path))
554+
os.remove(photo_path)
555+
except Exception as e:
556+
logger.exception("上传照片验证异常, e={}".format(e))
557+
return False, 8
558+
logger.info("处理上传图片验证的完成")
559+
return True, 8
560+
503561
def process_auth_button_one_verify_mobile(self):
504562
"""
505563
身份验证类型一,跳转按钮
@@ -536,6 +594,24 @@ def process_email_verify_mobile(self):
536594
logger.info("登录邮箱数字验证码验证处理完成")
537595
return True, 10
538596

597+
def process_email_verify_pc(self):
598+
"""
599+
登录邮箱数字验证码验证
600+
:param kwargs:
601+
:return: 成功返回 True, 失败返回 False
602+
"""
603+
try:
604+
logger.info("登录邮箱数字验证码验证处理中")
605+
check_button =WebDriverWait(self.driver, 6).until(
606+
EC.presence_of_element_located(
607+
(By.CSS_SELECTOR, self.get_key_words(10))))
608+
self.click(check_button)
609+
except Exception as e:
610+
logger.exception("登录邮箱数字验证码验证处理异常, e={}".format(e))
611+
return False, 10
612+
logger.info("登录邮箱数字验证码验证处理完成")
613+
return True, 10
614+
539615
def process_sms_verify_mobile(self):
540616
"""
541617
短信验证码验证
@@ -572,6 +648,23 @@ def process_wrong_password_mobile(self):
572648
logger.info("账号密码不正确")
573649
return False, -1
574650

651+
def process_wrong_password_pc(self):
652+
"""
653+
账号密码不正确
654+
:param kwargs:
655+
:return: 成功返回 True, 失败返回 False
656+
"""
657+
try:
658+
logger.info("账号密码不正确 处理中")
659+
WebDriverWait(self.driver, 6).until(
660+
EC.presence_of_element_located(
661+
(By.CSS_SELECTOR, self.get_key_words(12))))
662+
except Exception as e:
663+
logger.exception("账号密码不正确处理异常, e={}".format(e))
664+
return False, -1
665+
logger.info("账号密码不正确")
666+
return False, -1
667+
575668
def process_shared_login_mobile(self):
576669
"""
577670
移动端手机共享登录验证

task_service/executor/web_actions.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,17 @@ def __init__(self, finger_print={}, headless=False):
1919
self.driver = None
2020
self.options = None
2121

22-
def start_chrome(self):
22+
def start_chrome(self, force_display=False, force_client=""):
2323
"""
2424
配置并启动浏览器
25-
:return:
25+
:param force_display: 强制显示chrome界面
26+
:param force_client: 强制指定启动chrome的环境, 可选输入项为"pc"或“mobile"
27+
:return: True/False
2628
"""
2729
try:
2830
# 定制浏览器启动项
2931
chrome_options = webdriver.ChromeOptions()
30-
if self.headless:
32+
if self.headless and not force_display:
3133
chrome_options.add_argument('--headless')
3234
chrome_options.add_argument('--no-sandbox')
3335
chrome_options.add_argument('--disable-extensions')
@@ -41,17 +43,16 @@ def start_chrome(self):
4143
prefs = {'profile.default_content_setting_values':{'notifications': 2}}
4244
chrome_options.add_experimental_option('prefs', prefs)
4345

44-
if self.user_agent:
46+
if self.user_agent and force_client != "mobile":
4547
chrome_options.add_argument('--user-agent={}'.format(self.user_agent))
4648

47-
if self.device:
49+
if self.device and force_client != "pc":
4850
# 移动设备仿真
4951
mobile_emulation = {
5052
'deviceName': self.device
5153
# "deviceMetrics": {"width": 600, "height":800, "pixelRatio": 4.0},
5254
# "userAgent": "Mozilla/5.0 (Linux; Android 8.0.0; XT1635-02 Build/OPNS27.76-12-22-9)"
5355
}
54-
5556
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
5657

5758
chrome_driver = webdriver.Chrome(chrome_options=chrome_options)

task_service/resource/facebook_account.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
jonemarnug@hotmail.com---OA2TMcj8Fx
2+
meacp42dayem@hotmail.com---M9PTURFPI1s
3+
innocentsta7@hotmail.com---MYfOmf9U
4+
anonakrewer72@hotmail.com---iONxFDjdb
5+
donaldxgohman@hotmail.com---HWKlTVfMgyG
6+
jonniefvjhkeeran@hotmail.com---7ivRbOBCZPZ
7+
odessapharor6gp@hotmail.com---gBTe3UEH
8+
emorytzzp@hotmail.com---hwLxdK2YPJ
9+
raneelhnss@hotmail.com---fHQauyA4R
10+
lfloe2c@hotmail.com---7g9KldeMTUw
11+
jonniefvjhkeeran@hotmail.com---7ivRbOBCZPZ
12+
odessapharor6gp@hotmail.com---gBTe3UEH
13+
emorytzzp@hotmail.com:hwLxdK2YPJ---boFu3vbhvrw
114
franzenkneen87241371@outlook.com---s6c3aKWW42
215
hillelsim19451579@outlook.com---i2BGKjEupO
316
oramlusle1984@themail.website---Ec2kcRQegR

task_service/start_task.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def dispatch_test():
2424
time.sleep(600)
2525

2626

27-
def run(task_start_mode='new', update_interval=30):
27+
def run(task_start_mode='new', update_interval=60):
2828
"""
2929
启动任务调度系统
3030
:param task_start_mode: 'new':清空缓存,从头开始; 'restart': 则继续上一次结束点开始, 之前未处理完的任务将继续被执行
@@ -59,8 +59,8 @@ def run(task_start_mode='new', update_interval=30):
5959

6060

6161
if __name__ == '__main__':
62-
# run(task_start_mode=task_start_mode, update_interval=interval)
63-
run(task_start_mode="restart", update_interval=30)
62+
# global env, task_start_mode, interval
63+
run(task_start_mode=task_start_mode, update_interval=interval)
6464

6565
# pipenv run python3 start_task.py [test|pro] [new|restart]
6666
# eg: python3 start_task.py test new

task_service/start_worker.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99
import os
1010
import sys
11+
import datetime
1112
from celery import Celery, platforms
1213
from kombu import Exchange, Queue
1314
from config import load_config, get_broker_and_backend
@@ -31,7 +32,7 @@
3132
broker, backend = get_broker_and_backend()
3233
worker_log_path = ''
3334
beat_log_path = ''
34-
worker_log_path = os.path.join(os.path.dirname(os.path.dirname(__file__)) + '/logs', 'celery.log')
35+
worker_log_path = os.path.join(os.path.dirname(os.path.dirname(__file__)) + '/logs', 'celery_{}.log'.format(datetime.datetime.now().strftime("%Y-%m-%d_%H_%M_%S")))
3536
beat_log_path = os.path.join(os.path.dirname(os.path.dirname(__file__)) + '/logs', 'beat.log')
3637

3738

@@ -61,4 +62,27 @@
6162
# 'options': {'queue': 'feed_account_queue', 'routing_key': 'for_feed_account'}
6263
# }
6364
# }
64-
#celery -A tasks.workers -Q default,China,American,Japan worker -l info -c 4 -Ofair -f logs/celery.log -env pro
65+
#celery -A start_worker -Q default,China,American,Japan worker -l info -c 4 -Ofair -f logs/celery.log -env pro
66+
67+
if __name__ == '__main__':
68+
import subprocess
69+
env = "pro"
70+
save_log = True
71+
input_env = input("Please input execute environment(pro/test):")
72+
if input_env and input_env in ["pro", 'test']:
73+
env = input_env
74+
else:
75+
print("use default env: pro")
76+
77+
is_log_file = input("is save log to file(yes/no):")
78+
if is_log_file and is_log_file in ["yes", 'no']:
79+
if "no" in is_log_file:
80+
save_log = False
81+
82+
if save_log:
83+
subprocess.call("celery -A start_worker -Q default,China,American,Japan worker -l info -c 4 -Ofair -f logs/celery_{}.log -env {}".format(
84+
datetime.datetime.now().strftime("%Y-%m-%d_%H_%M_%S"), env), shell=True)
85+
else:
86+
subprocess.call(
87+
"celery -A start_worker -Q default,China,American,Japan worker -l info -c 4 -Ofair -env {}".format(env), shell=True)
88+

0 commit comments

Comments
 (0)