Skip to content
Snippets Groups Projects
Unverified Commit 7921b428 authored by hanfi's avatar hanfi
Browse files

add some python helpers

parent ebd75b11
No related branches found
No related tags found
No related merge requests found
from ppadb.device import Device
from ppadb.client import Client as AdbClient
from os import makedirs
INVENTORY_PATH = './inventory'
CACHE_PATH = './apps'
_client = AdbClient()
makedirs(INVENTORY_PATH, exist_ok=True)
makedirs(CACHE_PATH, exist_ok=True)
File added
File added
from . import _client, Device, CACHE_PATH
from os.path import isfile
from bs4 import BeautifulSoup
import requests
def _download_apk(package:str):
print("download", package)
response = requests.get(f"https://f-droid.org/en/packages/{package}/")
soup = BeautifulSoup(response.text, 'html.parser')
latest = soup.find(id="latest").find(class_="package-version-download").find("a")["href"]
print("downloading", latest, " ",end="")
with requests.get(latest, stream=True) as r:
r.raise_for_status()
with open(f"{CACHE_PATH}/{package}.apk", "wb") as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
print(".",end="")
print("")
print("downloaded", package)
def install_packages(packages:list[str]=[], device: Device = None):
print(device.get_serial_no())
installed = device.list_packages()
for package in packages:
if not package in installed:
print('need install', package)
if not (isfile(f'{CACHE_PATH}/{package}.apk')):
_download_apk(package)
device.install(f'{CACHE_PATH}/{package}.apk')
if __name__ == '__main__':
with open('packages.txt') as p:
for line in p:
print(line)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment