Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a08cdf3

Browse files
committed
两种加好友模式
1 parent 10b7786 commit a08cdf3

File tree

1 file changed

+69
-102
lines changed

1 file changed

+69
-102
lines changed

adb微信加好友/main.py

Lines changed: 69 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
@file: main.py
77
@time: 2019/12/5 15:59
88
"""
9-
109
import traceback
1110
import os
1211
import xml.etree.cElementTree as xmlParser
@@ -27,7 +26,7 @@
2726
phoe_tables = phone_excel.sheet_by_index(0)
2827
phone_get_col = 1 # 读取手机号的列
2928
phone_write_col = 2 # 写入手机号的列
30-
wait_time = 1 # 各个操作等待间隔
29+
wait_time = 20 # 等待间隔
3130
phone_can_write_index = 1 # 从哪一行开始记录手机号
3231

3332

@@ -165,8 +164,10 @@ def check_screen(self):
165164
判断屏幕状态 亮为True
166165
:return:
167166
"""
167+
# print(self._basePath)
168168
displayPowerState = os.popen(
169169
"adb shell dumpsys window policy | findstr mScreenOnFully ").read().strip() # 读出来这种 mAwake=truemScreenOnEarly=true mScreenOnFully=true 字节类型
170+
# print("134",displayPowerState)
170171
state = str(displayPowerState).split(" ")[1].split("=")[1]
171172
if state == 'true':
172173
return True
@@ -177,16 +178,16 @@ def wake_up_the_screen(self):
177178
唤醒屏幕 26 如果已唤醒则跳过
178179
:return:
179180
"""
180-
if not self.check_screen():
181-
self.adb_keyboard(26)
181+
# if not self.check_screen():
182+
self.adb_keyboard(26)
182183

183184
def check_screen_lock(self):
184185
"""
185186
判断屏幕是否锁屏 是True
186187
:return:
187188
"""
188189
displayPowerState = os.popen(
189-
'adb shell dumpsys window policy |find "isStatusBarKeyguard"').read().strip() # 读出来这种 mAwake=truemScreenOnEarly=true mScreenOnFully=true 字节类型
190+
'adb shell dumpsys window policy |findstr isStatusBarKeyguard').read().strip() # 读出来这种 mAwake=truemScreenOnEarly=true mScreenOnFully=true 字节类型
190191
state = str(displayPowerState).split(" ")[-1].split("=")[-1]
191192
if state == 'true':
192193
return True
@@ -197,8 +198,10 @@ def unlock(self):
197198
解锁 82 已解锁则跳过
198199
:return:
199200
"""
200-
if self.check_screen_lock():
201-
self.adb_keyboard(82)
201+
# if self.check_screen_lock():
202+
# self.adb_keyboard(82)
203+
self.swipe([500, 500], [500, 1500])
204+
print('解锁中')
202205

203206
def start_wechat(self):
204207
"""
@@ -393,7 +396,10 @@ def click_add_friend(self):
393396
点击添加好友 共两个操作 1,点击+号按钮 2,点击“添加朋友”
394397
:return:
395398
"""
396-
self.click_by_id_after_refresh("com.tencent.mm:id/rb")
399+
try:
400+
self.click_by_id_after_refresh("com.tencent.mm:id/rb")
401+
except Exception:
402+
pass
397403
self.click_by_text_after_refresh("添加朋友")
398404

399405
def click_wechat_and_friend(self):
@@ -518,76 +524,6 @@ def init(self):
518524
# self._adb.click_by_text_after_refresh('添加')
519525
# self._adb.click_by_text_after_refresh('微信号/手机号')
520526

521-
def change_user(self):
522-
"""
523-
切换微信账号 暂未完成
524-
:return:
525-
"""
526-
print(' ---- 开始切换账号 ----')
527-
528-
# 企业微信退回到主页面
529-
self._adb.adb_put_back()
530-
self._adb.adb_put_back()
531-
self._adb.adb_put_back()
532-
self._adb.click_by_text_after_refresh('我')
533-
534-
# 回到桌面
535-
self._adb.adb_back_to_desktop()
536-
537-
# 切换微信
538-
self._adb.click_by_text_after_refresh('微信')
539-
self._adb.click_by_text_after_refresh('我')
540-
self._adb.click_by_text_after_refresh('设置')
541-
self._adb.click_by_text_after_refresh('切换帐号')
542-
543-
544-
545-
self._adb.find_nodes_by_text(self._account[0])
546-
left = float(self._adb.get_bounds()[0])
547-
548-
self._adb.find_nodes_by_text(self._account[1])
549-
right = float(self._adb.get_bounds()[0])
550-
551-
self._adb.find_nodes_by_text('当前使用')
552-
cursor = float(self._adb.get_bounds()[0])
553-
554-
self._adb.find_nodes('true', By.naf)
555-
# 左侧用户在使用中
556-
if abs(cursor - left) < abs(cursor - right):
557-
self._adb.click(1)
558-
else:
559-
self._adb.click(0)
560-
561-
# 判断是否登录成功
562-
while True:
563-
self._adb.refresh_nodes()
564-
if self._adb.find_nodes_by_text('通讯录'):
565-
break
566-
time.sleep(2)
567-
568-
# 回到桌面打开企业微信
569-
self._adb.adb_back_to_desktop()
570-
self._adb.click_by_text_after_refresh('企业微信')
571-
self._adb.click_by_text_after_refresh('设置')
572-
self._adb.click_by_text_after_refresh('退出登录')
573-
self._adb.click_by_text_after_refresh('退出当前帐号')
574-
self._adb.click_by_text_after_refresh('确定')
575-
self._adb.click_by_text_after_refresh('微信登录')
576-
577-
# 判断是否登录成功
578-
while True:
579-
self._adb.refresh_nodes()
580-
if self._adb.find_nodes_by_text('进入企业 '):
581-
break
582-
time.sleep(2)
583-
self._adb.click(0)
584-
585-
while True:
586-
self._adb.refresh_nodes()
587-
if self._adb.find_nodes_by_text('通讯录'):
588-
break
589-
time.sleep(2)
590-
591527
def clean_phone(self):
592528
"""
593529
清空手机号
@@ -600,36 +536,36 @@ def clean_phone(self):
600536
return False
601537

602538
def add_friends(self, phone):
603-
# 输入号码
539+
604540
phone = str(int(phone))
541+
print("当前手机号:{}".format(phone))
605542
self._adb.adb_input(phone)
606543
# 点击搜索
607544

608545
search_res = "搜索:" + phone
609546
self._adb.click_by_text_after_refresh(search_res)
610547
print(' ==> 点击搜索 ==> ')
611548

612-
if self._adb.find_node_by_text('查找失败'):
613-
print(' <== 查找失败 <== ')
614-
write_to_excel(phone_file_path, phone_can_write_index, phone_write_col, "查找失败")
615-
self._adb.adb_put_back()
549+
if self._adb.find_node_by_text('该用户不存在') or self._adb.find_node_by_text('被搜帐号状态异常,无法显示'):
550+
print(' <== 该用户不存在 或 帐号异常 <== ')
551+
write_to_excel(phone_file_path, phone_can_write_index, phone_write_col, "该用户不存在")
616552

617553
# 查找成功
618554
elif self._adb.find_node_by_text('添加到通讯录'):
619555

620556
# self._adb.click(0)
621557
self._adb.click_by_text_after_refresh('添加到通讯录')
622558

623-
if not self._adb.find_node_by_text('发送添加朋友申请'):
624-
print(' <== 发送失败 <== ')
625-
write_to_excel(phone_file_path, phone_can_write_index, phone_write_col, "发送失败")
626-
559+
if self._adb.find_node_by_text('发消息'):
560+
print(' <== 发送成功 <== ')
561+
write_to_excel(phone_file_path, phone_can_write_index, phone_write_col, " 发送成功 ")
562+
self._adb.adb_put_back()
627563
else:
628564
self._adb.click_by_text_after_refresh("发送")
629565

630566
print(' !! <== 发送成功 <== ')
631567
write_to_excel(phone_file_path, phone_can_write_index, phone_write_col, "发送成功")
632-
time.sleep(2)
568+
time.sleep(3)
633569
self._adb.adb_put_back()
634570
if self._adb.find_node_by_text('添加到通讯录'):
635571
print("操作可能太频繁被限制,建议换号或者等会再试")
@@ -647,12 +583,16 @@ def add_friends(self, phone):
647583
# self.push('failed', phone + '同时拥有微信和企业微信')
648584
# self._adb.adb_put_back()
649585

650-
elif self._adb.find_node_by_text('该用户不存在') or self._adb.find_node_by_text('被搜帐号状态异常,无法显示'):
651-
print(' <== 该用户不存在 或 帐号异常 <== ')
652-
write_to_excel(phone_file_path, phone_can_write_index, phone_write_col, "已经是好友")
586+
# elif self._adb.find_node_by_text('该用户不存在') or self._adb.find_node_by_text('被搜帐号状态异常,无法显示'):
587+
# print(' <== 该用户不存在 或 帐号异常 <== ')
588+
# write_to_excel(phone_file_path, phone_can_write_index, phone_write_col, "该用户不存在")
653589

654590
# 清空已输入的字符
655591
self.clean_phone()
592+
try:
593+
self.clean_phone()
594+
except:
595+
pass
656596

657597
def fuck(self):
658598
"""
@@ -683,35 +623,62 @@ def Imsorry(self):
683623

