def notify( title="Python notification", message: str = "Your program has completed", duration: float = 10., sound: str = None ): if sys.platform != "darwin": # pynotifier is windows+linux from pynotifier import Notification Notification( title=title, description=message, icon_path=python_icon, duration=duration, urgency=Notification.URGENCY_CRITICAL ).send() else: from pync import Notifier Notifier.notify(message, title=title) Notifier.remove(os.getpid()) Notifier.list(os.getpid()) if sound is not None: if sound == "random": soundfile = get_random_soundfile() else: soundfile = get_soundfile(sound) playsound(soundfile)
def job(): config = None with open ("config.json") as file: config = json.load(file) for market in config.get("markets"): if market["active"] is False: continue symbol = market["name"] max_price = market["max"] min_price = market["min"] ticker = binance_client.get_symbol_ticker(symbol=symbol) price = float(ticker.get("price")) if price > max_price or price < min_price: Notifier.notify(message="{} is currently ${}".format(symbol, price), title='Crypto Alert!', appIcon='https://i.imgur.com/yqsHQIL.png', open='https://www.binance.com/en/trade/BTC_USDT') Notifier.remove(os.getpid()) Notifier.list(os.getpid())
def updateChecker(oldfile, newfile): for i in repoNames: if oldfile[i] == newfile[i]: Notifier.notify("Repository Updated", title=i) Notifier.remove(os.getpid()) Notifier.list(os.getpid()) with open("repos.json", "w") as r: #Erases content in file r.close() with open("repos.json", "w") as n: n.write("{\n") for i in newfile: n.write("\"" + i + "\": ") # Re writes file with updated repos n.write("\"" + newfile[i] + "\" ") n.write("\n}") n.close() exit() break else: print("No updates have occurred")
def yes_notify(message_time, now_time, interval): try: # Find when we last had a notification # last_in_queue['delivered_at'] is a datetime object last_in_queue = Notifier.list(group='weechat')[-1] epoch = datetime.datetime(1970, 1, 1, 0, 0, 0, tzinfo=tzutc()) last_message_time = int( (last_in_queue['delivered_at'] - epoch).total_seconds()) if (now_time - last_message_time) > int(interval): return True else: return False except IndexError: return True
from datetime import datetime import googlemaps import json gmaps = googlemaps.Client(key=GOOGLEMAPS_API_KEY) # Request directions via public transit now = datetime.now() directions_result = gmaps.directions(FROM_ADDRESS, TO_ADDRESS, mode="driving", departure_time=now) time_to_home = directions_result[0]['legs'][0]['duration_in_traffic']['text'] # Display notification on your mac with a link to google maps with prepopulated TO and FROM fields. from pync import Notifier import os Notifier.notify(time_to_home, title='Traffic Update', open=GOOGLE_MAPS_LINK) Notifier.remove(os.getpid()) Notifier.list(os.getpid()) # Send a text message from subprocess import call call([ "osascript", "sendMessage.applescript", TARGET_PHONE_NUMBER, "Hello, current time from Millennium park to Skydeck is: " + time_to_home ])
''' Going to use pync to make notifications on Mac OS X , before that you need to do this: brew install terminal-notifier and then: pip install pync ''' from pync import Notifier import os Notifier.notify('This is how it looks') Notifier.notify('Hello World', title='Python') Notifier.notify('Hello World', group=os.getpid()) Notifier.notify('Browser', activate='com.apple.Safari') Notifier.notify('Website', open='http://github.com/') Notifier.notify('Some execution', execute='say "I am hungry!"') Notifier.remove(os.getpid()) Notifier.list(os.getpid())