Marph, big thanks to you !
I tested API with win10 + Python 3.10.1x64 and Joplin 2.6.10 (prod, win32) - getting and modify notes works great!
Here script, that fills notes with only "URL" (from mobile Joplin) with readability text.
Used: joppy pypandoc readability-lxml
import pypandoc
import requests
from readability import Document as ReadabilityDocument
from joppy.api import Api
def replace_body2(api, note):
id = note["id"]
url = note["body"]
title = note["title"]
print(url)
res = requests.get(url, headers={'User-Agent': 'Chrome'}, timeout=30)
doc = ReadabilityDocument(res.text ,url=url)
body_html = doc.summary(html_partial=True)
if title==url:
title=doc.title()
api.modify_note(id, title=title)
body_md = pypandoc.convert_text(body_html,
format='html-native_divs',
to='gfm',
extra_args=['--wrap=none', '--quiet']
)
new_body = "# [{}]({})\n".format(title, url) + body_md
api.modify_note(id, source_url=url, body=new_body)
def main():
api = Api(token="YOUR TOKEN !")
print("Getting notes...")
all_notes = api.get_all_notes(fields="id,parent_id,title,source_url,body")
print("Notes: {}".format(len(all_notes)))
print("Finding notes...")
for note in all_notes:
body = note["body"]
if body[0:4]=="http" and body.find(" ") <= 0:
try:
replace_body2(api, note)
except:
print("Error at id={}, title={}".format(note["id"], note["title"]))
print("Done.")
if __name__ == "__main__":
main()