mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 13:08:31 +02:00
imported journal gets added to config
This commit is contained in:
parent
0c73448516
commit
774355971a
4 changed files with 23 additions and 3 deletions
|
@ -10,7 +10,7 @@ class DayOne2Importer(JSONImporter):
|
|||
extension = "json"
|
||||
|
||||
def __init__(self, path):
|
||||
self.type = "Day One 2"
|
||||
self.type = "DayOne2"
|
||||
self.path = path
|
||||
self.keys = [
|
||||
"audios",
|
||||
|
|
|
@ -6,6 +6,7 @@ from pathlib import Path
|
|||
|
||||
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):
|
||||
|
@ -28,7 +29,8 @@ class JSONImporter(PlainJournal, TextExporter):
|
|||
if self.validate_schema():
|
||||
self.data = self.parse_json()
|
||||
self.create_file(self.filename + ".txt")
|
||||
return self.export(self.journal, self.filename + ".txt")
|
||||
new_path = self.export(self.journal, self.filename + ".txt")
|
||||
add_journal_to_config(self.type, new_path)
|
||||
|
||||
def import_file(self):
|
||||
"""Reads a JSON file and returns a dict."""
|
||||
|
|
|
@ -28,7 +28,8 @@ class TextExporter:
|
|||
try:
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.write(cls.export_journal(journal))
|
||||
return f"[Journal exported to {path}]"
|
||||
print(f"[Journal exported to {path}]")
|
||||
return path
|
||||
except IOError as e:
|
||||
return f"[{ERROR_COLOR}ERROR{RESET_COLOR}: {e.filename} {e.strerror}]"
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
import yaml
|
||||
|
||||
from jrnl.util import load_config
|
||||
from jrnl.install import CONFIG_FILE_PATH, CONFIG_FILE_PATH_FALLBACK
|
||||
|
||||
|
||||
def get_tags_count(journal):
|
||||
|
@ -23,3 +27,16 @@ 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:
|
||||
try:
|
||||
data = load_config(CONFIG_FILE_PATH_FALLBACK)
|
||||
except FileNotFoundError:
|
||||
print("Config file not found.")
|
||||
finally:
|
||||
data["journals"][name] = path
|
||||
|
|
Loading…
Add table
Reference in a new issue