def write(self, values, context=None): if 'salesman' in values: # get the salesman to be notified for removal operation data = { 'type': 'sync', 'description': { 'master': 'activity.activity', 'operation': 'Delete', 'record_ids': json.load(StringIO([self.id])), } } if self.salesman.id: # notify about removal if self.salesman.device_identity: Notification.notify([self.salesman.device_identity], data) # check salesperson to be notified about add operation if values.get('salesman'): # notify about add data['description']['operation'] = 'Add' user = self.env['res.users'].browse([values.get('salesman')]) if user.device_identity: Notification.notify([user.device_identity], data) return super(Activity, self).write(values)
def create(self, values): activity = super(Activity, self).create(values) # if activity is created from web then notify the salesman for which activity is created if activity.salesman.id != activity.create_uid.id: if activity.salesman.device_identity: data = { 'type': 'sync', 'master': 'activity.activity', 'operation': 'Add', 'record_ids': json.load(StringIO([activity.id])), } Notification.notify([activity.salesman.device_identity], data) return activity
def check_sesssion(res): '''Method to check the presence of session and send notifications''' for center in res.get('centers'): for session in center.get('sessions'): if session.get('min_age_limit') >= int(os.getenv('MIN_AGE')) and \ session.get('min_age_limit') <= int(os.getenv('MAX_AGE')) and \ session.get('date') >= date and \ session.get('available_capacity') > int(os.getenv('MIN_REQUIRED')): message = f"Location - {center.get('district_name')} - {center.get('name')} {session.get('date')} - slots available {session.get('available_capacity')}" Notification().get_notification_channel_and_send(message)
def unlink(self): salesman_activities = {} for activity in self: if activity.salesman.device_identity: activities = salesman_activities.get(activity.salesman.device_identity, []) activities += [activity.id] salesman_activities[activity.salesman.device_identity] = activities is_deleted = super(Activity, self).unlink() if is_deleted: for registration_id, activities in salesman_activities.items(): data = { 'type': 'sync', 'master': 'activity.activity', 'operation': 'Delete', 'record_ids': json.load(StringIO(activities)), } Notification.notify([registration_id], data) return is_deleted
def main(): parser = argparse.ArgumentParser() parser.add_argument("--lang", nargs="?", default=to_lang, help="to lang") parser.add_argument("--notify", action="store_const", const=True, help=help_notify) parser.add_argument("--text", help="translates command line input text") args = parser.parse_args() text = args.text if args.text else clip.get() translator = Translator(to_lang=args.lang) translated = translator.translate(text) if args.notify: Notification("", translated) else: print(translated) clip.set(translated)
def clockwatcher_main(): syslog.syslog("clockwatcherd: starting clockwatcher_main") lifetime = timedelta(days=1) #Notif expiration delta s = Signer("/etc/clockwatcher/shiny.private", "shiny") addrlist=[] updates={} with open("/etc/clockwatcher/clockwatcherd.cfg","r") as cfg: for line in cfg: addrlist.append(line[:-1]) #remembering to remove trailing \n while 1: # Synchronize to next whole minute starttime = time.localtime() time.sleep(60-starttime.tm_sec) currtime = datetime.now()+ timedelta(seconds=30) # Force rounding in case we're early timemsg = currtime.strftime("It is now %H:%M") notif = Notification(4, lifetime, timemsg, timemsg + " and all is well") # Need to add expiration here notif.prepare(s) # For now, minimizing the possibility of a collision between this daemon and new authorizations coming in # by reading the additional authorizations from a separate file and adding them on here. Only the daemon # touches the main clockwatcherd.cfg file. rewrite = False try: with open("/etc/clockwatcher/newwatchers.cfg","r") as cfg: for line in cfg: newaddr = line if newaddr not in addrlist: #Handle unlikely duplicates addrlist.append(newaddr) rewrite = True except IOError: pass except: syslog.syslog("clockwatcherd: Unknown error opening newwatchers file") quit() if rewrite: cfg=open("/etc/clockwatcher/newwatchers.cfg","w") #Clobber newwatchers file cfg.close() with open("/etc/clockwatcher/clockwatcherd.cfg","w") as cfg: #Update config with new watchers for idx in range(len(addrlist)): if addrlist[idx] != "": cfg.write(addrlist[idx]) cfg.write("\n") rewrite = False for idx in range(len(addrlist)): notaddr = addrlist[idx] if notaddr == "": continue if notaddr in updates: #update an existing notif if possible notid = updates[notaddr] status = notif.update(notid) if status == 404: #if 404 delete notid from updates del updates[notaddr] if notaddr not in updates: #not an else because it could have just been removed # TODO: Handle exceptions (can't connect, etc.) here (notid, status) = notif.send(notaddr) #Need to get feedback on send failures, delete notaddr if status == 404: addrlist[idx]="" #Don't delete entry from addrlist inside loop, just blank it rewrite = True #Disk copy of list needs updating elif status == 200: updates[notaddr] = notid if rewrite: #Update disk copy of list, removing any blank addresses with open("/etc/clockwatcher/clockwatcherd.cfg","w") as cfg: for idx in range(len(addrlist)): if addrlist[idx] != "": cfg.write(addrlist[idx]) cfg.write("\n")
def test_notification_class(): status = Notification("Hello World", message="optional")() assert status is True
# load database kp = PyKeePass(args.database, password=password) except CredentialsIntegrityError as e: r.exit_with_error('Could not open database') options = [] for entry in kp.entries: options.append(entry.title) index, key = r.select('Name', options, key1=('Alt+1', "Type all"), key2=('Alt+2', "Type user"), key3=('Alt+3', "Type pass"), rofi_args=['-i', '-no-custom']) if(key == 0): # copy password cmd = "echo -n " + shlex.quote(kp.entries[index].password) + " | xclip -selection clipboard" subprocess.Popen(cmd,shell=True).communicate() Notification("Will be cleared in 15 seconds", kp.entries[index].title + " copied") subprocess.Popen("sleep 15 && echo -n "" | xclip -selection clipboard", shell=True).communicate() elif(key == 1): # type all subprocess.call(["sleep", "0.5"]) subprocess.call(["xdotool", "type", kp.entries[index].username]) subprocess.call(["xdotool", "key", "Tab"]) subprocess.call(["xdotool", "type", kp.entries[index].password]) elif(key == 2): # type user subprocess.call(["sleep", "0.5"]) subprocess.call(["xdotool", "type", kp.entries[index].username]) elif(key == 3): # type password subprocess.call(["sleep", "0.5"]) subprocess.call(["xdotool", "type", kp.entries[index].password])
def test_notification_class(): n = Notification("Hello World", title="optional") n()
def action(str): try: Notification("LinuxSpeachAPI", str) words = str.split() active_window = get_active_window.get_active_window_title().decode( 'utf-8') print(active_window) if "audio_play" in words[0]: os.popen("xdotool key XF86AudioPlay") elif "audio_next" in words[0]: os.popen("xdotool key XF86AudioNext") elif "audio_prev" in words[0]: os.popen("xdotool key XF86AudioPrev") elif "start_app" in words[0]: if len(words) > 1: if "web" in words[1]: os.popen("chromium") elif "text" in words[1]: os.popen("/opt/visual-studio-code/code") elif "music" in words[1]: os.popen("amarok") elif "files" in words[1]: if len(words) > 2: if "docs" in words[2]: os.popen("dolphin ~/OneDrive") elif "music" in words[2]: os.popen("dolphin ~/Music") elif "music" in words[2]: os.popen("dolphin ~/Desktop") else: os.popen("dolphin") elif "close_app" in words[0]: if len(words) == 1: if not ("Konsole" in active_window or "LinuxSpeachAPI" in active_window): os.popen("xdotool getactivewindow windowclose") else: if "web" in words[1]: os.popen("killall chromium") os.popen("killall chromium") os.popen("killall chromium") elif "text" in words[1]: os.popen("killall /opt/visual-studio-code/code") os.popen("killall /opt/visual-studio-code/code") os.popen("killall /opt/visual-studio-code/code") elif "music" in words[1]: os.popen("killall amarok") elif "files" in words[1]: os.popen("killall dolphin") elif "back" in words[0]: pyautogui.hotkey('ctrl', 'z') elif "nextt" in words[0]: pyautogui.hotkey('ctrl', 'shift', 'z') elif "mark_all" in words[0]: pyautogui.hotkey('ctrl', 'a') elif "cut" in words[0]: pyautogui.hotkey('ctrl', 'x') elif "copy" in words[0]: pyautogui.hotkey('ctrl', 'c') elif "paste" in words[0]: pyautogui.hotkey('ctrl', 'v') elif "enter" in words[0]: pyautogui.press('enter') elif "cancel" in words[0]: pyautogui.press('escape') elif "delete" in words[0]: pyautogui.press('del') elif "page_down" in words[0]: pyautogui.hotkey('pagedown') elif "page_up" in words[0]: pyautogui.hotkey('pageup') elif "end" in words[0]: pyautogui.hotkey('end') elif "home" in words[0]: pyautogui.hotkey('home') elif "volume_up" in words[0]: if len(words) > 1: os.popen("pactl set-sink-volume 0 +{}dB".format(words[1])) elif "volume_down" in words[0]: if len(words) > 1: os.popen("pactl set-sink-volume 0 -{}dB".format(words[1])) elif "mute" in words[0]: os.popen("pactl set-sink-mute 0 toggle") elif "audio_reset" in words[0]: os.popen("pactl set-sink-volume 0 0dB") elif "left" in words[0]: pyautogui.hotkey('left') elif "right" in words[0]: pyautogui.hotkey('right') elif "up" in words[0]: pyautogui.hotkey('up') elif "down" in words[0]: pyautogui.hotkey('down') elif "print_screen" in words[0]: os.popen('spectacle') elif "print" in words[0]: pyautogui.hotkey('ctrl', 'p') elif "change_desktop" in words[0]: pyautogui.hotkey('ctrl', 'alt', 'pageup') elif "Niezapisane*" in active_window: if "save_file" in words[0]: pyautogui.hotkey('ctrl', 's') elif "Visual Studio Code" in active_window: if "new_file" in words[0]: pyautogui.hotkey('ctrl', 'n') elif "save_file" in words[0]: pyautogui.hotkey('ctrl', 's') elif "save_as_new_file" in words[0]: pyautogui.hotkey('ctrl', 'shift', 's') elif "close_file" in words[0]: pyautogui.hotkey('ctrl', 'w') elif "search" in words[0]: pyautogui.hotkey('ctrl', 'f') elif "cart_close" in words[0]: pyautogui.hotkey('ctrl', 'w') elif "Chromium" in active_window: if "cart_new" in words[0]: pyautogui.hotkey('ctrl', 't') elif "cart_close" in words[0]: pyautogui.hotkey('ctrl', 'w') elif "site_prev" in words[0]: pyautogui.hotkey('alt', 'left') elif "site_next" in words[0]: print("action") pyautogui.hotkey('alt', 'right') elif "web_search" in words[0]: pyautogui.hotkey('ctrl', 'k') elif "cart_restore" in words[0]: pyautogui.hotkey('ctrl', 'shift', 't') elif "refresh" in words[0]: pyautogui.hotkey('ctrl', "f5") elif "home_website" in words[0]: pyautogui.hotkey('alt', "home") elif "cart_go" in words[0]: if len(words) > 1: if 'last_one' in words[1]: pyautogui.hotkey('ctrl', '9') else: pyautogui.hotkey('ctrl', '{}'.format(words[1])) except: print("repeat")
returnText = json.loads(responseObj.text) if returnText != 0: try: if isinstance(returnText, list): if get_data_file(key) == responseObj.text: continue set_data_file(key, responseObj.text) place = returnText[0]['Place'] timeFrom = datetime.strptime( returnText[0]['DisconnectionDateTime'], '%Y-%m-%dT%H:%M:%S').strftime('%d.%m.%Y %H:%M') timeTo = datetime.strptime( returnText[0]['EnergyOnPlanningDateTime'], '%Y-%m-%dT%H:%M:%S').strftime('%d.%m.%Y %H:%M') placeEquipment = returnText[0]['EquipmentName'] workDesc = returnText[0]['DisconnectionCause'] noty = Notification('{}({}): {}-{} | {}'.format( value, workDesc, timeFrom, timeTo, place)) else: noty = Notification(value) except: noty = Notification(sys.exc_info()[0]) raise noty.show_notification() noty.telegram_bot()
def notify_song(user): time.sleep(.300) curr = user.currently_playing()['item'] Notification(curr.artist.name, title=curr.name)
def clockwatcher_main(): syslog.syslog("clockwatcherd: starting clockwatcher_main") lifetime = timedelta(days=1) #Notif expiration delta s = Signer("/etc/clockwatcher/shiny.private", "shiny") addrlist = [] updates = {} with open("/etc/clockwatcher/clockwatcherd.cfg", "r") as cfg: for line in cfg: addrlist.append(line[:-1]) #remembering to remove trailing \n while 1: # Synchronize to next whole minute starttime = time.localtime() time.sleep(60 - starttime.tm_sec) currtime = datetime.now() + timedelta( seconds=30) # Force rounding in case we're early timemsg = currtime.strftime("It is now %H:%M") notif = Notification(4, lifetime, timemsg, timemsg + " and all is well") # Need to add expiration here notif.prepare(s) # For now, minimizing the possibility of a collision between this daemon and new authorizations coming in # by reading the additional authorizations from a separate file and adding them on here. Only the daemon # touches the main clockwatcherd.cfg file. rewrite = False try: with open("/etc/clockwatcher/newwatchers.cfg", "r") as cfg: for line in cfg: newaddr = line if newaddr not in addrlist: #Handle unlikely duplicates addrlist.append(newaddr) rewrite = True except IOError: pass except: syslog.syslog( "clockwatcherd: Unknown error opening newwatchers file") quit() if rewrite: cfg = open("/etc/clockwatcher/newwatchers.cfg", "w") #Clobber newwatchers file cfg.close() with open("/etc/clockwatcher/clockwatcherd.cfg", "w") as cfg: #Update config with new watchers for idx in range(len(addrlist)): if addrlist[idx] != "": cfg.write(addrlist[idx]) cfg.write("\n") rewrite = False for idx in range(len(addrlist)): notaddr = addrlist[idx] if notaddr == "": continue if notaddr in updates: #update an existing notif if possible notid = updates[notaddr] status = notif.update(notid) if status == 404: #if 404 delete notid from updates del updates[notaddr] if notaddr not in updates: #not an else because it could have just been removed # TODO: Handle exceptions (can't connect, etc.) here (notid, status) = notif.send( notaddr ) #Need to get feedback on send failures, delete notaddr if status == 404: addrlist[ idx] = "" #Don't delete entry from addrlist inside loop, just blank it rewrite = True #Disk copy of list needs updating elif status == 200: updates[notaddr] = notid if rewrite: #Update disk copy of list, removing any blank addresses with open("/etc/clockwatcher/clockwatcherd.cfg", "w") as cfg: for idx in range(len(addrlist)): if addrlist[idx] != "": cfg.write(addrlist[idx]) cfg.write("\n")
def uspeak(lang, use_sounds): notify = Notification('USpeak') r = sr.Recognizer(language=lang) with sr.Microphone() as source: with reduced_volume(): if use_sounds: say.run('go') notify.show('Waiting for voice command...', NOTIFY_TYPE.OK, NOTIFY_LEVEL.CRITICAL) try: audio = r.listen(source, timeout=3) except TimeoutError: notify.show('Sorry, could not hear your voice', notify_type=NOTIFY_TYPE.ERROR) return notify.show('Working on it...', NOTIFY_TYPE.MIC, NOTIFY_LEVEL.CRITICAL) try: recognized_text = r.recognize(audio) except LookupError: notify.show('Could not understand your phrase, try again please', notify_type=NOTIFY_TYPE.ERROR) return command = translate(recognized_text, dictionary=read_dictionary(language=lang)) if command: notify.show('Executing: {}.\nReady for another command.'.format(command), notify_type=NOTIFY_TYPE.OK) if run_command(command, lang): notify.show('Sorry, there were some problems running your command.', notify_type=NOTIFY_TYPE.ERROR) else: notify.show('Unknown command: {}'.format(recognized_text), notify_type=NOTIFY_TYPE.ERROR)
def uspeak(lang, use_sounds): notify = Notification('USpeak') r = sr.Recognizer(language=lang) with sr.Microphone() as source: with reduced_volume(): if use_sounds: say.run('go') notify.show('Waiting for voice command...', NOTIFY_TYPE.OK, NOTIFY_LEVEL.CRITICAL) try: audio = r.listen(source, timeout=3) except TimeoutError: notify.show('Sorry, could not hear your voice', notify_type=NOTIFY_TYPE.ERROR) return notify.show('Working on it...', NOTIFY_TYPE.MIC, NOTIFY_LEVEL.CRITICAL) try: recognized_text = r.recognize(audio) except LookupError: notify.show('Could not understand your phrase, try again please', notify_type=NOTIFY_TYPE.ERROR) return command = translate(recognized_text, dictionary=read_dictionary(language=lang)) if command: notify.show( 'Executing: {}.\nReady for another command.'.format(command), notify_type=NOTIFY_TYPE.OK) if run_command(command, lang): notify.show( 'Sorry, there were some problems running your command.', notify_type=NOTIFY_TYPE.ERROR) else: notify.show('Unknown command: {}'.format(recognized_text), notify_type=NOTIFY_TYPE.ERROR)