def main( days=7, start=6, end=20, path=os.path.expanduser('~') + '/.appointlist' ): appoints = io.read_appoints(path=path, fail_if_locked=False, print_map={ special._number:lambda tokens: '' if special._count in tokens else '\x1b[2;2m('+tokens[special._number]\ +')\x1b[22;22m∥', special._count:lambda tokens: '' if not special._number in tokens else '\x1b[2;2m('+tokens[special._number]+'/'\ +tokens[special._count]+')\x1b[22;22m∥', special._location:lambda tokens: '\x1b[2;4m'+tokens[special._location]+'\x1b[22;24m∥' } ) clearTerminal() printGrid( days, start, end ) printCurrTime( days, start, end ) printDates( days, start, end ) for i in range( 0, days ): #print(getAppoints(i, appoints)) printAppoints( days, start, end, i, getAppoints(i, appoints) )
def appoint(pl, count=1, time_before={"0":0, "1":30}, file_path=os.path.expanduser('~') + '/.appointlist'): '''Return the next ``count`` appoints :param int count: Number of appoints that shall be shown :param time_before: Time in minutes before the appoint to start alerting Highlight groups used: ``appoint``, ``appoint_urgent``. ''' appoints = io.read_appoints(file_path) if appoints == None: return None appoints = {prio: [ap for ap in appoints if ap.prio == prio] for prio in range(0, max([0]+[b.prio for b in appoints])+1)} if appoints == None or len(appoints) == 0: return None now = datetime.now() #split into upcoming, current, past events, and events in the far future far_away = {prio:[] for prio in appoints.keys()} upcoming = {prio:[] for prio in appoints.keys()} current = {prio:[] for prio in appoints.keys()} time_before = {int(a):int(time_before[a]) for a in time_before} lst = 0 for i in range(0, 1+max(appoints.keys())): if i in time_before: lst = time_before[i] else: time_before[i] = lst keys = appoints.keys() while len(appoints) != 0: for i in keys: if not i in appoints: appoints[i] = [] far_away = {prio:far_away[prio]+[a for a in appoints[prio] if a.is_future(now) and not a.is_near(now,timedelta(0,time_before[prio]*60))] for prio in keys} upcoming = {prio:upcoming[prio]+[a for a in appoints[prio] if a.is_near(now,timedelta(0,time_before[prio]*60))] for prio in keys} current = {prio:current[prio]+[a for a in appoints[prio] if a.is_present(now)] for prio in keys} past = {prio:[a for a in appoints[prio] if a.is_past(now)] for prio in keys} appoints = {prio:[a.evolve() for a in past[prio] if a.evolve() != None] for prio in past.keys()} appoints = {prio:appoints[prio] for prio in appoints.keys() if appoints[prio] != []} keys = [k for k in keys] keys.sort() keys.reverse() result = [] def prepend_space(str): if str == '': return '' return ' ' + str for k in keys: result += [{ 'contents': a.text+prepend_space(a.spec.print()), 'highlight_groups': ['appoint_urgent'] } for a in upcoming[k]] for k in keys: result += [{ 'contents': a.text+prepend_space(a.spec.print()), 'highlight_groups': ['appoint'] } for a in current[k]] #Write the changed appoints tw = [] for k in keys: tw += current[k] tw += upcoming[k] tw += far_away[k] io.write_appoints(tw, file_path) if result != []: return [result[i] for i in range(0,min(len(result),count))] return None
def appoint(pl, count=1, time_before={ "0": 0, "1": 30 }, file_path=os.path.expanduser('~') + '/.appointlist'): '''Return the next ``count`` appoints :param int count: Number of appoints that shall be shown :param time_before: Time in minutes before the appoint to start alerting Highlight groups used: ``appoint``, ``appoint:urgent``. ''' from appoints import (appoint, special, io) appoints = io.read_appoints(file_path) if appoints == None: return None appoints = { prio: [ap for ap in appoints if ap.prio == prio] for prio in range(0, max([0] + [b.prio for b in appoints]) + 1) } if appoints == None or len(appoints) == 0: return None now = datetime.now() #split into upcoming, current, past events, and events in the far future far_away = {prio: [] for prio in appoints.keys()} upcoming = {prio: [] for prio in appoints.keys()} current = {prio: [] for prio in appoints.keys()} time_before = {int(a): int(time_before[a]) for a in time_before} lst = 0 for i in range(0, 1 + max(appoints.keys())): if i in time_before: lst = time_before[i] else: time_before[i] = lst keys = appoints.keys() while len(appoints) != 0: for i in keys: if not i in appoints: appoints[i] = [] far_away = { prio: far_away[prio] + [ a for a in appoints[prio] if a.is_future(now) and not a.is_near(now, timedelta(0, time_before[prio] * 60)) ] for prio in keys } upcoming = { prio: upcoming[prio] + [ a for a in appoints[prio] if a.is_near(now, timedelta(0, time_before[prio] * 60)) ] for prio in keys } current = { prio: current[prio] + [a for a in appoints[prio] if a.is_present(now)] for prio in keys } past = { prio: [a for a in appoints[prio] if a.is_past(now)] for prio in keys } appoints = { prio: [a.evolve() for a in past[prio] if a.evolve() != None] for prio in past.keys() } appoints = { prio: appoints[prio] for prio in appoints.keys() if appoints[prio] != [] } keys = [k for k in keys] keys.sort() keys.reverse() result = [] def prepend_space(str): if str == '': return '' return ' ' + str for k in keys: result += [{ 'contents': a.text + prepend_space(a.spec.print()), 'highlight_groups': ['appoint:urgent'] } for a in upcoming[k]] for k in keys: result += [{ 'contents': a.text + prepend_space(a.spec.print()), 'highlight_groups': ['appoint'] } for a in current[k]] #Write the changed appoints tw = [] for k in keys: tw += current[k] tw += upcoming[k] tw += far_away[k] io.write_appoints(tw, file_path) if result != []: return [result[i] for i in range(0, min(len(result), count))] return None