I want to use org-capture-templates to scrape french verb conjugations from the web and insert them into an org-file to use with org-drill.
I have a (functioning) scraper that gets the desired data from www.verbix.com and prints out the preformatted conjugations like so:
** Indicatif *** Present | je ... | tu ...| | .... | ... |
I would like to call this python script from my capture using
Here is my lisp function:
(defun my-french-verb-template () "Capture template for French verbs" (let* ((arg (org-completing-read-no-i "Verb: " nil)) (conjugations (shell-command (concat "python2 ~/Nextcloud/05Code/python/verbix_scraper.py " arg)))) (format "** Verb: %s :drill:\n :PROPERTIES:\n :DRILL_CARD_TYPE: french_verb\n :END:\n*** Infinitive\n %s\n%s\n" arg arg conjugations)))
and my capture template:
("f" "French verb" entry (file+headline "~/Nextcloud/org-mode/brain/french.org" "Verb") (function my-french-verb-template))
(shell-command (concat "python2 ~/Nextcloud/05Code/python/verbix_scraper.py " arg))
from a scratch buffer prints out the desired output in a new minibuffer. However, calling org-capture-template will only print 0.
I think the problem is that shell-command will use a minibuffer to output the result from the shell command. How can I insert the result in the capture buffer?
Calling shell-command with
(current-buffer) will replace whatever buffer I am in when I call the capture-template.
Any ideas? The documentation is not helping so far.
I have also tried redirecting the result from shell-command to 'CAPTURE-french.org', but then my capture buffer will be renamed to 'CAPTURE-2-french.org'.
So I can think of two possibilities:
1) Delay the evaluation of
(shell-command ...) until the capture buffer has been created.
2) Specify a (scratch) output buffer to catch the text from
(shell-command ...) and then bind the buffer content to a variable which I insert in the capture buffer.
But I cannot think of a way to do this in emacs...
lawlist's solution worked for me: using
shell-command-to-string works pretty flawlessly for me and I now have a working capture which lets me type in a french verb as infinitive and then scrapes conjugations from the web and inserts them into my french-vocab.org file.
#STARTUP: align takes care of table formatting. SAWEEEET!