def cancel_removed_reminders_workaround(initial, final): """Zrusi vsechny pripominky z `initial` pokud nejsou ve `final`. Arguments: initial: Puvodni pripominky (pred zobrazenim / editaci). final: Pripominky, ktere maji zustat. """ if len(initial) == len(final): # Nic nechceme odstranit, koncime return # Musime zrusit vsechny notifikace notification.cancel_all() # Zjistime si aktualni cas now = time.time() def calculate_delay(note): # Funkce vypocita hodnotu delay a vlozi ji do notifikace. # fire_date je totiz cas kdy se ma notifikace zobrazit, ale my ji musime # znovu nastavit a tam se vyuziva delay, tj. za jak dlouho se ma zobrazit. note['delay'] = note.pop('fire_date') - now return note # Vypocitame delay pro vsechny notifikace notes = [calculate_delay(x['note']) for x in final] # Znovu je nastavime for note in notes: notification.schedule(**note) count = len(initial) - len(final) console.hud_alert(f'Odstraněno {count} připomínek')
def schedule_notfications(): nots = notification.get_scheduled() #print(nots) dayrange = list(range(7)) #print('dayrange before: {}'.format(dayrange)) today = datetime.datetime.now() ''' for n in nots: d1 = datetime.datetime.fromtimestamp( n['fire_date'] ) diff = d1 - today #print('diff: {}'.format(diff.days )) if diff.days in dayrange: dayrange.remove(diff.days) print('dayrange after: {}'.format(dayrange)) ''' notification.cancel_all() for i in dayrange: day = today + datetime.timedelta(days=i) h = 21 m = 30 desired_time = day.replace(hour=h, minute=m, second=0, microsecond=0) #print(desired_time) if desired_time > today: delta = desired_time - today delay_seconds = delta.total_seconds() notification.schedule( 'Complete Triggers', delay_seconds, 'default', 'pythonista3://triggers/enter-triggers.py?action=run&root=iCloud' )
def pause(): carbonized = [] for noti in PlannedNoti.get_scheduled(): delay_in_sec = round(noti.time_remaining.total_seconds()) if delay_in_sec < 1: delay_in_sec = 1 carbonized.append({'message':noti.message, 'delay':delay_in_sec, 'sound_name':noti.sound_name, 'action_url':noti.action_url}) with open(filename_pause_data, "w") as write_file: write_file.write(json.dumps(carbonized, indent=4)) notification.cancel_all()
def start(sender): '''UI: Start/Restart''' notification.cancel_all() # Erstmal aufräumen PlannedNoti.remove_pause_data() delay = 0.1 programm_id = dialogs.list_dialog(title='Programm?', items=list(programmes.keys())) print(programm_id) summe_der_einzelzeiten = round(sum(tupel[1] for tupel in programmes[programm_id]), 2) print('Dauer insg.: {} Minuten'.format(summe_der_einzelzeiten)) for (typ, dauer) in programmes[programm_id]: stell_benachrichtigung_ein(typ=task_types[typ], dauer=dauer, delay_in_minuten=delay) delay = dauer # Schlussbenachrichtigung einstellen: global letztes_delay letztes_delay = letztes_delay + delay * 60 PlannedNoti.init_and_schedule('Geschafft! 🥳', delay=letztes_delay, sound_name='arcade:Coin_3') print(PlannedNoti.get_benachrichtigungen_status()) sender.superview.close()
def test(): for i in range(1,3): PlannedNoti.init_and_schedule(message='Hello {}'.format(i), delay=i*60) noti = PlannedNoti.get_scheduled()[0] print(noti) notification.cancel_all()
def cancel(sender): '''UI: Benachrichtigungen entfernen''' notification.cancel_all() dialogs.alert(title='Benachrichtigungen entfernt', button1='Okay', hide_cancel_button=True) sender.superview.close()
#!/usr/bin/python # -*- coding: utf-8 -*- # CancelReminders Version 1.0 ## Cancels all currently scheduled notifications in Pythonista. import notification import console import webbrowser scheduled = notification.get_scheduled() url = 'launch://' if scheduled == []: console.hud_alert('None.', 'error') else: console.alert('Cancel all reminders?', 'Are you sure?', 'Yes') notification.cancel_all() console.hud_alert('Canceled.', 'success') webbrowser.open(url)
if touch.location.x > key.frame.center().x and len( key.names) > 1: webbrowser.open(key.names[1][1]) else: webbrowser.open(key.names[0][1]) return def touch_began(self, touch): self.any_touch(touch) return def touch_moved(self, touch): self.any_touch(touch) return def touch_ended(self, touch): self.any_touch(touch) return notification.cancel_all() notification.schedule('####### Call-Someone', 7, '', 'tel://12345678') notification.schedule('####### Whatsapp-Someone', 7, '', 'whatsapp://send?abid=123&text=hello') notification.schedule('####### Skype-Someone', 7, '', 'skype://12345678') notification.schedule('======= Whatsapp', 7, '', 'whatsapp:') notification.schedule('======= Reeder', 7, '', 'reeder:') notification.schedule('======= Map', 7, '', 'comgooglemaps:') notification.schedule('launch-todolist,calendar,rss', 7, '', 'pythonista://Launcher') run(Launcher(), PORTRAIT, 7)