mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-19 04:28:31 +02:00
consolidate demo plugins to common package
This commit is contained in:
parent
09d652899a
commit
b8f0e6a35f
5 changed files with 100 additions and 4 deletions
|
@ -32,6 +32,11 @@ jobs:
|
||||||
python-version: 3.9
|
python-version: 3.9
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: Extract branch name
|
||||||
|
shell: bash
|
||||||
|
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
|
||||||
|
id: extract_branch
|
||||||
|
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
|
@ -49,9 +54,9 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
pip install poetry
|
pip install poetry
|
||||||
poetry config --local virtualenvs.in-project true
|
poetry config --local virtualenvs.in-project true
|
||||||
poetry add git+https://github.com/MinchinWeb/jrnl-rot13-exporter.git
|
|
||||||
poetry install --remove-untracked
|
poetry install --remove-untracked
|
||||||
poetry install
|
poetry install
|
||||||
|
poetry run python -m pip install -e "git+${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git@{{ steps.extract_branch.outputs.branch }}#egg=jrnl-demo-plugins&subdirectory=tests/external_plugins_src"
|
||||||
|
|
||||||
- name: Test with pytest
|
- name: Test with pytest
|
||||||
if: success() || failure()
|
if: success() || failure()
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
# pelican\contrib\exporter\custom_json.py
|
||||||
|
import json
|
||||||
|
|
||||||
|
from jrnl.plugins.base import BaseExporter
|
||||||
|
from jrnl.plugins.util import get_tags_count
|
||||||
|
|
||||||
|
__version__ = "v1.0.0"
|
||||||
|
|
||||||
|
|
||||||
|
class Exporter(BaseExporter):
|
||||||
|
"""
|
||||||
|
This basic Exporter can convert entries and journals into JSON.
|
||||||
|
"""
|
||||||
|
|
||||||
|
names = ["json"]
|
||||||
|
extension = "json"
|
||||||
|
version = __version__
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def entry_to_dict(cls, entry):
|
||||||
|
return {
|
||||||
|
"title": entry.title,
|
||||||
|
"body": entry.body,
|
||||||
|
"date": entry.date.strftime("%Y-%m-%d"),
|
||||||
|
}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def export_entry(cls, entry):
|
||||||
|
"""Returns a json representation of a single entry."""
|
||||||
|
return json.dumps(cls.entry_to_dict(entry), indent=2) + "\n"
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def export_journal(cls, journal):
|
||||||
|
"""Returns a json representation of an entire journal."""
|
||||||
|
tags = get_tags_count(journal)
|
||||||
|
result = {
|
||||||
|
"entries": [cls.entry_to_dict(e) for e in journal.entries],
|
||||||
|
}
|
||||||
|
return json.dumps(result, indent=2)
|
|
@ -2,10 +2,11 @@ import codecs
|
||||||
|
|
||||||
from jrnl.plugins.base import BaseExporter
|
from jrnl.plugins.base import BaseExporter
|
||||||
|
|
||||||
__version__ = "1.0.0"
|
__version__ = "v1.0.0"
|
||||||
|
|
||||||
|
|
||||||
class Exporter(BaseExporter):
|
class Exporter(BaseExporter):
|
||||||
names = ["rot13"]
|
names = ["rot13", "txt"]
|
||||||
extension = "txt"
|
extension = "txt"
|
||||||
version = __version__
|
version = __version__
|
||||||
|
|
||||||
|
|
|
@ -13,3 +13,4 @@ from jrnl.plugins.base import BaseExporter
|
||||||
class Exporter(BaseExporter):
|
class Exporter(BaseExporter):
|
||||||
names = ["testing", "test"]
|
names = ["testing", "test"]
|
||||||
version = "v0.0.1"
|
version = "v0.0.1"
|
||||||
|
extension = "test"
|
|
@ -0,0 +1,50 @@
|
||||||
|
# pelican\contrib\importer\sample_json.py
|
||||||
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from jrnl import Entry
|
||||||
|
from jrnl.plugins.base import BaseImporter
|
||||||
|
|
||||||
|
__version__ = "v1.0.0"
|
||||||
|
|
||||||
|
|
||||||
|
class Importer(BaseImporter):
|
||||||
|
"""JSON Importer for jrnl."""
|
||||||
|
|
||||||
|
names = ["json"]
|
||||||
|
version = __version__
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def import_(journal, input=None):
|
||||||
|
"""
|
||||||
|
Given a nicely formatted JSON file, will add the
|
||||||
|
contained Entries to the journal.
|
||||||
|
"""
|
||||||
|
|
||||||
|
old_cnt = len(journal.entries)
|
||||||
|
if input:
|
||||||
|
with open(input, "r", encoding="utf-8") as f:
|
||||||
|
data = json.loads(f)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
data = sys.stdin.read()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print(
|
||||||
|
"[Entries NOT imported into journal.]",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
for json_entry in data:
|
||||||
|
raw = json_entry["title"] + "/n" + json_entry["body"]
|
||||||
|
date = json_entry["date"]
|
||||||
|
entry = Entry.Entry(journal, date, raw)
|
||||||
|
journal.entries.append(entry)
|
||||||
|
|
||||||
|
new_cnt = len(journal.entries)
|
||||||
|
print(
|
||||||
|
"[{} entries imported to '{}' journal]".format(
|
||||||
|
new_cnt - old_cnt, journal.name
|
||||||
|
),
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
Loading…
Add table
Reference in a new issue