6
6
@file: main.py
7
7
@time: 2019/12/5 15:59
8
8
"""
9
-
10
9
import traceback
11
10
import os
12
11
import xml .etree .cElementTree as xmlParser
27
26
phoe_tables = phone_excel .sheet_by_index (0 )
28
27
phone_get_col = 1 # 读取手机号的列
29
28
phone_write_col = 2 # 写入手机号的列
30
- wait_time = 1 # 各个操作等待间隔
29
+ wait_time = 20 # 等待间隔
31
30
phone_can_write_index = 1 # 从哪一行开始记录手机号
32
31
33
32
@@ -165,8 +164,10 @@ def check_screen(self):
165
164
判断屏幕状态 亮为True
166
165
:return:
167
166
"""
167
+ # print(self._basePath)
168
168
displayPowerState = os .popen (
169
169
"adb shell dumpsys window policy | findstr mScreenOnFully " ).read ().strip () # 读出来这种 mAwake=truemScreenOnEarly=true mScreenOnFully=true 字节类型
170
+ # print("134",displayPowerState)
170
171
state = str (displayPowerState ).split (" " )[1 ].split ("=" )[1 ]
171
172
if state == 'true' :
172
173
return True
@@ -177,16 +178,16 @@ def wake_up_the_screen(self):
177
178
唤醒屏幕 26 如果已唤醒则跳过
178
179
:return:
179
180
"""
180
- if not self .check_screen ():
181
- self .adb_keyboard (26 )
181
+ # if not self.check_screen():
182
+ self .adb_keyboard (26 )
182
183
183
184
def check_screen_lock (self ):
184
185
"""
185
186
判断屏幕是否锁屏 是True
186
187
:return:
187
188
"""
188
189
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 字节类型
190
191
state = str (displayPowerState ).split (" " )[- 1 ].split ("=" )[- 1 ]
191
192
if state == 'true' :
192
193
return True
@@ -197,8 +198,10 @@ def unlock(self):
197
198
解锁 82 已解锁则跳过
198
199
:return:
199
200
"""
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 ('解锁中' )
202
205
203
206
def start_wechat (self ):
204
207
"""
@@ -393,7 +396,10 @@ def click_add_friend(self):
393
396
点击添加好友 共两个操作 1,点击+号按钮 2,点击“添加朋友”
394
397
:return:
395
398
"""
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
397
403
self .click_by_text_after_refresh ("添加朋友" )
398
404
399
405
def click_wechat_and_friend (self ):
@@ -518,76 +524,6 @@ def init(self):
518
524
# self._adb.click_by_text_after_refresh('添加')
519
525
# self._adb.click_by_text_after_refresh('微信号/手机号')
520
526
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
-
591
527
def clean_phone (self ):
592
528
"""
593
529
清空手机号
@@ -600,36 +536,36 @@ def clean_phone(self):
600
536
return False
601
537
602
538
def add_friends (self , phone ):
603
- # 输入号码
539
+
604
540
phone = str (int (phone ))
541
+ print ("当前手机号:{}" .format (phone ))
605
542
self ._adb .adb_input (phone )
606
543
# 点击搜索
607
544
608
545
search_res = "搜索:" + phone
609
546
self ._adb .click_by_text_after_refresh (search_res )
610
547
print (' ==> 点击搜索 ==> ' )
611
548
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 , "该用户不存在" )
616
552
617
553
# 查找成功
618
554
elif self ._adb .find_node_by_text ('添加到通讯录' ):
619
555
620
556
# self._adb.click(0)
621
557
self ._adb .click_by_text_after_refresh ('添加到通讯录' )
622
558
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 ()
627
563
else :
628
564
self ._adb .click_by_text_after_refresh ("发送" )
629
565
630
566
print (' !! <== 发送成功 <== ' )
631
567
write_to_excel (phone_file_path , phone_can_write_index , phone_write_col , "发送成功" )
632
- time .sleep (2 )
568
+ time .sleep (3 )
633
569
self ._adb .adb_put_back ()
634
570
if self ._adb .find_node_by_text ('添加到通讯录' ):
635
571
print ("操作可能太频繁被限制,建议换号或者等会再试" )
@@ -647,12 +583,16 @@ def add_friends(self, phone):
647
583
# self.push('failed', phone + '同时拥有微信和企业微信')
648
584
# self._adb.adb_put_back()
649
585
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, "该用户不存在 ")
653
589
654
590
# 清空已输入的字符
655
591
self .clean_phone ()
592
+ try :
593
+ self .clean_phone ()
594
+ except :
595
+ pass
656
596
657
597
def fuck (self ):
658
598
"""
@@ -683,35 +623,62 @@ def Imsorry(self):
683
623
684
624
685
625
def main (self ):
626
+ """
627
+ 间断时间较长
628
+ :return:
629
+ """
630
+ global phone_can_write_index
686
631
#读取手机号数据
687
632
phone_datas = [get_keywords_data (phoe_tables , i , phone_get_col ) for i in
688
633
range (1 , phoe_tables .nrows )]
689
634
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
690
650
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
691
656
692
657
def test (self ):
658
+ """
659
+ 间断时间较短
660
+ :return:
661
+ """
693
662
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
- # 添加好友
703
663
self ._adb .click_add_friend ()
704
664
# 点击那两个 微信号/手机号
705
665
self ._adb .click_wechat_and_friend ()
706
- # 添加好友
707
666
phone_datas = [get_keywords_data (phoe_tables , i , phone_get_col ) for i in
708
667
range (1 , phoe_tables .nrows )]
709
668
for phone in phone_datas :
710
669
711
670
self .add_friends (phone )
671
+ time .sleep (wait_time )
712
672
phone_can_write_index += 1
673
+ y = input ("{}个电话号码已加完,是否关闭程序" .format (len (phone_datas )))
674
+ if y :
675
+ pass
713
676
714
677
715
678
if __name__ == '__main__' :
716
679
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