updater.py aktualisiert
better outputs
This commit is contained in:
parent
109925daae
commit
64f1e9ce06
41
updater.py
41
updater.py
@ -1,5 +1,5 @@
|
||||
#APK Updater v1.1
|
||||
#(C) 2023 by Manuel Kamper (kmpr.at)
|
||||
#APK Updater v1.2
|
||||
#(C) 2024 by Manuel Kamper (kmpr.at)
|
||||
#Do not remove copyright when distributing!
|
||||
import feedparser, mysql.connector, os, glob, time, shutil
|
||||
from datetime import datetime
|
||||
@ -13,10 +13,10 @@ repo_path = "/mnt/data/repo"
|
||||
temp_path = "/tmp/apkdown"
|
||||
|
||||
mydb = mysql.connector.connect(
|
||||
host="localhost",
|
||||
user="appstore",
|
||||
password="<your-pwd>",
|
||||
database="appstore"
|
||||
host="localhost",
|
||||
user="appstore",
|
||||
password="<your-pwd>",
|
||||
database="appstore"
|
||||
)
|
||||
|
||||
### NO EDITS BELOW NECESSARY ###
|
||||
@ -38,16 +38,19 @@ def get_last_filename_and_rename(new_filename):
|
||||
|
||||
mycursor = mydb.cursor()
|
||||
|
||||
print("APK Updater started.")
|
||||
print("Clearing APK Database from previous updates")
|
||||
print("APK Updater started on " + datetime.now().strftime("%d.%m.%Y %H:%M:%S") + ".")
|
||||
print("Clearing APK Database from previous updates...", end="", flush=True)
|
||||
sql = "TRUNCATE appstore"
|
||||
mycursor.execute(sql)
|
||||
mydb.commit()
|
||||
print(" DONE.")
|
||||
|
||||
#fetch updated apps from rss feed
|
||||
print("Fetching updated APKs from RSS...")
|
||||
print("Fetching updated APKs from RSS...", end="", flush=True)
|
||||
feed = feedparser.parse(url)
|
||||
print(" DONE")
|
||||
updates = 0
|
||||
print("Importing updated APK infos from RSS into Database...", end="", flush=True)
|
||||
for entry in feed.entries:
|
||||
updates += 1
|
||||
appname = str(entry.link).split("/")[-2]
|
||||
@ -56,14 +59,15 @@ for entry in feed.entries:
|
||||
val = (entry.link+"download/apk", appname, date_str)
|
||||
mycursor.execute(sql, val)
|
||||
mydb.commit()
|
||||
print("Imported " + str(updates) + " updated APK infos from RSS into Database.")
|
||||
print(" DONE (" + str(updates) + " APK infos).")
|
||||
|
||||
#find local available apps from metadata directory (filename without .yml)
|
||||
print("Searching for Apps in local Appstore...")
|
||||
print("Searching for Apps in local Appstore...", end="", flush=True)
|
||||
list_apps = ['.'.join(x.split('.')[:-1]) for x in os.listdir(metadata_path) if os.path.isfile(os.path.join(metadata_path, x))]
|
||||
print("Found " + str(len(list_apps)) + " Apps in local Appstore.")
|
||||
print(" Found " + str(len(list_apps)) + " Apps.")
|
||||
|
||||
#iterate throug local apps and query db to find matches. if match found, mark app for update
|
||||
print("Finding Apps to update...")
|
||||
real_updates = 0
|
||||
for app in list_apps:
|
||||
sql = "SELECT * FROM appstore WHERE app_name='" + app + "'"
|
||||
@ -75,9 +79,10 @@ for app in list_apps:
|
||||
mycursor.execute(sql2)
|
||||
real_updates +=1
|
||||
mydb.commit()
|
||||
print("Found " + str(real_updates) + " new updates for Apps in local Appstore")
|
||||
print("Found " + str(real_updates) + " new updates for Apps in local Appstore.")
|
||||
|
||||
if real_updates > 0:
|
||||
print("Downloading app updates...")
|
||||
#select all marked_for_update entries from db and download apk from apk_url into repo_path
|
||||
#with filename: app_name_version.apk/.xapk
|
||||
#make dir temp_path if it does not exist
|
||||
@ -107,19 +112,23 @@ if real_updates > 0:
|
||||
time.sleep(5)
|
||||
cookiebutton = driver.find_element(By.CSS_SELECTOR, 'svg.icon.ic-download-right')
|
||||
cookiebutton.click()
|
||||
print("APK " + row[2] + " downloaded.")
|
||||
print("APK " + row[2] + " downloaded...", end="", flush=True)
|
||||
time.sleep(30)
|
||||
#rename and move file to repo
|
||||
print("Moved APK to: " + get_last_filename_and_rename(row[2]))
|
||||
print(" moved to: " + get_last_filename_and_rename(row[2]) + ".")
|
||||
driver.close()
|
||||
driver.quit()
|
||||
|
||||
print("Cleanig up...", end="", flush=True)
|
||||
#delete temp_path directory and all files in it
|
||||
shutil.rmtree(temp_path)
|
||||
|
||||
#kill all running firefox processes to free RAM
|
||||
os.system("pkill -f firefox")
|
||||
print(" DONE.")
|
||||
|
||||
print("Updating local Appstore...", end="", flush=True)
|
||||
#todo run updating f-droid appstore command
|
||||
os.system("cd /mnt/data && fdroid update -c && cp /mnt/data/icons/icon.png /mnt/data/repo/icons/icon.png")
|
||||
print("Finished APK update.")
|
||||
print(" DONE.")
|
||||
print("Finished APK Updater on " + datetime.now().strftime("%d.%m.%Y %H:%M:%S") + ".")
|
Loading…
Reference in New Issue
Block a user