684624

685625
def main(self):
626+
"""
627+
间断时间较长
628+
:return:
629+
"""
630+
global phone_can_write_index
686631
#读取手机号数据
687632
phone_datas = [get_keywords_data(phoe_tables, i, phone_get_col) for i in
688633
range(1, phoe_tables.nrows)]
689634
for phone in phone_datas:
635+
try:
636+
self._adb.wake_up_the_screen()
637+
print("唤醒屏幕")
638+
# # # 解锁 此处只能滑动解锁
639+
time.sleep(2)
640+
self._adb.unlock()
641+
print("解锁成功")
642+
self._adb.start_wechat()
643+
print("启动微信")
644+
self._adb.click_add_friend()
645+
print("点击加号")
646+
self._adb.click_wechat_and_friend()
647+
print("点击那两个 微信号/手机号")
648+
except:
649+
pass
690650
self.add_friends(phone)
651+
time.sleep(wait_time)
652+
phone_can_write_index += 1
653+
y = input("{}个电话号码已加完,是否关闭程序".format(len(phone_datas)))
654+
if y:
655+
pass
691656

692657
def test(self):
658+
"""
659+
间断时间较短
660+
:return:
661+
"""
693662
global phone_can_write_index
694-
# # 唤醒屏幕
695-
# self._adb.wake_up_the_screen()
696-
# # 解锁 此处只能滑动解锁
697-
# self._adb.unlock()
698-
# # 启动微信
699-
# self._adb.start_wechat()
700-
# # 判断微信是否启动
701-
# self._adb.check_wechat_is_start()
702-
# 添加好友
703663
self._adb.click_add_friend()
704664
# 点击那两个 微信号/手机号
705665
self._adb.click_wechat_and_friend()
706-
# 添加好友
707666
phone_datas = [get_keywords_data(phoe_tables, i, phone_get_col) for i in
708667
range(1, phoe_tables.nrows)]
709668
for phone in phone_datas:
710669

711670
self.add_friends(phone)
671+
time.sleep(wait_time)
712672
phone_can_write_index +=1
673+
y = input("{}个电话号码已加完,是否关闭程序".format(len(phone_datas)))
674+
if y:
675+
pass
713676

714677

715678
if __name__ == '__main__':
716679
fun = Main()
717-
fun.test()
680+
chose = input("请选择运行模式 :1.长时间间隔模式,2:短时间间隔模式(此模式下建议等待时间为1s 保持屏幕亮了就可以)")
681+
if chose == "1":
682+
fun.main()
683+
if chose == "2":
684+
fun.test()

0 commit comments

Comments
 (0)