atom_data.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. """
  2. 启动app
  3. """
  4. def start_app(request_id, target_app="dongchedi", target_version="7.9.0",
  5. package_name="com.ss.android.auto", timeout=10, sleep_time=3):
  6. data = {
  7. "jsonrpcVersion": "2.0",
  8. "id": request_id,
  9. "type": "scenes",
  10. "target_app": target_app,
  11. "package_name": package_name,
  12. "target_version": target_version,
  13. "params": {
  14. "action": {
  15. "method": "start_app",
  16. "timeout": timeout,
  17. "sleep_time": sleep_time
  18. }
  19. }
  20. }
  21. return data
  22. """
  23. 关闭app
  24. """
  25. def stop_app(request_id, target_app="dongchedi", target_version="7.9.0",
  26. package_name="com.ss.android.auto", timeout=10, sleep_time=10):
  27. data = {
  28. "jsonrpcVersion": "2.0",
  29. "id": request_id,
  30. "type": "scenes",
  31. "target_app": target_app,
  32. "package_name": package_name,
  33. "target_version": target_version,
  34. "params": {
  35. "action": {
  36. "method": "stop_app",
  37. "timeout": timeout,
  38. "sleep_time": sleep_time
  39. }
  40. }
  41. }
  42. return data
  43. """
  44. 根据控件id单击
  45. """
  46. def single_click_by_control(request_id, target_app="dongchedi",
  47. target_version="7.9.0",
  48. package_name="com.ss.android.auto",
  49. control_ids="",
  50. control_id="com.ss.android.auto:id/c7p",
  51. item_index=None,
  52. sub_item_index=None,
  53. timeout=10, sleep_time=10):
  54. data = {
  55. "jsonrpcVersion": "2.0",
  56. "id": request_id,
  57. "type": "scenes",
  58. "target_app": target_app,
  59. "package_name": package_name,
  60. "target_version": target_version,
  61. "params": {
  62. "action": {
  63. "method": "click",
  64. "type": "1",
  65. "control_id": control_id,
  66. "control_ids": control_ids,
  67. "item_index": item_index,
  68. "sub_item_index": sub_item_index,
  69. "timeout": timeout,
  70. "sleep_time": sleep_time
  71. }
  72. }
  73. }
  74. return data
  75. """
  76. 根据控件id单击
  77. """
  78. def single_click_by_control_exact(request_id, target_app="dongchedi",
  79. target_version="7.9.0",
  80. package_name="com.ss.android.auto",
  81. control_ids="",
  82. control_id="com.ss.android.auto:id/c7p",
  83. item_index=None,
  84. sub_item_index=None,
  85. timeout=10, sleep_time=10):
  86. data = {
  87. "jsonrpcVersion": "2.0",
  88. "id": request_id,
  89. "type": "scenes",
  90. "target_app": target_app,
  91. "package_name": package_name,
  92. "target_version": target_version,
  93. "params": {
  94. "action": {
  95. "method": "exact_click",
  96. "type": "1",
  97. "control_id": control_id,
  98. "control_ids": control_ids,
  99. "item_index": item_index,
  100. "sub_item_index": sub_item_index,
  101. "timeout": timeout,
  102. "sleep_time": sleep_time
  103. }
  104. }
  105. }
  106. return data
  107. """
  108. 根据屏幕位置点击多次
  109. """
  110. def many_click_by_position(request_id, target_app="dongchedi",
  111. target_version="7.9.0",
  112. package_name="com.ss.android.auto",
  113. position="center",
  114. count=5,
  115. timeout=10, sleep_time=10):
  116. data = {
  117. "jsonrpcVersion": "2.0",
  118. "id": request_id,
  119. "type": "scenes",
  120. "target_app": target_app,
  121. "package_name": package_name,
  122. "target_version": target_version,
  123. "params": {
  124. "action": {
  125. "method": "many_click",
  126. "type": "1",
  127. "position": position,
  128. "count": count,
  129. "timeout": timeout,
  130. "sleep_time": sleep_time
  131. }
  132. }
  133. }
  134. return data
  135. '''
  136. 根据文本单击
  137. '''
  138. def single_click_by_text(request_id, target_app="dongchedi", target_version="7.9.0", sleep_time=10,
  139. package_name="com.ss.android.auto", text="车友圈", timeout=10, similarity=1, max_page="5"):
  140. data = {
  141. "jsonrpcVersion": "2.0",
  142. "id": request_id,
  143. "type": "scenes",
  144. "target_app": target_app,
  145. "package_name": package_name,
  146. "target_version": target_version,
  147. "params": {
  148. "action": {
  149. "method": "click",
  150. "type": "2",
  151. "control_text": text,
  152. "timeout": timeout,
  153. "sleep_time": sleep_time,
  154. "similarity": similarity,
  155. "max_page": max_page
  156. }
  157. }
  158. }
  159. return data
  160. """
  161. 通过图片识别后单击
  162. """
  163. def single_click_by_pic(request_id, target_app="dongchedi", target_version="7.9.0", sleep_time=10,
  164. package_name="com.ss.android.auto", base64_pic="data:image/gif;base64,"
  165. "R0lGODlhHAAmAKIHAKqqqsvLy0hISObm5vf394uLiwAAAP///yH5BEoqQqJKAIBaQOVKHAXr3t7txgBjboSvB8EpLoFZywOAo3LFE5lYs/QW9LT1TRk1V7S2xYJADs=",
  166. timeout=10):
  167. data = {
  168. "jsonrpcVersion": "2.0",
  169. "id": request_id,
  170. "type": "scenes",
  171. "target_app": target_app,
  172. "package_name": package_name,
  173. "target_version": target_version,
  174. "params": {
  175. "action": {
  176. "method": "click",
  177. "type": "3",
  178. "base64_pic": base64_pic,
  179. "timeout": timeout,
  180. "sleep_time": sleep_time
  181. }
  182. }
  183. }
  184. return data
  185. '''
  186. 滑动手机屏幕的百分比
  187. '''
  188. def swipe_screen(request_id, target_app="dongchedi", target_version="7.9.0", package_name="com.ss.android.auto",
  189. scale=0.5, timeout=10, sleep_time=10, direction="up", scale_from=None, scale_to=None, duration=None):
  190. data = {
  191. "jsonrpcVersion": "2.0",
  192. "id": request_id,
  193. "type": "scenes",
  194. "target_app": target_app,
  195. "package_name": package_name,
  196. "target_version": target_version,
  197. "params": {
  198. "action": {
  199. "method": "swipe",
  200. "timeout": timeout,
  201. "direction": direction,
  202. "scale": scale,
  203. "sleep_time": sleep_time,
  204. "scaleFrom": scale_from,
  205. "scaleTo": scale_to,
  206. "duration": duration
  207. }
  208. }
  209. }
  210. return data
  211. '''
  212. 连续滑动手机屏幕的百分比
  213. '''
  214. def continual_swipe_screen(request_id, target_app="dongchedi", target_version="7.9.0",
  215. package_name="com.ss.android.auto",
  216. scale=0.5, timeout=10, sleep_time=10, direction="up", continuous_time=None,
  217. continuous_time_interval=None, continuous_count=None):
  218. data = {
  219. "jsonrpcVersion": "2.0",
  220. "id": request_id,
  221. "type": "scenes",
  222. "target_app": target_app,
  223. "package_name": package_name,
  224. "target_version": target_version,
  225. "params": {
  226. "action": {
  227. "method": "swipe",
  228. "timeout": timeout,
  229. "direction": direction,
  230. "scale": scale,
  231. "sleep_time": sleep_time,
  232. # 持续时间 单位:s
  233. "continuous_time": continuous_time,
  234. # 睡眠时间区间(传输一个string类型 区间首尾使用,分割。eg:'3,50')
  235. "sleep_time_interval": continuous_time_interval,
  236. # 持续次数与continuous_time互斥 都传以continuous_time为主
  237. "continuous_count": continuous_count
  238. }
  239. }
  240. }
  241. return data
  242. '''
  243. 根据控件id长按某个控件
  244. '''
  245. def long_press_by_control(request_id, target_app="dongchedi", target_version="7.9.0",
  246. package_name="com.ss.android.auto",
  247. control_id="com.ss.android.auto:id/c7d", timeout=10, sleep_time=10):
  248. data = {
  249. "jsonrpcVersion": "2.0",
  250. "id": request_id,
  251. "type": "scenes",
  252. "target_app": target_app,
  253. "package_name": package_name,
  254. "target_version": target_version,
  255. "params": {
  256. "action": {
  257. "method": "long_press",
  258. "control_id": control_id,
  259. "timeout": timeout,
  260. "sleep_time": sleep_time
  261. }
  262. }
  263. }
  264. return data
  265. """
  266. 根据控件id输入文本(包括emoj表情)
  267. """
  268. def send_text_by_control(request_id, target_app="dongchedi", target_version="7.9.0",
  269. package_name="com.ss.android.auto", control_id="com.ss.android.auto:id/cg",
  270. content="文章不错,写的很好👍", timeout=10, sleep_time=10, item_index=None):
  271. data = {
  272. "jsonrpcVersion": "2.0",
  273. "id": request_id,
  274. "type": "scenes",
  275. "target_app": target_app,
  276. "package_name": package_name,
  277. "target_version": target_version,
  278. "params": {
  279. "action": {
  280. "method": "send_text",
  281. "control_id": control_id,
  282. "text": content,
  283. "timeout": timeout,
  284. "sleep_time": sleep_time,
  285. "item_index": item_index
  286. }
  287. }
  288. }
  289. return data
  290. """
  291. 根据控件id获取内容
  292. 如果id/帖子正文内容未获取到 接口返回eleNotFound,包含点击操作
  293. :param
  294. type - 1- 帖子正文内容 2- 控件id的文本
  295. """
  296. """
  297. """
  298. def get_content_by_control(request_id, target_app="dongchedi", target_version="7.9.0", operator_type=1, max_page="10",
  299. package_name="com.ss.android.auto", control_id="com.ss.android.auto:id/cg",
  300. timeout=10, sleep_time=10, title="听说24年不送绿牌"):
  301. data = {
  302. "jsonrpcVersion": "2.0",
  303. "id": request_id,
  304. "type": "scenes",
  305. "target_app": target_app,
  306. "package_name": package_name,
  307. "target_version": target_version,
  308. "params": {
  309. "action": {
  310. "method": "spider_content",
  311. "type": operator_type,
  312. "title": title,
  313. "max_page": max_page,
  314. "control_id": control_id,
  315. "timeout": timeout,
  316. "sleep_time": sleep_time
  317. }
  318. }
  319. }
  320. return data
  321. """
  322. 先下滑若干屏幕
  323. 然后根据匹配到的文本点击
  324. """
  325. def click_by_content(request_id, target_app="dongchedi", target_version="7.9.0", max_page="10", operator_type=1,
  326. package_name="com.ss.android.auto", timeout=10, sleep_time=10, title="听说24年不送绿牌"):
  327. data = {
  328. "jsonrpcVersion": "2.0",
  329. "id": request_id,
  330. "type": "scenes",
  331. "target_app": target_app,
  332. "package_name": package_name,
  333. "target_version": target_version,
  334. "params": {
  335. "action": {
  336. "method": "spider_content",
  337. "title": title,
  338. "type": operator_type,
  339. "max_page": max_page,
  340. "timeout": timeout,
  341. "sleep_time": sleep_time
  342. }
  343. }
  344. }
  345. return data
  346. """
  347. 根据图片判断页面图片是否存在
  348. """
  349. def check_pic_exist(request_id, target_app="dongchedi", target_version="7.9.0",
  350. package_name="com.ss.android.auto",
  351. pic_base64="com.ss.android.auto:id/c7p", timeout=10, sleep_time=10, direction="up", swipe_count=0):
  352. data = {
  353. "jsonrpcVersion": "2.0",
  354. "id": request_id,
  355. "type": "scenes",
  356. "target_app": target_app,
  357. "package_name": package_name,
  358. "target_version": target_version,
  359. "params": {
  360. "action": {
  361. "method": "check_pic",
  362. "type": "1",
  363. "pic_base64": pic_base64,
  364. "timeout": timeout,
  365. "sleep_time": sleep_time,
  366. # (默认up。up 向上滑动(及屏幕向下翻取),down向下滑动(及屏幕向上翻取))
  367. "direction": direction,
  368. # 滑动次数(默认0 不滑动)
  369. "swipe_count": swipe_count
  370. }
  371. }
  372. }
  373. return data
  374. """
  375. 根据图片进行点击
  376. """
  377. def click_pic(request_id, target_app="dongchedi", target_version="7.9.0",
  378. package_name="com.ss.android.auto",
  379. pic_base64="com.ss.android.auto:id/c7p", timeout=10, sleep_time=10):
  380. data = {
  381. "jsonrpcVersion": "2.0",
  382. "id": request_id,
  383. "type": "scenes",
  384. "target_app": target_app,
  385. "package_name": package_name,
  386. "target_version": target_version,
  387. "params": {
  388. "action": {
  389. "method": "click_pic",
  390. "type": "1",
  391. "pic_base64": pic_base64,
  392. "timeout": timeout,
  393. "sleep_time": sleep_time
  394. }
  395. }
  396. }
  397. return data
  398. """
  399. 操作失败
  400. """
  401. def operation_fail(request_id, target_app="dongchedi", target_version="7.9.0",
  402. package_name="com.ss.android.auto", step="action0"):
  403. data = {
  404. "jsonrpcVersion": "2.0",
  405. "id": request_id,
  406. "type": "scenes",
  407. "target_app": target_app,
  408. "package_name": package_name,
  409. "target_version": target_version,
  410. "params": {
  411. "action": {
  412. "step": step
  413. }
  414. }
  415. }
  416. return data
  417. """
  418. 返回上一页
  419. """
  420. def back_last_page(request_id, target_app="dongchedi", target_version="7.9.0", package_name="com.ss.android.auto",
  421. sleep_time=10,
  422. timeout=10):
  423. data = {
  424. "jsonrpcVersion": "2.0",
  425. "id": request_id,
  426. "type": "scenes",
  427. "target_app": target_app,
  428. "package_name": package_name,
  429. "target_version": target_version,
  430. "params": {
  431. "action": {
  432. "method": "back",
  433. "timeout": timeout,
  434. "sleep_time": sleep_time
  435. }
  436. }
  437. }
  438. return data
  439. """
  440. 根据元素id获取到对应text信息
  441. text信息返回在下一次调用接口result中的performActionText字段返回
  442. """
  443. def get_text_by_control(request_id, target_app="dongchedi", target_version="7.9.0", max_page="10",
  444. package_name="com.ss.android.auto", control_id="com.ss.android.auto:id/cg",
  445. timeout=10, sleep_time=10, item_index=None, sub_item_index=None):
  446. data = {
  447. "jsonrpcVersion": "2.0",
  448. "id": request_id,
  449. "type": "scenes",
  450. "target_app": target_app,
  451. "package_name": package_name,
  452. "target_version": target_version,
  453. "params": {
  454. "action": {
  455. "method": "spider_text_get",
  456. # 最大下滑页
  457. "max_page": max_page,
  458. "control_id": control_id,
  459. "timeout": timeout,
  460. "sleep_time": sleep_time,
  461. "item_index": item_index,
  462. "sub_item_index": sub_item_index
  463. }
  464. }
  465. }
  466. return data
  467. """
  468. 根据元素id获取到对应text信息
  469. text信息返回在下一次调用接口result中的performActionText字段返回
  470. """
  471. def get_text_by_control_comment(request_id, target_app="dongchedi", target_version="7.9.0", max_page="10",
  472. package_name="com.ss.android.auto", control_id="com.ss.android.auto:id/cg",
  473. timeout=10, sleep_time=10, item_index=None, sub_item_index=None):
  474. data = {
  475. "jsonrpcVersion": "2.0",
  476. "id": request_id,
  477. "type": "scenes",
  478. "target_app": target_app,
  479. "package_name": package_name,
  480. "target_version": target_version,
  481. "params": {
  482. "action": {
  483. "method": "spider_text_list_get",
  484. # 最大下滑页
  485. "max_page": max_page,
  486. "control_id": control_id,
  487. "timeout": timeout,
  488. "sleep_time": sleep_time,
  489. "item_index": item_index,
  490. "sub_item_index": sub_item_index
  491. }
  492. }
  493. }
  494. return data
  495. '''
  496. 根据text 点击对应的子元素id
  497. '''
  498. def spider_content_parent_find_click(request_id, target_app="dongchedi", target_version="7.9.0",
  499. package_name="com.ss.android.auto", title=None,
  500. child_control_id=None, timeout=10, sleep_time=10, item_index=None):
  501. data = {
  502. "jsonrpcVersion": "2.0",
  503. "id": request_id,
  504. "type": "scenes",
  505. "target_app": target_app,
  506. "package_name": package_name,
  507. "target_version": target_version,
  508. "params": {
  509. "action": {
  510. "method": "spider_content_parent_find_click",
  511. "child_control_id": child_control_id,
  512. "timeout": timeout,
  513. "title": title,
  514. "item_index": item_index,
  515. "sleep_time": sleep_time
  516. }
  517. }
  518. }
  519. return data