Skip to content

Commit

Permalink
fix CI v2
Browse files Browse the repository at this point in the history
  • Loading branch information
marph91 committed Apr 11, 2024
1 parent a3f5100 commit 94c9387
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 89 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
os: ["windows-latest", "ubuntu-latest", "macos-latest"]
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.11"
- name: Install dependencies
run: pip install -r requirements-dev.txt
- name: Build executable with pyinstaller
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install pip dependencies
run: pip install -r requirements-dev.txt
- name: Run linting
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install pip dependencies
run: pip install -r requirements-dev.txt
- name: Run linting
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ ignore_missing_imports = True

[pylint.*]
disable = logging-fstring-interpolation,missing-function-docstring
[pylint.MISCELLANEOUS]
notes = # don't show todos
85 changes: 43 additions & 42 deletions src/apps/notion.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@
import intermediate_format as imf


def convert(input_zip: Path, parent: imf.Notebook):
# TODO: note links and attachments
temp_folder = Path(tempfile.gettempdir()) / f"joplin_export_{int(time.time())}"

# unzip nested zip file
def unzip(input_zip: Path, temp_folder: Path):
# unzip nested zip file in notion format
with zipfile.ZipFile(input_zip) as zip_ref:
for nested_zip_name in zip_ref.namelist():
with zip_ref.open(nested_zip_name) as nested_zip:
nested_zip_filedata = io.BytesIO(nested_zip.read())
with zipfile.ZipFile(nested_zip_filedata) as nested_zip_ref:
nested_zip_ref.extractall(temp_folder)


def convert(input_zip: Path, parent: imf.Notebook):
# TODO: note links and attachments
temp_folder = Path(tempfile.gettempdir()) / f"joplin_export_{int(time.time())}"

unzip(input_zip, temp_folder)

# Flatten folder structure. I. e. move all files to root directory.
# https://stackoverflow.com/a/50368037/7410886
for item in temp_folder.iterdir():
Expand All @@ -31,44 +35,41 @@ def convert(input_zip: Path, parent: imf.Notebook):
item.rmdir()

for item in temp_folder.iterdir():
if item.is_dir():
if item.is_dir() or item.suffix != ".md":
continue
if item.suffix == ".md":
# id is appended to filename
title, original_id = item.stem.rsplit(" ", 1)
# first line is title, second is whitespace
body = "\n".join(item.read_text().split("\n")[2:])
# id is appended to filename
title, original_id = item.stem.rsplit(" ", 1)
# first line is title, second is whitespace
body = "\n".join(item.read_text().split("\n")[2:])

