diff options
| author | Jakob L. Kreuze <zerodaysfordays@sdf.lonestar.org> | 2019-04-27 15:41:06 -0400 |
|---|---|---|
| committer | Jakob L. Kreuze <zerodaysfordays@sdf.lonestar.org> | 2019-04-27 15:41:06 -0400 |
| commit | 86c10b9efab3f4e431b5f9278708c8ace1563faa (patch) | |
| tree | 41d8b2ce3cb711a3e4800977811bc9c98b81e3f7 | |
| parent | b14c411be70fb910f16807e83ef66201e636a1b6 (diff) | |
Implement 'post-article
| -rw-r--r-- | brisket.hy | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -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 @@ "fetch-posts" "list-groups" "list-posts" + "post-article" "version"]) (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])") + (return)) + (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. |