Conditions | 4 |
Total Lines | 21 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | #!/usr/bin/env python |
||
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 |