def main(): c = Controller() if len(sys.argv) != 2: Output.error("usage: dlimport [filename]") c.exit() return 0 try: csvfile = open(sys.argv[1], newline='', encoding='utf-8-sig') reader = csv.reader(csvfile, delimiter=';') category = '' for row in reader: if row[0] == 'events': category = 'e' continue elif row[0] == 'tasks': category = 't' continue elif row[0] == '': continue if category == 'e': pass print(row[0], row[2], f'{row[3]}-{row[4]}', row[1]) c.add_event(row[0], row[2], f'{row[3]}-{row[4]}', row[1]) elif category == 't': print(row[0], row[2], row[3], row[1]) c.add_task(row[0], row[2], row[3], row[1]) csvfile.close() except FileNotFoundError: Output.error("file not found") finally: c.exit()
def done(self, id): t = self.db.get_task_by(id) if not t: Out.error(f'no task with id {id} found') return 0 done_time = Dataparser.nearest_deadline(t).strftime('%Y-%m-%d %H:%M') Out.info(f'task {id} done until {done_time}') self.db.set_done(id, done_time)
def validate(args): ''' validates input values of the user ''' # only need to validate if cmd is event or task if args.cmd == 'event' or args.cmd == 'task': # -t -d -f are available but -d is optional # try to match -f w/o/d if not re.match('^(w|weekly|d|daily|o|once)$', args.f): O.error(f'wrong frequency format: {args.f}') return False # if daily: no date/day set if args.f[0] == 'd': if args.d != None: O.error( f'you cannot use -d here because the {args.cmd} is daily.' ) return False # if once: date YYYY-MM-DD needs to be set elif args.f[0] == 'o': if not args.d or not re.match( '^((\d\d\d\d)-(0[1-9]|1[0-2])-(0[1-9]|(1|2)[0-9]|3[0-1]))$', args.d): O.error(f'wrong date format: {args.d}') return False # if weekly: day needs to be set else: if not args.d or not re.match( '^(mon|tue|wed|thu|fri|sat|sun)$', args.d): O.error(f'wrong day format: {args.d}') return False # if event try to match HH:MM-HH:MM if args.cmd == 'event': if not re.match( '^([0-1][0-9]|2[0-3]):[0-5][0-9]-([0-1][0-9]|2[0-3]):[0-5][0-9]$', args.t): O.error(f'wrong time format: {args.t}') return False # if event try to match HH:MM else: if not re.match('^([0-1][0-9]|2[0-3]):[0-5][0-9]$', args.t): O.error(f'wrong time format: {args.t}') return False return True