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 recover the lost energy in ant forest

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

Editor to share with you how to use Python to recover the lost energy in the ant forest. I hope you will gain something after reading this article. Let's discuss it together.

1 brief introduction of ant forest

Ant Forest is a public welfare project designed to drive the public to reduce emissions. Everyone's low-carbon behavior can be regarded as "green energy" in the ant forest. When "green energy" accumulates to a certain extent, you can use your mobile phone to apply for planting a real tree in areas where ecology is in urgent need of restoration, or to "claim" protection rights and interests in areas where biodiversity is in urgent need of protection.

The ecological restoration projects of ant forest in various places are donated funds to public welfare organizations by ant groups, planting and maintenance and other specific work are organized by public welfare institutions, and are supervised by local forestry departments. All projects have corresponding donation agreements and acceptance reports. [23]

On September 19, 2019, China's "Ant Forest" project won the United Nations "Guardian of the Earth Award".

In the five years since its launch in 2016, the ant forest has led more than 613 million people to participate in low-carbon life and generated more than 20 million tons of "green energy", according to data released by the Ministry of Ecology and Environment's "National low carbon Day" home event in 2021.

In order to encourage the public to live a low-carbon life, the ant forest has participated in the ecological restoration work in 11 provinces in the past five years, planting a total of 326 million trees, including more than 100 million in Gansu and Inner Mongolia. At the same time, the Ant Forest has also set up 18 public welfare protection sites in 10 provinces across the country, protecting more than 1500 species of wild animals and plants. Through ecological and environmental protection projects in various places, the ant forest has created a total of 2.38 million green jobs such as planting, maintenance and patrolling, bringing an increase of 350 million yuan in labor income for the local people.

Ant Group publicly declared that the annual investment of hundreds of millions of dollars in ant forest is a pure public welfare donation. Once the trees planted in the ant forest are donated, they belong to the state and society. if these trees produce carbon sequestration in the future, they will all be used for public welfare. Ant Forest has never been involved in carbon trading. If the individual carbon reductions recorded in the ant forest can be traded in the future, all the benefits generated will belong to the user, not the ant forest.

2 the passing of Sichuan sighs

In the past, for me, who was easy to ignore the support treasure, a lot of energy was snatched by my friends, and then I was always looking for an opportunity to get back the lost energy on a large scale. Due to the limited ability of the code, it had not been implemented. Recently, I wanted to do it very much. I sighed not in Shikawa, and let others envy me.

3 result display

Steal again in a few minutes, make a lot of money, ha!

4 Python--uiautomator2 library installation

UiAutomator is a Java library provided by Google for Android automation testing. It can get any control property of any APP on the screen and manipulate it at will. Uiautomator2 is the interface encapsulation of python on Uiautomator. Simply put, Uiautomator2 can see what controls are on the phone's current screen, what their coordinates are, and can also simulate clicks.

Let's talk about how to install the uiautomator2 library (which I often use).

5 Python code implementation # = import related library = import numpy as npimport matplotlib.pyplot as pltimport matplotlib as mplmpl.rcParams ['font.sans-serif'] = [' SimHei'] # specify the default font mpl.rcParams ['axes.unicode_minus'] = False # solve the problem that the saved image is a negative sign'-'displayed as a square import matplotlib Matplotlib.use ('TkAgg') import uiautomator2 as u2import timeimport random#=# wired connection, phone needs to be plugged into the computer, Alipay fully starts = d = u2.connect () # d.app_stop ("com.eg.android.AlipayGphone") print ("open Alipay") d.app_start ("com.eg.android.AlipayGphone") time.sleep (2) # # dormant 2s waiting for Alipay to fully start # = enter the ant forest = print ("open the ant forest") Wait for 5s. ") D (text= "ant forest"). Click () time.sleep (5) # # my phone is stuck. It will take a few seconds to fully load after entering the ant forest. # = collect energy = def collectEnergy (cnt): print ("start stealing energy for the d time!" % cnt) # = = start scanning and click on areas capable of appearing = = for x in range (150 random.randint 1000150): for y in range (600900150): d.long_click (x + random.randint (1010), y + random.randint (10) 20) Time.sleep if cnt! = 1: d.click (536-1816) cnt = 1while True: collectEnergy (cnt) a = d.xpath ("/ / * [@ resource-id='J_tree_dialog_wrap']") .get () .bounds d.click (1000 A [3]-80) # find the coordinates of the energy button # = if the page appears "return to my Forest" means there is no energy to steal End = if d.xpath ('/ * [@ text= "return to my forest]') .click_exists (timeout=2.0): break cnt + = 1print (" # end # ") d.app_stop (" com.eg.android.AlipayGphone ") # quit Alipay after reading this article, I believe you have some understanding of" how to use Python to recover the energy lost in the ant forest " If you want to know more related knowledge, welcome to follow the industry information channel, thank you for reading!

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

Development