# coding: utf-8#
import uiautomator2 as u2
import time
from tqdm import tqdm
from loguru import logger
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)
logger.error(f"xpath等待超时:{xpath}是否存在")
return False
def 领取nft():
time.sleep(2)
d(description="首页").click()
time.sleep(2)
d(description="赚币中心").click()
#d.xpath('//*[contains(@content-desc, "新人任务")]').click()
time.sleep(3)
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:
d.click(0.501, 0.874)
time.sleep(5)
def click_5s(xpath,timeout=10):
for index in range(0,timeout):
wallet_ele = d.xpath(xpath).exists
if(wallet_ele):
d.xpath(xpath).click()
logger.success("成功点击")
return True
else:
logger.debug(f"xpath未找到 {xpath} 等待:{index}")
time.sleep(1)
logger.error("点击失败")
return False
def 添加私钥(privatekey):
d.app_start("com.bitkeep.wallet", use_monkey=True)
d(description="暂不开启").click_exists()
time.sleep(10)
#d(description="钱包").click()
#d.xpath('//*[contains(@content-desc, "我")]/android.widget.ImageView[1]').click()
click_5s('//*[contains(@content-desc, "钱") and contains(@content-desc, "包") and contains(@content-desc, "我")]/android.widget.ImageView[1]')
d(description="添加钱包").click()
d(description="助记词/私钥钱包\n支持12位、24位助记词导入或私钥导入").click()
for index in range(0, 6):
d(description="0").click()
time.sleep(5)
click_5s('//android.widget.EditText')
time.sleep(2)
d.send_keys(privatekey, True)
#d.set_fastinput_ime(False)
time.sleep(2)
d(description="确认导入").click()
#d(scrollable=True).scroll.to(description="Polygon")
d.xpath('//*[@content-desc="Polygon"]').click()
d(description="确认").click()
try:
d(description="开始探索").click()
except:
pass
return True
if __name__ == '__main__':
d = u2.connect("22b4097f")
d.set_fastinput_ime(True)
print(d.info)
#领取nft()
acc_list =[]
with open("address.txt","r") as f:
lines = f.readlines()[300:]
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
# 检查元素是否可点击