diff --git a/features/dayone2.feature b/features/dayone2.feature index 30b9024d..d245e017 100644 --- a/features/dayone2.feature +++ b/features/dayone2.feature @@ -23,10 +23,9 @@ Feature: Day One 2.0 implementation details. Scenario: Converted journal is validated Given we use the config "basic.yaml" When we run "jrnl --import dayone2 features/data/journals/dayone2.json" - Then we should get no error When we run "jrnl dayone2 -n 2" Then we should get no error - and the output should contain "10-01-2020 12:21 Entry Number Two." + and the output should contain "2020-01-10 12:21 Entry Number Two." Scenario: Check tags are handled correctly Given we use the config "basic.yaml" diff --git a/jrnl/cli.py b/jrnl/cli.py index 2ba696a4..ee1d6ecc 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -348,7 +348,8 @@ def run(manual_args=None): # Import mode if args.import_: - return plugins.get_importer(args.import_, args.text) + root_config = install.load_or_install_jrnl() + return plugins.get_importer(args.import_, args.text, root_config) # This is where we finally open the journal! try: diff --git a/jrnl/plugins/__init__.py b/jrnl/plugins/__init__.py index aa53d248..7ce3185e 100644 --- a/jrnl/plugins/__init__.py +++ b/jrnl/plugins/__init__.py @@ -38,8 +38,8 @@ def get_exporter(format): return None -def get_importer(file_format, path): +def get_importer(file_format, path, root_config): for importer in __importers: if hasattr(importer, "names") and file_format in importer.names: - return importer(path) + return importer(path, root_config) return None diff --git a/jrnl/plugins/dayone2_importer.py b/jrnl/plugins/dayone2_importer.py index 67bb8d70..727f9797 100644 --- a/jrnl/plugins/dayone2_importer.py +++ b/jrnl/plugins/dayone2_importer.py @@ -9,7 +9,7 @@ class DayOne2Importer(JSONImporter): names = ["dayone2"] extension = "json" - def __init__(self, path): + def __init__(self, path, root_config): self.type = "dayone2" self.path = path self.keys = [ @@ -22,6 +22,7 @@ class DayOne2Importer(JSONImporter): "timeZone", "uuid", ] + self.root_config = root_config JSONImporter.__init__(self) self.convert_journal() diff --git a/jrnl/plugins/json_importer.py b/jrnl/plugins/json_importer.py index be954f70..4e33598b 100644 --- a/jrnl/plugins/json_importer.py +++ b/jrnl/plugins/json_importer.py @@ -4,9 +4,9 @@ import os from abc import abstractmethod from pathlib import Path +from jrnl.install import save_config from jrnl.Journal import PlainJournal from jrnl.plugins.text_exporter import TextExporter -from jrnl.plugins.util import add_journal_to_config class JSONImporter(PlainJournal, TextExporter): @@ -30,7 +30,8 @@ class JSONImporter(PlainJournal, TextExporter): self.data = self.parse_json() self.create_file(self.filename + ".txt") new_path = self.export(self.journal, self.filename + ".txt") - add_journal_to_config(self.type, new_path) + self.root_config["journals"][self.type] = new_path + save_config(self.root_config) def import_file(self): """Reads a JSON file and returns a dict.""" diff --git a/jrnl/plugins/util.py b/jrnl/plugins/util.py index 4303d175..a030f8d3 100644 --- a/jrnl/plugins/util.py +++ b/jrnl/plugins/util.py @@ -1,10 +1,5 @@ #!/usr/bin/env python # encoding: utf-8 -import yaml - -from jrnl.install import CONFIG_FILE_PATH, save_config -from jrnl.util import load_config -from pathlib import Path def get_tags_count(journal): @@ -28,14 +23,3 @@ def oxford_list(lst): return lst[0] + " or " + lst[1] else: return ", ".join(lst[:-1]) + ", or " + lst[-1] - - -def add_journal_to_config(name, path): - data = {} - try: - data = load_config(CONFIG_FILE_PATH) - except FileNotFoundError: - print("Config file not found.") - finally: - data["journals"][name] = path - save_config(data)