Created
December 14, 2015 20:41
-
-
Save sanryuu/776ef48e1c1961678e4d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; package --- | |
;;; Commentary: | |
;;; Code: | |
(require 'json) | |
(require 'qiita) | |
(require 'package) | |
(setq inhibit-startup-message t) | |
(package-initialize) | |
(setq qiita->token "c06d5534aaad880a45cd8c530098e7751cb2cabc") | |
(setq response-emacs (qiita:api-tag-items "emacs")) | |
(defun tips-insert-qiita-item (qiita-item-list) | |
(mapcar | |
'(lambda (x) | |
(insert | |
(concat | |
(plist-get x :stock) | |
"[[" | |
(plist-get x :url) | |
"][" | |
(plist-get x :title) | |
"]]" | |
"\n"))) | |
qiita-item-list)) | |
(defun url-http-get (url args) | |
"Send ARGS to URL as a GET request." | |
(let ( | |
(response-string nil) | |
(url-request-method "GET") | |
(url-request-data | |
(mapconcat (lambda (arg) | |
(concat (url-hexify-string (car arg)) | |
"=" | |
(url-hexify-string (cdr arg)))) | |
args | |
"&"))) | |
(switch-to-buffer | |
(url-retrieve-synchronously | |
(concat url "?" url-request-data))) | |
(goto-char (point-min)) | |
(re-search-forward "\n\n") | |
(setq response-string | |
(buffer-substring-no-properties | |
(point) (point-max))) | |
(kill-buffer (current-buffer)) | |
response-string)) | |
(setq loading-tips-melpa-dl-url "http://melpa.org/download_counts.json") | |
(setq loading-tips-melpa-archive-url "http://melpa.org/archive.json") | |
(defun tips-get-desc (package-name archive-data) | |
(cdr | |
(assoc 'desc | |
(cdr (cdr (assoc package-name archive-data)))))) | |
(setq tips-boder 30000) | |
(defun tips-filter (tips-boder download-number-set) | |
(let (filtered-set) | |
(mapcar | |
'(lambda (n) | |
(if (> (cdr n) tips-boder) | |
(add-to-list 'filtered-set n) | |
)) | |
download-number-set) | |
filtered-set)) | |
(defun tips-choice-package (tips-choice-num download-set) | |
(let ((loop-count 0) | |
(tips-display-list ()) | |
(random-item)) | |
(while (< loop-count tips-choice-num) | |
(setq loop-count (1+ loop-count)) | |
(setq random-item (nth (random (length download-set)) download-set)) | |
(add-to-list | |
'tips-display-list | |
random-item) | |
(setq download-set (delete random-item download-set))) | |
tips-display-list)) | |
(defun tips-create-desc-set (download-set archive-data) | |
(let (package-desc-set) | |
(mapcar '(lambda (n) | |
(add-to-list | |
'package-desc-set | |
(cons | |
(car n) | |
(tips-get-desc (car n) archive-data)))) | |
download-set) | |
package-desc-set)) | |
(setq tips-choice-num 10) | |
(defun tips-insert-package-info-part (name-desc-set) | |
(mapcar | |
'(lambda (n) | |
(insert | |
(concat "- " | |
(symbol-name (car n)) | |
": " | |
(cdr n) | |
"\n"))) | |
name-desc-set)) | |
(defun tips-insert-package-info () | |
(let ((tips-melpa-download-data | |
(json-read-from-string | |
(url-http-get loading-tips-melpa-dl-url ""))) | |
(tips-melpa-archive-data | |
(json-read-from-string | |
(url-http-get loading-tips-melpa-archive-url ""))) | |
filtered-download-data | |
choiced-package | |
package-set | |
name-desc-set) | |
(setq filtered-download-data | |
(tips-filter tips-boder tips-melpa-download-data)) | |
(setq choiced-package | |
(tips-choice-package tips-choice-num filtered-download-data)) | |
(setq name-desc-set | |
(tips-create-desc-set choiced-package tips-melpa-archive-data)) | |
(tips-insert-package-info-part name-desc-set))) | |
(defun tips-init () | |
(interactive) | |
(switch-to-buffer (get-buffer-create "*tips*")) | |
(org-mode) | |
(tips-insert-qiita-item (qiita:api-tag-items "emacs")) | |
(tips-insert-package-info)) | |
(provide 'tips) | |
;;; tips.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment