-
Notifications
You must be signed in to change notification settings - Fork 0
/
html_bookmark_gen.lisp
executable file
·86 lines (68 loc) · 2.71 KB
/
html_bookmark_gen.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/local/bin/sbcl --script
;;; format of arguments: filename, output name
;; example call:
;; ./html_bookmark_gen.lisp ~/bookmarks.txt ./landed
;; progress so far:
;; can read in the text file
;; can list all links / put them into a data structure
;; need to be able to name the output textfile
;; need to write things out to a text file
;; signal an error if there is a file with that name already
;; will restoring bookmarks overwrite existing ones? NOPE just adds a new bkmk
;; to do
;; make sure this isn't an HTML parsing task--it's not!
;; format my output !biggest task
;; clean up code, document it
(format t "hi ~%")
;; first arg is always the location of the sbcl process
(format t "~s~%" (second *posix-argv*))
(format t "~s~%" (third *posix-argv*))
(defparameter *in* (second *posix-argv*))
(defparameter *out* (third *posix-argv*))
(defparameter *list-of-links* '())
(defun spit-out (line)
(format t "~a~%" line))
(defun add-tags (a-link)
;; format goal, (it's one line):
;; <DT><A HREF="https://www.reddit.com/r/EatCheapAndHealthy" ADD_DATE="1451909662" LAST_MODIFIED="1451909662">https://www.reddit.com/r/EatCheapAndHealthy</A>
(add-<dt> (add-<a> a-link)))
(defun add-<A> (a-link &key href add-date last-modified icon-uri)
(concatenate 'string "<A HREF=" a-link ">" a-link "</A>"))
(add-<a> "https://www.reddit.com/r/EatCheapAndHealthy")
(defun add-<DT> (a-string)
(concatenate 'string "<DT>" a-string))
(add-<dt> (add-<a> "https://www.reddit.com/r/EatCheapAndHealthy"))
(defun add-new-line (a-string)
(concatenate 'string a-string "
"))
;; function is not used nor necessary
(defun wrap-<DL> (a-string)
(concatenate 'string "<DL>
" a-string "
</DL>"))
(wrap-<dl>
(add-<dt> (add-<a> "https://www.reddit.com/r/EatCheapAndHealthy")))
(defun create-header ()
(format nil "<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!-- This is an automatically generated file
using a common lisp utility program.
It will be read and overwritten.
DO NOT EDIT! -->
<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">"))
(create-header)
(with-open-file (in *in* :if-does-not-exist nil)
(if in
(with-open-file (out *out* :direction :output :if-exists nil)
(if out
(progn
(write-line (create-header) out)
(loop for link = (read-line in nil)
while link do (write-line (add-tags link) out)))
(format t "~%Error! Output filename already exists~%")))
(format t "~%Error! Input file not found!~%")))
;; tag legend
;; <HR> is for horizontal bar
;; <DL> is directory list, NEEDS closing </DL>
;; <p> always follows <DL>
;; <DT> defines a tab/row item that you can select
;; <DD> only one case of this : <DD>Add bookmarks to this folder to see them displayed on the Bookmarks Toolbar