summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Sotoudeh <matthewsot@outlook.com>2021-02-08 13:18:36 -0800
committerMatthew Sotoudeh <matthewsot@outlook.com>2021-02-08 13:18:36 -0800
commit1cfe6c8e5b1a88cc40c8b884332f1e8e6bac9bc0 (patch)
tree318d932e8c9862e4790f474b9f873e111643940d
parent43c341f6165a7b5105ee28451efe7e26d4eb197b (diff)
Support printing PDFs from arXiv
-rw-r--r--printers/arxiv.rkt28
1 files changed, 28 insertions, 0 deletions
diff --git a/printers/arxiv.rkt b/printers/arxiv.rkt
new file mode 100644
index 0000000..ff15e58
--- /dev/null
+++ b/printers/arxiv.rkt
@@ -0,0 +1,28 @@
+#lang racket
+
+(require "../audrey3/feed-item.rkt"
+ net/url)
+(provide download-arxiv-pdf)
+
+(define (download-arxiv-pdf item)
+ (cond
+ [(is-arxiv? item)
+ (let* ([url (abs->pdf (feed-item->attr-value item "url"))]
+ [out-name "private/printed.pdf"]
+ [in-port (get-pure-port (string->url url))]
+ [out-file (open-output-file out-name #:exists 'truncate/replace)])
+ (write-bytes (port->bytes in-port) out-file)
+ (close-input-port in-port)
+ (close-output-port out-file)
+ #t)]
+ [else #f]))
+
+(define (is-arxiv? item)
+ (and (feed-item->has-attr? item "url")
+ (string-prefix? (feed-item->attr-value item "url")
+ "http://arxiv.org/abs/")))
+
+(define (abs->pdf url)
+ (string-append
+ (string-replace url "http://arxiv.org/abs/" "https://arxiv.org/pdf/")
+ ".pdf"))
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback