Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
JackGruber committed Dec 26, 2020
2 parents a5c3374 + 6cfe182 commit 2e85c23
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 8 deletions.
10 changes: 3 additions & 7 deletions JoplinWinBackup.au3
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,9 @@ if( WinWaitActive("[REGEXPTITLE:^Joplin$; CLASS:Chrome_WidgetWin_1]","", 10) = 0
EndIf

; Send keys for export menue
$keyCombo = IniRead($INI, "General", "key_combo", "fej")
Send ("!" & StringMid($keyCombo,1,1))
$keyCombo = IniRead($INI, "General", "key_combo", "{ALT}{SPACE}ej")
Send ($keyCombo)
Sleep(100)
For $i = 2 To StringLen($keyCombo) Step +1
Send (StringMid($keyCombo,$i,1))
Sleep(100)
Next

; Wait wor save dialog
$save_dialog = IniRead($INI, "General", "save_dialog", "Speichern unter")
Expand Down Expand Up @@ -73,7 +69,7 @@ $BACKUPFILE = $BACKUPFILE & ".jex"
ControlSetText($hSAVE, "", "[CLASS:Edit]", $BACKUPFOLDER & "\" & $BACKUPFILE)
Sleep(50)
ControlClick($hSAVE, "", "[Class:Button;Instance:2]")
Sleep(50)
Sleep(IniRead($INI, "General", "wait_overwrite_dialog", 200))

; Check for confirmation dialog
$hCONFIRM = WinGetHandle ( "[ACTIVE]", "" )
Expand Down
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pip install PyMuPDF
- [hotfolder.py](#hotfolderpy)
- [add_pdf_previews.py](#add_pdf_previewspy)
- [todo_overview.py](#todo_overviewpy)
- [note_overview.py](#note_overviewpy)
- [JoplinWinBackup.au3](#JoplinWinBackupau3)

### Parameters for all tools
Expand Down Expand Up @@ -94,6 +95,27 @@ Creates or Updates a note with a list of all open ToDo's. All to-dos that have b
python todo_overview.py --title "Open ToDo's" --as-todo --tag "importend"
```

### note_overview.py

Creates or updates a note with a list of all notes that match the search query.

<img src="img/note_overview.jpg">

**Parameters**

- `-n` Defines the notebook in which the new Note should be created.
- `--title` Defines the title for the note to be updated or createt. Default `Note overview`
- `--tag` Specify of comma separated Tags which should be added to the note. Example: `project, overview`
- `--query` Specify the [seach query](https://joplinapp.org/#searching) for the Notes like in Joplin
- `--order_by` Specify the field for the sorting of the Table content. (All Joplin fields can be used for sorting). Default `user_updated_time`
- `--order_dir` Sorting sequence, possible values `DESC` or `ASC`. Default `DESC`

**Example**

```python
python note_overview.py --query "tag:! tag:\"project xyz\"" -n Scans --title "Overview Important Notes" --tag "!"
```

### JoplinWinBackup.au3

---
Expand All @@ -115,3 +137,24 @@ Options from the JoplinWinBackup.ini
- `backup_file_add_time` Append time to the Backupfile. Default `1`, `0` = No, `1`= Yes
- `backup_file_name` Filename of the Backup. Default `joplin_backup.jex`
- `overwrite_file` Overwrite existing backup file. Default `0`, `0` = No, `1`= Yes

## Changelog

## 2020-12-26 v1.5.0

- Added note_overview.py script

### add_pdf_previews.py

- Keep original updated time when adding PDF preview

### JoplinWinBackup

- Read complet key_combo from ini
- Read sleep value wait_overwrite_dialog from ini

## 2020-11-18 v1.4.0

❗ breaking changes, requires at least Joplin v1.4.11 ❗

- Change to new Joplin API
Binary file added img/note_overview.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion joplin/joplintools.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def AddPDFPreviewToNote(note_id):
print("")
return True
else:
note = joplinapi.GetNotes(note_id, "body, title")
note = joplinapi.GetNotes(note_id, "body, title, user_updated_time")
body_new = note['body']

print("\t" + note['title'])
Expand Down Expand Up @@ -97,6 +97,7 @@ def AddPDFPreviewToNote(note_id):
if note_update == True:
data = {}
data['body'] = body_new
data['user_updated_time'] = note['user_updated_time']
json_data = json.dumps(data)
joplinapi.UpdateNote(note_id, json_data)
print("")
Expand Down
154 changes: 154 additions & 0 deletions note_overview.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# -*- coding: utf-8 -*-

import click
from joplin import joplinapi
import time
import sys
import json
from datetime import datetime


@click.command()
@click.option(
"-n",
"--notebook",
"notebook",
required=False,
help="""Specify the notebook in which to place newly created overview."""
""" Specified notebook must exist or program will exit.""",
)
@click.option(
"--title",
"title",
required=True,
default="Note overview",
help="""Note Title for the overview note""",
)
@click.option(
"--tag",
"add_tag",
required=False,
help="""Specify Tags to add to the note. Comma separated for multiple tags.""",
)
@click.option(
"-t",
"--token",
"token",
required=False,
help="""Specify the Joplin API token.""",
)
@click.option(
"-u",
"--url",
"url",
required=False,
default="http://localhost:41184",
show_default=True,
help="""Specify the Joplin web clipper URL.""",
)
@click.option(
"-q",
"--query",
"query",
required=True,
help="""Specify the search query.""",
)
@click.option(
"--order_by",
"order_by",
required=False,
default='user_updated_time',
help="""Specify the Joplin field for the note ordering.""",
)
@click.option(
"--order_dir",
"order_dir",
required=False,
type=click.Choice(['ASC', 'DESC'], case_sensitive=False),
default="DESC",
show_default=True
)
def Main(notebook, title, add_tag, token, url, query, order_by, order_dir):
if token is not None:
joplinapi.SetEndpoint(url, token)
elif joplinapi.LoadEndpoint() == False:
joplinapi.SetEndpoint(url, token)

while joplinapi.Ping() == False:
print("Joplin not running")
sys.exit(1)

new_note_query = "title:'" + title + "'"
if notebook != None:
new_note_query += ' notebook:"' + notebook + '"'

# Find ID for overview note
page = 1
overview_id = None
while True and overview_id == None:
search = joplinapi.Search(new_note_query, 'note', limit=50, page=page, fields='id, title', order_by=order_by, order_dir=order_dir)
for note in search['items']:
if(note['title'] == title):
overview_id = note['id']
if search['has_more'] == False:
break
page += 1

# Find notbook ID
if overview_id is None and notebook is not None:
notebook_id = joplinapi.GetNotebookID(notebook)
if notebook_id == False:
print("Notebook not found")
sys.exit(1)
elif overview_id is None:
print("No notebook defined and no note with title '" + title + "' found!")
sys.exit(1)

if add_tag is not None:
add_tag = add_tag.replace(", ", ",")
add_tag = add_tag.split(",")

# collect information
body = "| created time | updated time | Title |\n"
body += "| --- | --- | --- |\n"
page = 1
print(query)
while True:
search = joplinapi.Search(query, 'note', limit=50, page=page, fields='id, title, created_time, user_updated_time', order_by=order_by, order_dir=order_dir)
for note in search['items']:
if(note['id'] != overview_id):
epoch = int(note['created_time'] / 1000)
date_created = datetime.fromtimestamp(epoch).strftime('%Y-%m-%d %H:%M')
epoch = int(note['user_updated_time'] / 1000)
date_updated = datetime.fromtimestamp(epoch).strftime('%Y-%m-%d %H:%M')
body += "|" + date_created + "|" + date_updated + "|[" + note['title'] + "](:/" + note['id'] + ")|\n"
if search['has_more'] == False:
break
page += 1

if overview_id is None:
overview_id = joplinapi.CreateNote(title, body, notebook_id)
if(overview_id != False):
print("Create note '" + title + "' in notebook '" + notebook + "'")
else:
print("Error on note create")
sys.exit(1)
else:
org_note = joplinapi.GetNotes(overview_id, "body")
if (org_note['body'] != body):
data = {}
data['body'] = body
if( joplinapi.UpdateNote(overview_id, json.dumps(data)) ):
print("Note '" + title + "' in '" + notebook + "' updated")
else:
print("Error on note create")
sys.exit(1)
else:
print("No new information")

if add_tag is not None:
for tag in add_tag:
joplinapi.AddTagToNote(tag, overview_id, True)

if __name__ == "__main__":
Main()

0 comments on commit 2e85c23

Please sign in to comment.