bitget_nft2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | # coding: utf-8# import uiautomator2 as u2 import time from tqdm import tqdm from loguru import logger from ocr_test import OCR_UI2 class ClickTimeOutException(Exception): def __init__( self , message = "This is a custom exception" ): self .message = message super ().__init__( self .message) def xpath是否存在(xpath,timeout = 30 ): for index in range ( 0 ,timeout): wallet_ele = d.xpath(xpath).exists if (wallet_ele): logger.success(f "xpath已找到:{xpath}" ) return True else : logger.debug(f "xpath未找到 {xpath} 等待:{index}" ) time.sleep( 1 ) raise ClickTimeOutException(f "xpath等待超时:找不到 {xpath} " ) def click_5s_desc(xpath,timeout = 20 ): for index in range ( 0 ,timeout): wallet_ele = d(description = xpath).exists if (wallet_ele): d(description = xpath).click() logger.success(f "{xpath} --- desc 成功点击" ) return True else : logger.debug(f "desc 未找到 {xpath} 等待:{index}" ) time.sleep( 1 ) raise ClickTimeOutException(f "{xpath} --- desc 点击失败" ) def OCR_click(xpath,timeout = 20 ): for index in range ( 0 ,timeout): find = ocr.是否存在文本(xpath) if (find): pos_x,pos_y = ocr.查询文本坐标百分比(xpath) d.click(pos_x,pos_y) logger.success(f "{xpath} --- OCR 成功点击" ) return True else : logger.debug(f "OCR 未找到 {xpath} 等待:{index}" ) time.sleep( 1 ) raise ClickTimeOutException(f "{xpath} --- OCR 点击失败" ) def 领取nft(): click_5s_desc( "首页" , 20 ) click_5s_desc( "赚币中心" ) time.sleep( 2 ) d(scrollable = True ).scroll.toEnd() time.sleep( 2 ) d.click( 0.806 , 0.413 ) d(scrollable = True ).scroll.toEnd() d.xpath( '//*[contains(@content-desc, "SecondLive")]//android.view.View[1]' ).click() d(description = "以后再说" ).click_exists() claim = xpath是否存在( '//*[@content-desc="SecondLive"]' ) if claim: time.sleep( 1 ) OCR_click( "验证" ) find = ocr.是否存在文本(d, "交互已完成" ) if find: return time.sleep( 5 ) def click_5s(xpath,timeout = 10 ,wait = 0 ): for index in range ( 0 ,timeout): wallet_ele = d.xpath(xpath).exists if (wallet_ele): time.sleep(wait) d.xpath(xpath).click() logger.success(f "{xpath} --- 成功点击" ) return True else : logger.debug(f "xpath未找到 {xpath} 等待:{index}" ) time.sleep( 1 ) raise ClickTimeOutException(f "{xpath} --- 点击失败" ) def 添加私钥(privatekey): d.app_start( "com.bitkeep.wallet" , use_monkey = True ) d(description = "暂不开启" ).click_exists() click_5s( '//*[contains(@content-desc, "钱") and contains(@content-desc, "包") and contains(@content-desc, "我")]/android.widget.ImageView[1]' , 20 , 2 ) click_5s_desc( "添加钱包" ) click_5s_desc( "助记词/私钥钱包\n支持12位、24位助记词导入或私钥导入" ) for index in range ( 0 , 6 ): d(description = "0" ).click() click_5s( '//android.widget.EditText' ) time.sleep( 2 ) d.send_keys(privatekey, True ) #d.set_fastinput_ime(False) click_5s_desc( "确认导入" ) #d(scrollable=True).scroll.to(description="Polygon") click_5s( '//*[@content-desc="Polygon"]' ) click_5s_desc( "确认" ) click_5s_desc( "开始探索" ) return True if __name__ = = '__main__' : d = u2.connect( "22b4097f" ) ocr = OCR_UI2(d) d.set_fastinput_ime( True ) print (d.info) acc_list = [] with open ( "address.txt" , "r" ) as f: lines = f.readlines()[ 691 :] bar = tqdm(total = len (lines)) for line in lines: line = line.replace( "\n" ,"") addr,key = line.split( "----" ) acc = { "private_key" : key, "address" : addr } acc_list.append(acc) for acc in acc_list: try : add_status = 添加私钥(acc[ 'private_key' ]) if add_status: 领取nft() logger.success(f "{acc['address']} 领取nft成功!!!" ) d.app_stop( "com.bitkeep.wallet" ) bar.update( 1 ) except BaseException as e: logger.error(f "{acc['address']} 领取nft失败!!! ---- {e}" ) finally : try : d.app_stop( "com.bitkeep.wallet" ) except : pass # 检查元素是否可点击 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | # coding: utf-8# import uiautomator2 as u2 import time from loguru import logger from cnocr import CnOcr class OCR_UI2(): def __init__( self ,device): self .device = device self .ocr = CnOcr() def 计算文本中心点坐标( self ,points): if len (points) = = 0 : return None num_points = len (points) sum_x = sum (point[ 0 ] for point in points) sum_y = sum (point[ 1 ] for point in points) centroid_x = sum_x / num_points centroid_y = sum_y / num_points return (centroid_x, centroid_y) # Example usage def 坐标转百分比( self ,x,y,image): width = image.width hight = image.height pos_w = "{:.4f}" . format (x / width) pos_y = "{:.4f}" . format (y / hight) return (pos_w,pos_y) def 是否存在文本( self ,find_str): time.sleep( 1 ) find = False image = self .device.screenshot() outs = self .ocr.ocr(image) texts = [out[ 'text' ] for out in outs] for text in texts: if find_str in text: logger.success(f "OCR查找成功:{text} --- 预期:{find_str}" ) find = True return find def 查询文本坐标百分比( self ,find_str): image = self .device.screenshot() outs = self .ocr.ocr(image) for line in outs: if find_str in line[ 'text' ]: (x,y) = self .计算文本中心点坐标(line[ 'position' ]) (pos_w,pos_y) = self .坐标转百分比(x,y,image) logger.success(f "查询坐标百分比成功:{ line['text']} --- 预期:{find_str} ---坐标:{(x,y)} --- 坐标百分比:{(pos_w,pos_y)}" ) return ( float (pos_w), float (pos_y)) logger.debug(f "查询坐标百分比失败:预期:{find_str}" ) return False def 查询文本坐标( self ,find_str): image = self .device.screenshot() outs = self .ocr.ocr(image) for line in outs: if find_str in line[ 'text' ]: (x,y) = self .计算文本中心点坐标(line[ 'position' ]) logger.success(f "查询坐标百分比成功:{ line['text']} --- 预期:{find_str} ---坐标:{(x,y)}" ) return ( int (x), int (y)) logger.debug(f "查询坐标失败:预期:{find_str}" ) return False if __name__ = = '__main__' : d = u2.connect( "5f83933a" ) ocr = OCR_UI2(d) ocr.查询文本坐标百分比( "回家" ) |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
2019-03-15 微信公众号开发-java版 腾讯课堂(开发接入)