jrnl/jrnl/plugins/jrnl_importer.py
Micah Jerome Ellison c5729420a4
Comply with GPL by acknowledging all authors and including license info in each source file (#1121)
* Update authors to "jrnl contributors" to comply with GPL3
* Include jrnl email address with contributors
* Include GPL notice in jrnl --version
* Apply consistent copyright and license to all Python files
* Add copyright and license to documentation
* Add copyright and license to docs theme
* Wiping poetry cache to try to resolve a test issue
* Testing with Python 3.9.0 in attempt to bypass GitHub Actions failure in 3.9.1
* make format
* Exclude Windows Python 3.9 build which is failing due to a GitHub Actions problem
* Modify testing to get around this 3.9 issue...
* Fix exclude
2020-12-19 14:53:15 -08:00

34 lines
1 KiB
Python

#!/usr/bin/env python
# encoding: utf-8
# Copyright (C) 2012-2021 jrnl contributors
# License: https://www.gnu.org/licenses/gpl-3.0.html
import sys
class JRNLImporter:
"""This plugin imports entries from other jrnl files."""
names = ["jrnl"]
@staticmethod
def import_(journal, input=None):
"""Imports from an existing file if input is specified, and
standard input otherwise."""
old_cnt = len(journal.entries)
if input:
with open(input, "r", encoding="utf-8") as f:
other_journal_txt = f.read()
else:
try:
other_journal_txt = sys.stdin.read()
except KeyboardInterrupt:
print("[Entries NOT imported into journal.]", file=sys.stderr)
sys.exit(0)
journal.import_(other_journal_txt)
new_cnt = len(journal.entries)
print(
"[{} imported to {} journal]".format(new_cnt - old_cnt, journal.name),
file=sys.stderr,
)
journal.write()