26
26
phoe_tables = phone_excel .sheet_by_index (0 )
27
27
phone_get_col = 1 # 读取手机号的列
28
28
phone_write_col = 2 # 写入手机号的列
29
- wait_time = 20 # 等待间隔
29
+ wait_time = 40 # 等待间隔
30
30
phone_can_write_index = 1 # 从哪一行开始记录手机号
31
31
32
32
@@ -99,8 +99,8 @@ def __init__(self, port=None, device=None):
99
99
self ._device = device # 设备号
100
100
self ._p = '' if (port is None ) else '-P ' + str (port ) + ' '
101
101
self ._s = '' if (device is None ) else '-s ' + str (device ) + ' '
102
- self ._baseShell = adb_path () + 'adb ' + self ._p + self ._s # 指定端口 指定设备 组装adb命令
103
102
self ._basePath = os .path .dirname (__file__ ) # 获取该文件(adbtools.py) 所在对文件夹路径
103
+ self ._baseShell = adb_path () + 'adb ' + self ._p + self ._s # 指定端口 指定设备 组装adb命令
104
104
self ._nodes = None # 缓存当前查找到的nodes => type 列表 | value 字典
105
105
self ._x = None
106
106
self ._y = None
@@ -138,7 +138,6 @@ def swipe(self, start=None, end=None):
138
138
end = x1 , y1 - int (y1 / 2 )
139
139
x2 , y2 = end
140
140
cmd = self ._baseShell + "shell input swipe " + str (x1 ) + " " + str (y1 ) + " " + str (x2 ) + " " + str (y2 )
141
- print (cmd )
142
141
os .system (cmd )
143
142
144
143
def show_current_pk (self ):
@@ -165,8 +164,11 @@ def check_screen(self):
165
164
:return:
166
165
"""
167
166
# print(self._basePath)
167
+
168
+ # os.system(self._baseShell+"shell dumpsys window policy | findstr mScreenOnFully")
169
+
168
170
displayPowerState = os .popen (
169
- "adb shell dumpsys window policy | findstr mScreenOnFully " ).read ().strip () # 读出来这种 mAwake=truemScreenOnEarly=true mScreenOnFully=true 字节类型
171
+ " bash shell dumpsys window policy | findstr mScreenOnFully " ).read ().strip () # 读出来这种 mAwake=truemScreenOnEarly=true mScreenOnFully=true 字节类型
170
172
# print("134",displayPowerState)
171
173
state = str (displayPowerState ).split (" " )[1 ].split ("=" )[1 ]
172
174
if state == 'true' :
@@ -187,12 +189,20 @@ def check_screen_lock(self):
187
189
:return:
188
190
"""
189
191
displayPowerState = os .popen (
190
- 'adb shell dumpsys window policy |findstr isStatusBarKeyguard' ).read ().strip () # 读出来这种 mAwake=truemScreenOnEarly=true mScreenOnFully=true 字节类型
192
+ self . _baseShell + ' shell dumpsys window policy |findstr isStatusBarKeyguard' ).read ().strip () # 读出来这种 mAwake=truemScreenOnEarly=true mScreenOnFully=true 字节类型
191
193
state = str (displayPowerState ).split (" " )[- 1 ].split ("=" )[- 1 ]
192
194
if state == 'true' :
193
195
return True
194
196
return False
195
197
198
+ def return_home (self ):
199
+ """
200
+ 返回桌面
201
+ :return:
202
+ """
203
+ self .adb_keyboard (3 )
204
+
205
+
196
206
def unlock (self ):
197
207
"""
198
208
解锁 82 已解锁则跳过
@@ -261,6 +271,7 @@ def generate_nodes(self):
261
271
解析xml文件生成node数据
262
272
:return:
263
273
"""
274
+ # print("file_path",self._basePath + '/data/dump.xml')
264
275
xml = xmlParser .ElementTree (file = self ._basePath + '/data/dump.xml' )
265
276
nodes = xml .findall (path = ".//node" ) # 全部node节点
266
277
tem_node = []
@@ -400,17 +411,23 @@ def click_add_friend(self):
400
411
self .click_by_id_after_refresh ("com.tencent.mm:id/rb" )
401
412
except Exception :
402
413
pass
403
- self .click_by_text_after_refresh ("添加朋友" )
414
+ try :
415
+ self .click_by_text_after_refresh ("添加朋友" )
416
+ except Exception :
417
+ pass
404
418
405
419
def click_wechat_and_friend (self ):
406
420
"""
407
421
点击那两个 微信号/手机号
408
422
:return:
409
423
"""
410
- bounds1 = self .find_node_by_resource_id ("com.tencent.mm:id/dlc" )
411
- self .click_use_bounds (bounds1 )
412
- bounds2 = self .find_node_by_resource_id ("com.tencent.mm:id/c4j" )
413
- self .click_use_bounds (bounds2 )
424
+ try :
425
+ bounds1 = self .find_node_by_resource_id ("com.tencent.mm:id/dlc" )
426
+ self .click_use_bounds (bounds1 )
427
+ bounds2 = self .find_node_by_resource_id ("com.tencent.mm:id/c4j" )
428
+ self .click_use_bounds (bounds2 )
429
+ except Exception :
430
+ pass
414
431
415
432
def click_use_bounds (self , bounds ):
416
433
x , y = self .cal_coordinate (bounds )
@@ -536,62 +553,67 @@ def clean_phone(self):
536
553
return False
537
554
538
555
def add_friends (self , phone ):
556
+ try :
557
+ self ._adb .return_home ()
558
+ print ("返回桌面" )
559
+ self ._adb .start_wechat ()
560
+ print ("启动微信" )
561
+ phone = str (int (phone ))
562
+ print ("当前手机号:{}" .format (phone ))
563
+ self ._adb .adb_input (phone )
564
+ # 点击搜索
565
+ search_res = "搜索:" + phone
566
+ self ._adb .click_by_text_after_refresh (search_res )
567
+ print (' ==> 点击搜索 ==> ' )
568
+
569
+ if self ._adb .find_node_by_text ('该用户不存在' ) or self ._adb .find_node_by_text ('被搜帐号状态异常,无法显示' ):
570
+ print (' <== 该用户不存在 或 帐号异常 <== ' )
571
+ write_to_excel (phone_file_path , phone_can_write_index , phone_write_col , "该用户不存在" )
572
+
573
+ # 查找成功
574
+ elif self ._adb .find_node_by_text ('添加到通讯录' ):
575
+
576
+ # self._adb.click(0)
577
+ self ._adb .click_by_text_after_refresh ('添加到通讯录' )
578
+
579
+ if self ._adb .find_node_by_text ('发消息' ):
580
+ print (' <== 发送成功 <== ' )
581
+ write_to_excel (phone_file_path , phone_can_write_index , phone_write_col , " 发送成功 " )
582
+ self ._adb .adb_put_back ()
583
+ else :
584
+ self ._adb .click_by_text_after_refresh ("发送" )
539
585
540
- phone = str (int (phone ))
541
- print ("当前手机号:{}" .format (phone ))
542
- self ._adb .adb_input (phone )
543
- # 点击搜索
544
-
545
- search_res = "搜索:" + phone
546
- self ._adb .click_by_text_after_refresh (search_res )
547
- print (' ==> 点击搜索 ==> ' )
548
-
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 , "该用户不存在" )
552
-
553
- # 查找成功
554
- elif self ._adb .find_node_by_text ('添加到通讯录' ):
555
-
556
- # self._adb.click(0)
557
- self ._adb .click_by_text_after_refresh ('添加到通讯录' )
558
-
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 ()
563
- else :
564
- self ._adb .click_by_text_after_refresh ("发送" )
565
-
566
- print (' !! <== 发送成功 <== ' )
567
- write_to_excel (phone_file_path , phone_can_write_index , phone_write_col , "发送成功" )
568
- time .sleep (3 )
569
- self ._adb .adb_put_back ()
570
- if self ._adb .find_node_by_text ('添加到通讯录' ):
571
- print ("操作可能太频繁被限制,建议换号或者等会再试" )
586
+ print (' !! <== 发送成功 <== ' )
587
+ write_to_excel (phone_file_path , phone_can_write_index , phone_write_col , "发送成功" )
588
+ time .sleep (3 )
572
589
self ._adb .adb_put_back ()
590
+ if self ._adb .find_node_by_text ('添加到通讯录' ):
591
+ print ("操作可能太频繁被限制,建议换号或者等会再试" )
592
+ self ._adb .adb_put_back ()
573
593
574
594
575
595
576
- elif self ._adb .find_node_by_text ('发消息' ):
577
- print (' <== 已经是好友 无需再次添加 <== ' )
578
- write_to_excel (phone_file_path , phone_can_write_index , phone_write_col , "已经是好友" )
579
- self ._adb .adb_put_back ()
596
+ elif self ._adb .find_node_by_text ('发消息' ):
597
+ print (' <== 已经是好友 无需再次添加 <== ' )
598
+ write_to_excel (phone_file_path , phone_can_write_index , phone_write_col , "已经是好友" )
599
+ self ._adb .adb_put_back ()
580
600
581
- # elif self._adb.find_node_by_text('同时拥有微信和企业微信'):
582
- # print(' <== 同时拥有微信和企业微信 <== ')
583
- # self.push('failed', phone + '同时拥有微信和企业微信')
584
- # self._adb.adb_put_back()
601
+ # elif self._adb.find_node_by_text('同时拥有微信和企业微信'):
602
+ # print(' <== 同时拥有微信和企业微信 <== ')
603
+ # self.push('failed', phone + '同时拥有微信和企业微信')
604
+ # self._adb.adb_put_back()
585
605
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, "该用户不存在")
606
+ # elif self._adb.find_node_by_text('该用户不存在') or self._adb.find_node_by_text('被搜帐号状态异常,无法显示'):
607
+ # print(' <== 该用户不存在 或 帐号异常 <== ')
608
+ # write_to_excel(phone_file_path, phone_can_write_index, phone_write_col, "该用户不存在")
589
609
590
- # 清空已输入的字符
591
- self .clean_phone ()
592
- try :
610
+ # 清空已输入的字符
593
611
self .clean_phone ()
594
- except :
612
+ try :
613
+ self .clean_phone ()
614
+ except :
615
+ pass
616
+ except Exception :
595
617
pass
596
618
597
619
def fuck (self ):
@@ -631,14 +653,17 @@ def main(self):
631
653
#读取手机号数据
632
654
phone_datas = [get_keywords_data (phoe_tables , i , phone_get_col ) for i in
633
655
range (1 , phoe_tables .nrows )]
634
- for phone in phone_datas :
656
+ for index , phone in enumerate (phone_datas ):
657
+ print ("手机号总数:{},当前已添加至第{}个号码" .format (len (phone_datas ), index + 1 ))
635
658
try :
636
659
self ._adb .wake_up_the_screen ()
637
660
print ("唤醒屏幕" )
638
661
# # # 解锁 此处只能滑动解锁
639
662
time .sleep (2 )
640
663
self ._adb .unlock ()
641
664
print ("解锁成功" )
665
+ self ._adb .return_home ()
666
+ print ("返回桌面" )
642
667
self ._adb .start_wechat ()
643
668
print ("启动微信" )
644
669
self ._adb .click_add_friend ()
@@ -659,16 +684,33 @@ def test(self):
659
684
间断时间较短
660
685
:return:
661
686
"""
687
+ try :
688
+ self ._adb .wake_up_the_screen ()
689
+ print ("唤醒屏幕" )
690
+ # # # 解锁 此处只能滑动解锁
691
+ time .sleep (2 )
692
+ self ._adb .unlock ()
693
+ print ("解锁成功" )
694
+ self ._adb .return_home ()
695
+ print ("返回桌面" )
696
+ self ._adb .start_wechat ()
697
+ print ("启动微信" )
698
+ self ._adb .click_add_friend ()
699
+ print ("点击加号" )
700
+ self ._adb .click_wechat_and_friend ()
701
+ print ("点击那两个 微信号/手机号" )
702
+ except :
703
+ pass
704
+
662
705
global phone_can_write_index
663
706
self ._adb .click_add_friend ()
664
707
# 点击那两个 微信号/手机号
665
708
self ._adb .click_wechat_and_friend ()
666
709
phone_datas = [get_keywords_data (phoe_tables , i , phone_get_col ) for i in
667
710
range (1 , phoe_tables .nrows )]
668
- for phone in phone_datas :
669
-
711
+ for index , phone in enumerate ( phone_datas ) :
712
+ print ( "手机号总数:{},当前已添加至第{}个号码" . format ( len ( phone_datas ), index + 1 ))
670
713
self .add_friends (phone )
671
- time .sleep (wait_time )
672
714
phone_can_write_index += 1
673
715
y = input ("{}个电话号码已加完,是否关闭程序" .format (len (phone_datas )))
674
716
if y :
@@ -677,7 +719,9 @@ def test(self):
677
719
678
720
if __name__ == '__main__' :
679
721
fun = Main ()
680
- chose = input ("请选择运行模式 :1.长时间间隔模式,2:短时间间隔模式(此模式下建议等待时间为1s 保持屏幕亮了就可以)" )
722
+ chose = input ("请选择运行模式 :" )
723
+ print ("1.长时间间隔模式,2:短时间间隔模式(此模式下建议等待时间为1s 保持屏幕亮了就可以)" )
724
+ print ("请注意:两个模式都需要确保手机屏幕在熄灭状态下启动!!" )
681
725
if chose == "1" :
682
726
fun .main ()
683
727
if chose == "2" :
0 commit comments