summaryrefslogtreecommitdiffstats
path: root/mb
blob: e7b5371d253f336e45f5a5c6b4f250644247a122 (plain)
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
#!/usr/bin/env hy3
(import [datetime [datetime]]
        time
        [os.path [realpath]]
        [os [chmod]]
        [tempfile [NamedTemporaryFile :as mktemp]]
        [subprocess [call :as unixcmd]])

(defn mb-datestring  []
  (.strftime (datetime.fromtimestamp (time.time)) "%Y-%m-%d %H:%M"))

(defn mb-titlestring [words]
  (stringify-wordlist (take 5 words) " "))

(defn mb-namestring [words date]
  (setv first-five-words  (take 5 words))
  (.replace (+ "micro-post-" date) " " "-"))

(defn mb-content [title date text]
  (stringify-wordlist  ["Title: " title "\n"
               "date: " date "\n" 
               "Category: notes\n\n" text "\n"] ""))

(defn stringify-wordlist [wlist delim]
  (reduce (fn [a b] (+ a delim b)) wlist))

(defmain [&rest args]
  (setv mb-words (list (drop 1 args))
        mb-text (stringify-wordlist mb-words " ")
        mb-date (mb-datestring)
        mb-title (.format "microblog {}" mb-date)
        mb-filename (mb-namestring mb-words mb-date))
  (with [mb-file (mktemp :mode "w" )]
    (.write  mb-file (mb-content mb-title mb-date mb-text))
    (.flush mb-file)
    (chmod (. mb-file name) 0o666)
    (unixcmd ["scp" (. mb-file name) (.format "www:/pconch/posts/{}.post" mb-filename)])))