2024-12-18 10:25:47 +02:00
|
|
|
from loguru import logger
|
|
|
|
import os
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
|
|
async def git_notifications_update():
|
|
|
|
logger.info('module for checking updates started')
|
2024-12-18 10:54:05 +02:00
|
|
|
cwd = os.getcwd()
|
|
|
|
os.chdir(cwd)
|
2024-12-18 10:25:47 +02:00
|
|
|
while True:
|
|
|
|
termux_api = os.system('termux-api-start')
|
|
|
|
if termux_api == 0:
|
|
|
|
logger.info('Checking for updates...')
|
|
|
|
fetching_git = os.system('git fetch')
|
|
|
|
if fetching_git == 0:
|
2024-12-19 00:55:50 +02:00
|
|
|
os.system("printf 'For apply tap button Get update and restart bot\nChanges:\n' > upd_info")
|
2024-12-18 20:45:33 +02:00
|
|
|
commits = os.popen(
|
2024-12-19 10:31:12 +02:00
|
|
|
"git log --pretty=format:'%h %s%n%b' HEAD..origin/$(git rev-parse --abbrev-ref HEAD) | tee upd_info").read()
|
2024-12-18 10:54:05 +02:00
|
|
|
if len(commits) <= 5:
|
|
|
|
logger.info('updates not found, nothing to do')
|
|
|
|
else:
|
2024-12-18 20:45:33 +02:00
|
|
|
os.system(
|
2024-12-19 10:33:48 +02:00
|
|
|
f"cat upd_info | termux-notification -i ub4tgupd --title 'ub4tg: update avalaible!' --button1 'Get update' --button1-action 'termux-notification-remove ub4tgupd'; cd {cwd}; git pull; termux-toast 'ub4tg updated, now restart it for apply update'")
|
2024-12-18 10:25:47 +02:00
|
|
|
else:
|
2024-12-18 20:45:33 +02:00
|
|
|
os.system(
|
|
|
|
"termux-toast '[ub4tg]: failed fetching update, maybe connection error, check console log for more info'")
|
2024-12-18 10:25:47 +02:00
|
|
|
else:
|
2024-12-18 20:45:33 +02:00
|
|
|
logger.warning(
|
|
|
|
'For getting updates via notifications, you should:')
|
2024-12-18 10:25:47 +02:00
|
|
|
logger.warning('pkg install termux-api')
|
2024-12-18 20:45:33 +02:00
|
|
|
logger.warning(
|
|
|
|
'download the apk: https://f-droid.org/repo/com.termux.api_51.apk')
|
2024-12-18 10:54:05 +02:00
|
|
|
logger.debug('next update will be check after 6 hours')
|
2024-12-18 10:25:47 +02:00
|
|
|
await asyncio.sleep(6 * 60 * 60)
|