[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/xkcd d890179cde 09/82: Add xkcd-download
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/xkcd d890179cde 09/82: Add xkcd-download |
Date: |
Mon, 12 Dec 2022 21:59:49 -0500 (EST) |
branch: elpa/xkcd
commit d890179cde85431fee63a715c03df965f3e89be4
Author: Vibhav Pant <vibhavp@cthulhu-p5kpl.lan>
Commit: Vibhav Pant <vibhavp@cthulhu-p5kpl.lan>
Add xkcd-download
---
emacs-xkcd.el | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/emacs-xkcd.el b/emacs-xkcd.el
index aff133cf1f..f491124322 100644
--- a/emacs-xkcd.el
+++ b/emacs-xkcd.el
@@ -47,11 +47,19 @@
(let ((buffer (url-retrieve-synchronously url))
(json nil))
(with-current-buffer buffer
+ (goto-char (point-min))
(re-search-forward "^$")
(setq json (buffer-substring-no-properties (+ (point) 1) (point-max)))
(kill-buffer (current-buffer)))
json))
+(defun xkcd-download (url num)
+ "Download the image linked by URL. If the file arleady exists, do nothing"
+ (let ((name (concat xkcd-cache (number-to-string num) ".png")))
+ (if (file-exists-p name)
+ nil
+ (url-copy-file url name))))
+
(defun xkcd-get (num)
"Get the xkcd number NUM"
(interactive "nEnter comic number: ")
@@ -66,17 +74,16 @@
(let ((out (if (eq num nil)
(xkcd-get-json "http://xkcd.com/info.0.json")
(xkcd-get-json (concat "http://xkcd.com/" (number-to-string num)
- "/info.0.json"))))
+ "/info.0.json"))))
(img nil)
(num nil)
(title nil))
- (setq num (number-to-string (cdr (assoc 'num (json-read-from-string
out)))))
+ (setq num (cdr (assoc 'num (json-read-from-string out))))
(setq img (cdr (assoc 'img (json-read-from-string out))))
;; FIXME: This looks pretty ugly.
(message "Downloading comic...")
- (with-temp-buffer (shell-command
- (concat "wget " "-O " xkcd-cache num ".png " "'" img
"'") t))
+ (xkcd-download img num)
(setq title (format "%d: %s" (cdr (assoc 'num (json-read-from-string out)))
(cdr (assoc 'safe_title (json-read-from-string out)))))
(insert (concat title "\n"))
- [nongnu] branch elpa/xkcd created (now 80011da2e7), ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 51bf8b0d49 05/82: Rename functions, make json retrieving function smaller., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd fcedf74f71 01/82: Initial commit, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 620f3417cf 08/82: Update README.md, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd d890179cde 09/82: Add xkcd-download,
ELPA Syncer <=
- [nongnu] elpa/xkcd add1413ee9 11/82: Correct typo in readme., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd c816cfa893 12/82: Add caching and offline support., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 736b1c9abf 02/82: Initial commit, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 0f1abaebf5 14/82: typo: keybinding is t not r, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd f7b5157cdd 03/82: * README.md: Fix directory path, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 7ceb6cfb46 04/82: Update README.md, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 3acd31542b 06/82: Fix up search in xkcd-get-json. Add new line to README.md., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 3a1d89e234 07/82: Add screenshot, ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd ef2ae149e6 10/82: Add TODO to docs., ELPA Syncer, 2022/12/12
- [nongnu] elpa/xkcd 637f3d546e 15/82: Merge pull request #1 from oylenshpeegul/patch-1, ELPA Syncer, 2022/12/12