You are here: Practice · Battery

After the first three feel less scary

Your text file can ask the phone a question.

Use Termux:API so the script asks how full the battery is. You do not need to memorize the helper lines. You need the idea: run a phone command, read packed text, print one number.

Example idea. Type it only after hello, guess, and a file feel less scary.

battery.py
import subprocess, json
raw = subprocess.check_output(["termux-battery-status"])
data = json.loads(raw)
print("Battery:", data["percentage"], "%")

Run the phone’s battery command, read the answer (JSON), print the percentage.

python ~/learn/battery.py

If it breaks

termux-battery-status itself must work first. If that command fails, the pair is incomplete. Termux:API room.

JSON looks loud. Tap the lunch box.

The point

A script can use the phone, not only print words you typed. Clipboard can be a second experiment on another day.

Later: tiny app ideas →

Next step

App ideas wait until hello.py feels ordinary. Extras are here if you want another tiny file.