GithubHelp home page GithubHelp logo

nriver / trilium-py Goto Github PK

View Code? Open in Web Editor NEW
111.0 4.0 26.0 192 KB

Python client for ETAPI of Trilium Note. Trilium 的 Python版 ETAPI 客户端

License: GNU Affero General Public License v3.0

Python 100.00%
etapi markdown python python3 trilium-notes migration-tool note-taking

trilium-py's Issues

em tags in imported image paths

Hello,

trilium-py has been invaluable. Thank you for all your work.

I am using trilium-py version 0.8.2.

After importing an obsidian vault using obsidian-export and importing it using upload_md_folder, I ended up with a series of images that had the underscores replaced with em tags. For example: 2023_abandoned_canyon.png becomes 2023<em>abandoned</em>canyon.png.

Below is a simple python script to fix entries that have been corrupted in that way that worked for me™️ and provides a workaround for the issue.

res = ea.search_note("</em>")
for r in res['results']:
    if r["type"] == "image" and "</em>" in r['title']:
        orig_title = r['title']
        new_title = orig_title.replace("<em>", "_").replace("</em>", "_")
        ea.patch_note(r['noteId'], title=new_title)
        print(f" [!] {orig_title} -> {new_title}")

        for n in r['parentNoteIds']:
            id = n
            n = ea.get_note(id)
            print(f" [ ] - {n['title']}")
            c = ea.get_note_content(id)
    
            c = c.replace(orig_title, new_title)
            ea.update_note_content(id, c)
        
        print(" [-] Fixed")

Problem with certain images when importing .md

There are certain images that are not recognized correctly when importing markdown files.

<p><img width="736" height="414" src="../certainpath.jpg"/></p>

that is due to the fact that the regex expression in

pat = '<img (.*?) />'
is expecting a white space just before "/>". And that is not always the case (even with though all the code is generated by markdown2markdown.

the simplest solution is to change that line to:

pat = '<img (.*?)/>'
But i'm not sure that that change could generate problems with other images (not that i can think of)

[feature requests] Upload file

Sounds like markdown import only process image, sometime the markdown file contain link to other file, which not upload in this script.

Could I use this for making ChatGPT bot?

I want to use ChatGPT API for updating notes by clicking a button or pushing hotkeys in a note.

Can this library be used for my purpose?

I am proficient in Python but have no idea about Node.js things.

Thanks.

Sync by using trilium-py?

I don't find the proper API method for syncing.

I may need to get notes after specific modifiedDate.

Duplicate Journal Day Note

I am not sure this is a trilium-py or trilium sync server issue. Or, mine...

I wrote a script to query critical items from Jira and create TODO items for me on the Journal Day Note. The script works fine when the Day note exists.

When it creates a new empty page (3am via cron) and then I press the "Open Today's Journal Note" launcher (at 8am) the launcher creates a second note for the day... The note created by trilium-py has the TODO items and my Day template contents while the launcher note only has my "Day template" contents.

I am running a sync server (quadlet/podman) and the script is configured to run against that server. The launcher, of course, is run on my laptop.

Is it "bad" style to call the ETAPI endpoint refresh-note-ordering after creating the Day note? That is the only ETAPI endpoint that seems to push to clients. At least from the OpenAPI spec. Or, there appears to be apiRoute(POST, '/api/sync/now'

Homepage: https://github.com/zadam/trilium
App version: 0.60.4
DB version: 214
Sync version: 29
Build date: 2023-06-19T23:26:50+02:00
Build revision: 5905950c17791ce0eb278e010c2c8b3450fdb447
Data directory: .../.local/share/trilium-data
Image: docker.io/zadam/trilium:0.60.4

invalid escape sequence (was Export: no argument 'savePath')

This snippet worked a last week:

def export(noteId, alias):
    res = ea.export_note(
        noteId=noteId,
        format="html",
        savePath=f"out/{alias}.zip",
    )
    print(f"Export 'out/{alias}.zip'", res)
    return res

today I get:

D:\personal\metril\.pixi\envs\default\Lib\site-packages\trilium_py\client.py:874: SyntaxWarning: invalid escape sequence '\l'
  lambda x: x.replace("<", " \lt ").replace(">", " \gt "), latex_code_part
D:\personal\metril\.pixi\envs\default\Lib\site-packages\trilium_py\client.py:874: SyntaxWarning: invalid escape sequence '\g'
  lambda x: x.replace("<", " \lt ").replace(">", " \gt "), latex_code_part
Trilium appVersion: 0.63.5
Found note: FlE3sCcgtRkW maphew.com
Traceback (most recent call last):
  File "D:\personal\metril\export-note.py", line 48, in <module>
    export(id, alias)
  File "D:\personal\metril\export-note.py", line 18, in export
    res = ea.export_note(
          ^^^^^^^^^^^^^^^
TypeError: ETAPI.export_note() got an unexpected keyword argument 'savePath'

Doubling the backslashes in client.py:874 makes the syntax warning go away, but looking at git blame says the code has been single slash for at least 7 months so this is probably not the right fix:

lambda x: x.replace("<", " \\lt ").replace(">", " \\gt "), latex_code_part

ModuleNotFoundError: No module named 'magic'

Running this package from pypi results in the error: ModuleNotFoundError: No module named 'magic'

It looks like there may have been a pull request that fixed this. Maybe you only need to re-deploy to pypi?

How to test for valid login and etapi session?

How to test for a valid login and ETAPI session gracefully?

For example this will fail with ugly json decode error if the server is wrong url:

server_url = "http://nas:8080/"
token = os.environ["TRILIUM_TOKEN"]

ea = ETAPI(server_url, token)
print(f'Source Trilium appVersion: {ea.app_info()["appVersion"]}')
...snip...
  File "A:\code\mhw\metril\.pixi\envs\default\Lib\site-packages\trilium_py\client.py", line 86, in app_info
    return res.json()
           ^^^^^^^^^^
  File "A:\code\mhw\metril\.pixi\envs\default\Lib\site-packages\requests\models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

The simpler print(ea.appinfo()) does the same, so I can't do something like if not ea.appinfo(): ...

And dropping the braces, so just print(ea.appinfo) emits <bound method ETAPI.app_info of <trilium_py.client.ETAPI object at 0x00000147F106E840>> which I don't know what to do with.

Question: What is the earliest python version to be supported?

I have been working from the assumption that you intended to support Python 3.6+ is that true? You mentioned in another issue that the project was using default templates. If the project drops earlier versions that will clean up some of the typing code.

I would like to configure tox and add unit tests.

/jwh

    classifiers=[  # Optional
        # How mature is this project? Common values are
        #   3 - Alpha
        #   4 - Beta
        #   5 - Production/Stable
        'Development Status :: 5 - Production/Stable',

        # Indicate who your project is intended for
        'Intended Audience :: Developers',
        'Topic :: Software Development :: Build Tools',

        # Pick your license as you wish
        'License :: OSI Approved :: GNU Affero General Public License v3',

        # Specify the Python versions you support here. In particular, ensure
        # that you indicate you support Python 3. These classifiers are *not*
        # checked by 'pip install'. See instead 'python_requires' below.
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
        'Programming Language :: Python :: 3.8',
        'Programming Language :: Python :: 3.9',
        "Programming Language :: Python :: 3.10",
        "Programming Language :: Python :: 3.11",
        'Programming Language :: Python :: 3 :: Only',
    ],

Img tags without closing "/>"

Hi,

again with importing img tags. I'm still importing some md files and i found another issue (previous: #34) related with the regex expression. I still found some images that are not properly imported. That's because img tag not necessarily need a closing match /> and > is enough. This can be seen in the example from the w3schools

<img src="img_girl.jpg" alt="Girl in a jacket" width="500" height="600">

So, again, probably the regex expression should be better like this:

pat = '<img (.*?)/?>'

So the / is optional.

Error raised using code from main: 4dc017d03d65dad31871e36b6d1fd59439d80b34

Traceback (most recent call last):
  File "/home/jhonce/Projects/trilium-addons/bugSLA/bugSLA.py", line 25, in <module>
    from trilium_py.client import ETAPI
  File "/home/jhonce/Projects/Python/trilium-py/src/trilium_py/client.py", line 18, in <module>
    from .utils.note_util import beautify_content, sort_note_by_headings
  File "/home/jhonce/Projects/Python/trilium-py/src/trilium_py/utils/note_util.py", line 7, in <module>
    from trilium_py.src.trilium_py.utils.html_util import sort_h_tags_with_hierarchy
ModuleNotFoundError: No module named 'trilium_py.src'

Using python 3.11 and trilium-py installed using python -m pip install --user -e .

Import markdown files with frontmatter yaml?

Thanks for creating this library! I've only just started testing out Trilium, but I'm liking it so far. One of the things I'd like to do is import all of my old notes from Joplin and Obsidian.

I used a script similar to the one in the README but noticed yaml frontmatter doesn't get preserved. For example, a joplin exported note like this:

---
title: 2021-03-05 - hvac furnace tune up
updated: 2021-03-05 15:27:20Z
created: 2021-03-05 13:43:07Z
latitude: xx.xx
longitude: -yy.yy
altitude: 101
---

note contents here

Gets turned into this (when viewing the source of the trilium note):

<hr />

<p>title: 2021-03-05 - hvac furnace tune up
updated: 2021-03-05 15:27:20Z
created: 2021-03-05 13:43:07Z
latitude: xx.xx
longitude: -yy.yy</p>

<h2>altitude: 101</h2>

<p>note contents here</p>

Is it possible (and does it make sense) to convert that yaml frontmatter and turn it into attributes on the note? For my example, I think it'd get turned into something like #latitude=xx.xx #longitude=-yy.yy #altitude=101 .

I've used https://pypi.org/project/python-frontmatter/ in the past and it worked okay. I haven't looked much at the code here or the trilium api, but I might try to take a look this weekend if I continue w/ trilium.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.