jrnl.plugins.jrnl_importer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A JRNLImporter.import_() 0 21 4
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