File Uploader and OCR

I tried to tidy up some of the missing pieces of rest_uploader by releasing a new version. Command line options for destination notebook, server, port, and a fix for the temp file location on Windows installations. Any feedback appreciated!

How do I install the new version? Do I have to uninstall the old one first? Typing ‘pip install rest_uploader’ in WinPython’s Command Prompt Window gives 15 Requirement already satisfied lines. Sorry to be a Python newbie!

No worries!
pip install -U rest_uploader
oughtta do the trick.

One does indeed uninstall first!
pip uninstall rest_uploader
pip install rest_uploader. Easy!

I’ve noticed a discrepancy between the help and the github doc in the order of the command line arguments. Help has the [OPTIONS] before the PATH and github languages example has them the other way round. Oh, and on github you have two hyphens before the s and p options.

It’s many many years since I was working on a Unix system and can’t remember the rules about command line options. I don’t think we had two hyphen names. However is a trailing space optional after the name or the letter? e.g. for the taging option which are correct?

-t=no
-t =no
-t no
-tno

-t no

Thanks again for the feedback!
Fixed the hyphens and made a couple other clarifications to the readme. Options can come before or after the path.

I have it working and it’s looking good, nice extra info telling us what’s going on.

Is it by design that once you have uploaded a file ‘the file is still open in Python’? Once I have a file copied to JoplinProfile\resources I want to delete it in the temp\scans folder but I can’t till I stop rest_uploader?

The following example will upload newly created notes to the Taxes Notebook, and OCR in German: rest_uploader -d "Taxes" -l ger /path/to/directory

No need for "s around Taxes? (have tried with and without and both work)

no need, correct. A better example might have been “Tax Documents”, which would require the quotes.

Not by design, no. I think I noticed it once during testing when launching from git bash on Windows but the issue didn’t persist when launching from the regular Win command line, Powershell, or Linux.

I was wondering if I might like an option in rest_uploader to ‘move’ the file rather than copy it (if it got copied correctly!)

A sweep option. Yeah, that'd be a nice addition in a future version :slightly_smiling_face:

D:\PA.c\PortableApps\_NonPAF-StartRest_uploader>rest_uploader.exe D:\Temp\Scans -d __rest_uploaded -t no
Launching Application rest_uploader.cli.main
Endpoint: http://127.0.0.1:41184
Temp Path: C:\Users\Roger\AppData\Local\Temp
Found Notebook ID: 399d7f8404e146b885c4fb346af24bd8
Language: eng
Automatically Tag Notes? no
Desitnation Notebook: __rest_uploaded
Monitoring directory D:\Temp\Scans for files

Destination spelt wrong and colon missed off end of Monitoring Directory? (and maybe on end of Launching Application?

Ugh... spelling error :frowning:
Well I fixed it in my code but it's going to have to wait for the next version release to get the fix...
Thanks!

I have been experimenting with having Poppler and tesseract-OCR in the PATH. It seems rest_uploader doesn’t complain if Tesseract-OCR isn’t in the PATH but does complain if Poppler isn’t. Would it be possible to check for the presence of Poppler early so you could output an error message immediately rather than having many lines of errors before suggesting Poppler isn’t installed? No bigee, just a thought.

Specify a different upload notebook by specifying a destination from the command line using -d or --destination

Oops?

F:\rest_uploader>rest_uploader.exe F:\Temp\Scans -d _rest_uploaded -t no
Usage: rest_uploader [OPTIONS] PATH
Try 'rest_uploader --help' for help.

Error: no such option: -d

F:\rest_uploader>

and

F:\rest_uploader>rest_uploader.exe F:\Temp\Scans --destination _rest_uploaded -t no
Usage: rest_uploader [OPTIONS] PATH
Try 'rest_uploader --help' for help.

Error: no such option: --destination

F:\rest_uploader>

@kellerjustin

Sorry. My Oops, somehow I was running 1.5.0

[Edit] I was running on another flash drive where I hadn’t updated rest_uploader (the clue was in F:)

I’ve finished testing now and want to thank you for your help in getting this going and for creating it.
It is superb! Now to start scanning and uploading a mountain of paperwork.

Here is my portable one-click program for anyone else that would like to run portably.

; File: Start_rest_uploader.au3 v1.0  2020-05-14
;
; Allows rest_uploader to be run from a shortcut portably
; i.e drive letter change is handled
; and env PATH is put back when finished

$iniFile       = "Start_rest_uploader.ini"
$drive         = StringLeft(@ScriptDir, 2)
$programPath   = $drive & IniRead($iniFile, "section", "programPath",   "")
$tesseractPath = $drive & IniRead($iniFile, "section", "tesseractPath", "")
$popplerPath   = $drive & IniRead($iniFile, "section", "popplerPath",   "")
$sourcePath    = $drive & IniRead($iniFile, "section", "sourcePath",    "")
$options       =          IniRead($iniFile, "section", "options",       "")

EnvSet( "PATH", EnvGet("PATH") & $popplerPath   & ';' _
                               & $tesseractPath & ';'  ) ; not needed?
Run            ( $programPath ) ; WinPython's cmd.bat
$winTitle      = "C:\WINDOWS\system32\cmd.exe"
WinWaitActive  ( $winTitle)
$arguments     = $sourcePath & ' ' & $options
Send           ( "rest_uploader.exe " & $arguments & "{Enter}" ) ; as though we typed it
WinWaitClose   ( $winTitle ) ; so Env PATH doesn't get put back as it was till we exit
Exit

; File: Start_rest_uploader.ini v1.0  2020-05-14
;
[Section]

programPath   = \Progs\WPy64-3770\scripts\cmd.bat
tesseractPath = \Progs\Tesseract-OCR
popplerPath   = \Progs\Poppler-0.68.0\bin
sourcePath    = \Temp\Scans
options       = --destination rest_uploaded --autotag no
2 Likes

Thanks, and I appreciate the feedback - glad you’re enjoying it!

Just as a point of clarification for portable WinPython users, if one looks in the file WPy64-3770\scripts\cmd.bat that I run you see it calls env_for_icons.bat which in turn calls env.bat which does all the Python related PATH additions for the duration of my run (and they get removed after, which is a requirement for portability)