MCPcopy
hub / github.com/InstaPy/InstaPy / toast_notification

Function toast_notification

instapy/quota_supervisor.py:274–309  ·  view source on GitHub ↗

Send toast notifications about supervising states directly to OS using 'plyer' module

(notify, alert, job, interval)

Source from the content-addressed store, hash-verified

272
273
274def toast_notification(notify, alert, job, interval):
275 """Send toast notifications about supervising states directly to OS
276 using 'plyer' module"""
277 platform_matches = platform.startswith(("win32", "linux", "darwin"))
278 if notify is True and platform_matches:
279 icons = get_icons()
280 delay = 9 if alert == "exit" else 7
281 label = job.replace("_", " ").capitalize()
282
283 expr = (
284 "Yawn! {} filled {} quotient!\t~falling asleep a little bit :>"
285 if alert == "sleep"
286 else "Yikes! {} just woke up from {} quotient bandage!\t~let's "
287 "chill again wakey ;)"
288 if alert == "wakeup"
289 else "D'oh! {} finished {} quotient!\t~exiting ~,~"
290 )
291
292 try:
293 notification.notify(
294 title="Quota Supervisor",
295 message=expr.format(label, interval),
296 app_name="InstaPy",
297 app_icon=icons[alert],
298 timeout=delay,
299 ticker="To switch supervising methods, please review "
300 "quickstart script",
301 )
302
303 except Exception:
304 # TypeError: out of 'plyer' bug in python 2 - INNER EXCEPTION
305 # NotImplementedError: when 'plyer' is not supported
306 # DBusException: dbus-display issue on linux boxes
307
308 # turn off toast notification for the rest of the session
309 configuration.update(notify=False)
310
311
312def get_icons():

Callers 1

controllerFunction · 0.85

Calls 1

get_iconsFunction · 0.85

Tested by

no test coverage detected