#!/usr/bin/env python3 import sys def main() -> None: priority_words = {w.lower() for w in sys.argv[1:]} lines = [] for line in sys.stdin.readlines(): words = line.split() if words[1].startswith('(') and words[1].endswith(')'): priority = words[1] else: priority = '(X)' for due in words: if due.startswith('due:'): break else: due = 'due:3000-01-01' has_priority_words = not any(w.lstrip('+#@').lower() in priority_words for w in words) lines.append((priority, has_priority_words, due, line)) print(''.join(l for *_, l in sorted(lines))) if __name__ == '__main__': main()