# find links
resources = []
note_links = []
for description, url in common.get_markdown_links(body):
if url.startswith("http"):
continue # web link
elif url.endswith(".md"):
# internal link
_, linked_note_id = Path(url).stem.rsplit("%20", 1)
note_links.append(
imf.NoteLink(
f"[{description}]({url})", linked_note_id, description
)
)
elif (temp_folder / url).is_file():
# resource
resources.append(
imf.Resource(
temp_folder / url, f"[{description}]({url})", description
)
# find links
resources = []
note_links = []
for description, url in common.get_markdown_links(body):
if url.startswith("http"):
continue # web link
if url.endswith(".md"):
# internal link
_, linked_note_id = Path(url).stem.rsplit("%20", 1)
note_links.append(
imf.NoteLink(f"[{description}]({url})", linked_note_id, description)
)
elif (temp_folder / url).is_file():
# resource
resources.append(
imf.Resource(
temp_folder / url, f"[{description}]({url})", description
)
)

note_joplin = imf.Note(
{
"title": title,
"body": body,
"source_application": Path(__file__).stem,
},
original_id=original_id,
resources=resources,
note_links=note_links,
)
parent.child_notes.append(note_joplin)
note_joplin = imf.Note(
{
"title": title,
"body": body,
"source_application": Path(__file__).stem,
},
original_id=original_id,
resources=resources,
note_links=note_links,
)
parent.child_notes.append(note_joplin)
73 changes: 37 additions & 36 deletions src/apps/obsidian.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,48 @@ def convert(folder: Path, parent: imf.Notebook, root_folder: Path | None = None)
root_folder = folder

for item in folder.iterdir():
note_links = []
resources = []
if item.is_file():
if item.suffix == ".md":
body = item.read_text()
if item.suffix != ".md":
continue
note_links = []
resources = []
body = item.read_text()

# https://help.obsidian.md/Linking+notes+and+files/Internal+links
# TODO: markdown links
for file_prefix, url, description in common.get_wikilink_links(body):
alias = "" if description.strip() == "" else f"|{description}"
original_text = f"{file_prefix}[[{url}{alias}]]"
if file_prefix:
# Resources can be located anywhere?!
potential_matches = list(root_folder.glob(f"**/{url}"))
if not potential_matches:
LOGGER.debug(f"Couldn't find match for resource {url}")
continue
resources.append(
# TODO: is image and add ! in markdown -> ![]()
imf.Resource(
potential_matches[0], original_text, description or url
)
# https://help.obsidian.md/Linking+notes+and+files/Internal+links
# TODO: markdown links
for file_prefix, url, description in common.get_wikilink_links(body):
alias = "" if description.strip() == "" else f"|{description}"
original_text = f"{file_prefix}[[{url}{alias}]]"
if file_prefix:
# Resources can be located anywhere?!
potential_matches = list(root_folder.glob(f"**/{url}"))
if not potential_matches:
LOGGER.debug(f"Couldn't find match for resource {url}")
continue
resources.append(
# TODO: is image and add ! in markdown -> ![]()
imf.Resource(
potential_matches[0], original_text, description or url
)
else:
# internal link
note_links.append(
imf.NoteLink(original_text, url, description or url)
)

parent.child_notes.append(
imf.Note(
{
"title": item.stem,
"body": body,
"source_application": Path(__file__).stem,
},
original_id=item.stem,
resources=resources,
note_links=note_links,
)
else:
# internal link
note_links.append(
imf.NoteLink(original_text, url, description or url)
)

parent.child_notes.append(
imf.Note(
{
"title": item.stem,
"body": body,
"source_application": Path(__file__).stem,
},
original_id=item.stem,
resources=resources,
note_links=note_links,
)
)
else:
new_parent = imf.Notebook(
{
Expand Down
2 changes: 1 addition & 1 deletion src/apps/simplenote.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def convert(zip_or_folder: Path, parent: imf.Notebook):
for description, url in common.get_markdown_links(body):
if url.startswith("http"):
continue # web link
elif url.startswith("simplenote://"):
if url.startswith("simplenote://"):
# internal link
_, linked_note_id = url.rsplit("/", 1)
note_links.append(
Expand Down
14 changes: 7 additions & 7 deletions test/example_commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ set -e
python src/joplin_custom_importer.py test_inputs
python src/joplin_custom_importer.py test_inputs/arbitrary_folder test_inputs

python src/joplin_custom_importer.py test_inputs/clipto/clipto_backup_240401_105154.json --app clipto
python src/joplin_custom_importer.py test_inputs/Google\ Keep --app google_keep
python src/joplin_custom_importer.py test_inputs/obsidian_vault --app obsidian
python src/joplin_custom_importer.py test_inputs/simplenote --app simplenote
python src/joplin_custom_importer.py test_inputs/todo_txt/examples_from_readme.txt --app todo_txt
python src/joplin_custom_importer.py test_inputs/todoist/Privates.csv --app todoist

# This is a local directory, because it contains user data.
if [ -d "tmp" ]; then
python src/joplin_custom_importer.py tmp/nimbus_export_user/Food\ Original\ export\ from\ Nimbus/ --app nimbus_note
python src/joplin_custom_importer.py tmp/notion/72a2f31c-3a46-4b44-826d-ae046e693551_Export-d609fb9f-43a4-475d-ba88-1db3e9e6bcd2.zip --app notion
# python src/joplin_custom_importer.py tmp/tiddlywiki/tiddlers.json --app tiddlywiki
fi

python src/joplin_custom_importer.py test_inputs/clipto/clipto_backup_240401_105154.json --app clipto
python src/joplin_custom_importer.py test_inputs/Google\ Keep --app google_keep
python src/joplin_custom_importer.py test_inputs/obsidian_vault --app obsidian
python src/joplin_custom_importer.py test_inputs/simplenote --app simplenote
python src/joplin_custom_importer.py test_inputs/todo_txt/examples_from_readme.txt --app todo_txt
python src/joplin_custom_importer.py test_inputs/todoist/Privates.csv --app todoist

0 comments on commit 94c9387

Please sign in to comment.