add desktop notifs

This commit is contained in:
Izalia Mae 2019-12-07 02:36:17 -05:00
parent 84a24194a1
commit 3715606a9e
2 changed files with 14 additions and 6 deletions

1
.python-version Normal file
View file

@ -0,0 +1 @@
3.8.0

View file

@ -4,7 +4,8 @@
# by Zoey Mae @izalia@barkshark.xyz
#
# Installation:
# $ pip install aiohttp --user
# # apt install libnotify-bin
# $ pip install aiohttp plyer dbus-python --user
###
import asyncio
import aiohttp
@ -38,7 +39,7 @@ logging.basicConfig(
)
NAME = f'Multi-Notifs'
NAME = 'Multi-Notifs'
NOTIF = '/data/data/com.termux/files/usr/bin/termux-notification'
CONF = f'{dirname(abspath(__file__))}/config.json'
@ -51,6 +52,10 @@ HEADERS = {
}
if not droid:
from plyer import notification
def setup_config(config):
if isfile(config):
confjson = json.load(open(CONF))
@ -180,10 +185,9 @@ def display_notif(username, action, msg):
return msg
account = msg['account']
message = f"{account['display_name']} ({account['acct']}) {notmsg[action]}\n"
summary = f"{account['display_name']} ({account['acct']}) {notmsg[action]}\n"
if action != 'follow':
message += strip(msg['status'].get('content'))
message = strip(msg['status'].get('content')) if action != 'follow' else ''
#message = message.replace('"', '\"')
message = message.replace("'", "")
@ -191,10 +195,13 @@ def display_notif(username, action, msg):
logging.info(f'{action} from {account["display_name"]}')
if droid:
CMDOPTS = f'--title="{NAME} - {username}" --content=\'{message}\''
CMDOPTS = f'--title="{NAME} - {username}" --content=\'{summary}\n{message}\''
URL = f'termux-open {HOSTURL}/web/notifications'
os.system(f'{NOTIF} --action "{URL}" {CMDOPTS}')
return
else:
notification.notify(title=f'{NAME}: {username}', message=f'{summary}\n{message}')
return
logging.info(message)