Created
December 12, 2017 22:10
-
-
Save elfsternberg/0ba6e5e1babd36cb1d5fb7c9d6ade3c8 to your computer and use it in GitHub Desktop.
Given a URL and an optional list of tags, write an Emacs ORG-mode bookmark and associated content to a bookmark repository.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env hy | |
; This script requires `pip install slugify newspaper`. It runs on Hy 0.12 and Python 3.5. | |
; This is part of an (incomplete) xinetd-driven toolchain for managing local bookmarks. | |
(import sys os os.path [slugify [slugify]] [newspaper [Article]]) | |
(def bookmark-index | |
(os.path.join (get os.environ "HOME") "Wiki" "Bookmarks" "Bookmarks.org")) | |
(def bookmark-folder | |
(os.path.join (get os.environ "HOME") "Wiki" "Bookmarks" "Bookmarks")) | |
(defn fetch-article [url] | |
(let [article (Article url)] | |
(.download article) | |
(.parse article) | |
article)) | |
(defmain [&rest args] | |
(if (< (len args) 2) | |
(do | |
(print "Must supply a URL!") | |
(sys.exit 1))) | |
(let [tags (if (= (len args) 2) [] (cut args 2)) | |
article (fetch-article (get args 1)) | |
newfilename (+ (slugify (. article title)) ".org")] | |
(with [hndl (open bookmark-index "a")] | |
(if (len tags) | |
(.write hndl (.format "** [[file:./Bookmarks/{}][{}]] :{}:\n\n" newfilename (. article title) (.join ":" tags))) | |
(.write hndl (.format "** [[file:./Bookmarks/{}][{}]]\n\n" newfilename (. article title))))) | |
(with [hndl (open (os.path.join bookmark-folder newfilename) "w")] | |
(.write hndl (. article text))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment