def lire(args): key = ' '.join(args).strip() if len(key) == 0: print('Choisissez un document ou un message à lire.') print('Examples: "lire 1037" ou "lire le livre rouge"') print( 'Tapez "messages" ou "documents" pour voir les fichiers disponibles.' ) return if all([d.isdigit() for d in key]): # email key = int(key) email = get_emails().get(key, None) if email is not None: read_email(email) else: print('Pas de message {}.'.format(key)) else: # document doc = all_documents().get(key.lower(), None) if doc is not None: read_doc(doc) else: print('Le document {} n’existe pas.'.format(key))
def list_email(): return jsonify({ e.id_: { 'auteur': e.source, 'sujet': e.subject, 'text': f'{e.text[:40]}...', } for e in get_emails().values() })
def message(): emails = [e for e in get_emails().values() if not e.is_read] ret = [] if len(emails) > 0: ret.extend([ ("class:emails", f"{len(emails)} messages non lus "), ("class:colon", "| "), ]) ret.extend([ ("class:project", "idunn"), ("class:pound", "# "), ]) return ret
def delete(): to_del = request.json['title'].lower() if all([d.isdigit() for d in to_del]): # email key = int(to_del) email = get_emails().get(key, None) if email is not None: with open(email.file, 'w', encoding='latin-1') as f: f.write('') return 'ok', 200 else: return 'unkown mail', 500 else: # document doc = all_documents().get(to_del, None) if doc is not None: with open(doc.file, 'w', encoding='latin-1') as f: f.write('') return 'ok', 200 else: return 'unkown doc', 500
def messages(args): emails = get_emails() read = {k: v for k, v in emails.items() if v.is_read} unread = {k: v for k, v in emails.items() if not v.is_read} id_s = 'ID' so_s = 'Envoyeur' su_s = 'Sujet' da_s = 'Date' so_l = max([len(e.source) for e in emails.values()] + [len(so_s)]) + 2 su_l = max([len(e.subject) for e in emails.values()] + [len(su_s)]) + 2 da_l = 16 + 2 # len of date num_pad = 6 header = f'{id_s:<{num_pad}} {da_s:<{da_l}} {so_s:<{so_l}} {su_s:<{su_l}}' print_m = lambda m: f'{m.id_:<{num_pad}} {print_t(m.date):<{da_l}} {m.source:<{so_l}} {m.subject:<{su_l}}' if len(unread) > 0: cprint(f'\n{len(unread)} messages non lus :', on_color='on_green', color='blue') cprint(header, color='blue', on_color='on_yellow') for m in sorted(unread.values(), key=lambda e: e.date, reverse=True): print(print_m(m)) else: cprint('\nPas de messages non lus.', color='blue') if len(read) > 0: cprint(f'\n{len(read)} messages déjà ouverts :', on_color='on_green', color='blue') cprint(header, color='blue', on_color='on_yellow') for m in sorted(read.values(), key=lambda e: e.date, reverse=True): print(print_m(m)) else: cprint('\nPas de messages déjà ouverts.', color='blue') print('\nTapez "lire [ID du message]" pour lire un message.')