Total Complexity | 4 |
Total Lines | 33 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | #!/usr/bin/env python |
||
2 | # encoding: utf-8 |
||
3 | |||
4 | import sys |
||
5 | |||
6 | |||
7 | class JRNLImporter: |
||
8 | """This plugin imports entries from other jrnl files.""" |
||
9 | |||
10 | names = ["jrnl"] |
||
11 | |||
12 | @staticmethod |
||
13 | def import_(journal, input=None): |
||
14 | """Imports from an existing file if input is specified, and |
||
15 | standard input otherwise.""" |
||
16 | old_cnt = len(journal.entries) |
||
17 | if input: |
||
18 | with open(input, "r", encoding="utf-8") as f: |
||
19 | other_journal_txt = f.read() |
||
20 | else: |
||
21 | try: |
||
22 | other_journal_txt = sys.stdin.read() |
||
23 | except KeyboardInterrupt: |
||
24 | print("[Entries NOT imported into journal.]", file=sys.stderr) |
||
25 | sys.exit(0) |
||
26 | journal.import_(other_journal_txt) |
||
27 | new_cnt = len(journal.entries) |
||
28 | print( |
||
29 | "[{} imported to {} journal]".format(new_cnt - old_cnt, journal.name), |
||
30 | file=sys.stderr, |
||
31 | ) |
||
32 | journal.write() |
||
33 |