From 871a3ddf64993123aa6c722603d3f94e73a00156 Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 18 Dec 2024 11:54:05 +0300 Subject: [PATCH] fix updater --- src/updatenotif.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/updatenotif.py b/src/updatenotif.py index be0c797..8fdf467 100644 --- a/src/updatenotif.py +++ b/src/updatenotif.py @@ -5,6 +5,8 @@ import asyncio async def git_notifications_update(): logger.info('module for checking updates started') + cwd = os.getcwd() + os.chdir(cwd) while True: termux_api = os.system('termux-api-start') if termux_api == 0: @@ -12,12 +14,15 @@ async def git_notifications_update(): fetching_git = os.system('git fetch') if fetching_git == 0: commits = os.popen('git log --oneline HEAD..origin/$(git rev-parse --abbrev-ref HEAD)').read() - cwd = os.getcwd() - os.system(f"termux-notification --title 'ub4tg: update avalaible!' --content 'For apply tap button Get update and restart bot\nChanges:\n{commits}' --button1 'Get update' --button1-action 'cd {cwd}; git pull'") + if len(commits) <= 5: + logger.info('updates not found, nothing to do') + else: + os.system(f"termux-notification --title 'ub4tg: update avalaible!' --content 'For apply tap button Get update and restart bot\nChanges:\n{commits}' --button1 'Get update' --button1-action 'cd {cwd}; git pull'") else: os.system("termux-toast '[ub4tg]: failed fetching update, maybe connection error'") else: logger.warning('For getting updates via notifications, you should:') logger.warning('pkg install termux-api') logger.warning('download the apk: https://f-droid.org/repo/com.termux.api_51.apk') + logger.debug('next update will be check after 6 hours') await asyncio.sleep(6 * 60 * 60)