Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python to automatically collect Ant Forest Energy

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use Python to achieve timing automation to collect ant forest energy", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to use Python to achieve timing automation to collect ant forest energy" bar!

1. Overview

When it comes to ant forest, everyone should know, have you ever been collected by your friends because you forgot to collect energy?

If you are not a heavy user of Ant Forest, it may not matter to you that someone else has collected energy.

But if you are a heavy user of ant forest and encounter energy stolen.

two。 Environment

The main environment of this paper is as follows:

Win7 millet 5sPython3.7Appium1.5 Alipay 10.2.6.70103. Realize

The basic idea of function realization is:

Open Alipay and enter the ant forest to collect your own energy.

After collecting your own energy, click to find energy to enter the good friend ant forest, collect your friend energy, and so on.

Next let's take a look at the main code implementation.

The parameter configuration code is implemented as follows:

Desired_caps = {

"platformName": "Android", # system

"platformVersion": "8.0.0", # system version number

"deviceName": "M5s", # device name

"appPackage": "com.eg.android.AlipayGphone", # package name

"appActivity": "AlipayLogin", # main Activity when app starts

'noReset': True # retains session information to avoid re-login

}

Usually everyone will put the ant forest on the home page of Alipay, at this time we open Alipay and directly click on the ant forest option to enter.

The code is implemented as follows:

Driver.find_elements_by_id ('com.alipay.android.phone.openplatform:id/home_app_view') [10] .click ()

After entering our own ant forest, we begin to collect our own energy, because the new version of Alipay can no longer locate the energy ball elements, so we need to click in the area where the energy ball may appear. The code for collecting energy is implemented as follows:

# collecting energy

Def collect_energy (driver):

Print ('start collecting energy')

# get the width and height of the phone screen

Width = int (driver.get_window_size () ['width'])

Height = int (driver.get_window_size () ['height'])

# possible regional coordinates of the energy ball

Start_x = 110,

End_x = 940

Start_y = 460

End_y = 880

For i in range (start_y, end_y, 80):

For j in range (start_x, end_x, 80):

Tap_x1 = int ((int (j) / width) * width)

Tap_y1 = int ((int (I) / height) * height)

# Click to specify coordinates

Driver.tap ([(tap_x1, tap_y1), (tap_x1, tap_y1)], 1000)

Print ('energy collection is complete')

After your energy collection is finished, click find Energy to enter my friend Ant Forest to continue to collect energy. The code is implemented as follows:

# find energy

Def search_energy (driver):

Print ('find energy, collect energy from friends')

Time.sleep (3)

# Click to find energy

Driver.tap ([(1000, 1520), (1080, 1580)], 1000)

Time.sleep (3)

# collect energy from friends

Collect_energy (driver)

Time.sleep (3)

# after collection, continue to look for energy

Search_energy (driver)

After the function of energy collection is realized, we can use timing tasks to achieve timing collection. Let's take a look at the implementation of timing tasks.

For the implementation of scheduled tasks, we use the apscheduler component, which needs to be installed by pip install apscheduler before use.

The code implementation of the scheduled task is as follows:

Scheduler = BlockingScheduler ()

# collect_main: timed execution method

Scheduler.add_job (collect_main, 'cron', hour=20, minute=23, second=20)

Try:

Scheduler.start ()

Except (KeyboardInterrupt, SystemExit):

Pass thank you for your reading, the above is "how to use Python to achieve timing automation to collect ant forest energy" content, after the study of this article, I believe you on how to use Python to achieve timing automation to collect ant forest energy this problem has a deeper understanding, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report