86c10b9efab3f4e431b5f9278708c8ace1563faa — Jakob L. Kreuze 3 years ago b14c411
Implement 'post-article
1 files changed, 19 insertions(+), 1 deletions(-)

M brisket.hy
M brisket.hy => brisket.hy +19 -1
@@ 25,7 25,7 @@
(import [configparser [ConfigParser]])
(import [os [getcwd getenv makedirs]])
(import [os.path [dirname expanduser join]])
(import [sys [argv exit stderr]])
(import [sys [argv exit stderr stdin]])
(import [nntplib [NNTP-SSL]])
(import [subprocess [Popen PIPE]])

@@ 38,6 38,7 @@

(defn help [&rest args]

@@ 164,6 165,23 @@ usage: fetch-posts (group [optional]) (article-id [optional])"
          [group (fetch-group-articles session dest write-to-stdout group)]
          [True (fetch-all-articles session dest write-to-stdout)])))

(defn post-article [session &rest args]
  "Post an article to the server.

Reads from stdin if the path of a file is not specified.

usage: post-article [group] (path [optional])"
  (when (= (len args) 0)
    (err "usage: post-article [group] (path [optional])")
  (let [group (first args)
        path (if (> (len args) 1) (second args))]
    (.group session group)
    (if path
        (with [f (open path "rb")]
          (.post session))
        (.post session (list (map str.encode (.split (.read stdin) "\n")))))))

(defn make-config []
  "Create a default configuration file.