From 40eb75bbcf0c0ee7f0432b455fa0b3590059b522 Mon Sep 17 00:00:00 2001 From: Thanh Vuong Date: Sat, 17 Aug 2019 09:41:46 -0600 Subject: wip --- .gitignore | 11 + Cask | 10 + TODOs.org | 8 + hnreader.el | 78 ++++ test/frontpage.html | 1057 +++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1164 insertions(+) create mode 100644 .gitignore create mode 100644 Cask create mode 100644 TODOs.org create mode 100644 hnreader.el create mode 100644 test/frontpage.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..206569d --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# Compiled +*.elc + +# Packaging +.cask + +# Backup files +*~ + +# Undo-tree save-files +*.~undo-tree diff --git a/Cask b/Cask new file mode 100644 index 0000000..a96ccfe --- /dev/null +++ b/Cask @@ -0,0 +1,10 @@ +(source gnu) +(source melpa) + +;; (package-file "TODO") + +(development + (depends-on "f") + (depends-on "ecukes") + (depends-on "ert-runner") + (depends-on "el-mock")) diff --git a/TODOs.org b/TODOs.org new file mode 100644 index 0000000..491f55e --- /dev/null +++ b/TODOs.org @@ -0,0 +1,8 @@ +#+STARTUP: align fold hidestars oddeven indent +#+SEQ_TODO: TODO(t) INPROGRESS(i) | DONE(d) CANCELED(c) +* why not using hn api +hn api will invole a lot of rest requests which would not be fast for emacs +also the data layout is already available at hn webiste, one curl call and +then parse them to org would be faster +* parse front page +now what diff --git a/hnreader.el b/hnreader.el new file mode 100644 index 0000000..091fa21 --- /dev/null +++ b/hnreader.el @@ -0,0 +1,78 @@ +(require 'request) +(require 'shr) +(require 'dom) +(require 'promise) +(require 'cl-lib) + + +(defvar hn--buffer "*HN*" + "Buffer for HN pages.") + +(defun hnreader--get-hn-buffer () + "Get hn buffer." + (get-buffer-create hn--buffer)) + +(defun hnreader--promise-dom (url) + "Promise (url . dom) from URL with curl." + (promise-new + (lambda (resolve reject) + (request url + :parser (lambda () (libxml-parse-html-region (point-min) (point-max))) + :error (cl-function (lambda (&rest args &key error-thrown &allow-other-keys) + (message "bad") + (funcall reject error-thrown))) + :success (cl-function (lambda (&key data &allow-other-keys) + (message "yay") + (setq thanh data) + ;; (message "%s" data) + (funcall resolve data))))))) + +(defun hnreader--prepare-buffer (buf &optional msg) + "Print MSG message and prepare window for BUF buffer." + (when (not (equal (window-buffer) buf)) + ;; (switch-to-buffer-other-window howdoi-buffer)) + (display-buffer buf '(display-buffer-use-some-window (inhibit-same-window . t)))) + (with-current-buffer buf + (read-only-mode -1) + (erase-buffer) + (insert (if msg + msg + "Loading..."))) + buf) + +(defun hnreader--print-frontpage-item (thing subtext) + "Print THING dom and SUBTEXT dom." + (insert (format "\n* %s %s (%s) [%s]\n" + ;; rank + (dom-text (dom-by-class thing "^rank$")) + ;; title + (dom-text (dom-by-class thing "^storylink$")) + ;; points + (dom-text (dom-by-class subtext "^score$")) + ;; comments + (dom-text (last (dom-children subtext))))) + ;; link + (insert (dom-attr (dom-by-class thing "^storylink$") 'href) "\n" ) + ;; comment link + (insert "https://news.ycombinator.com/item?id=" (dom-attr thing 'id))) + +(defun hnreader--print-frontpage (dom buf) + "Print raw DOM on BUF." + (message "am i here") + (let ((things (dom-by-class dom "^athing$")) + (subtexts (dom-by-class dom "^subtext$"))) + (with-current-buffer buf + (read-only-mode -1) + (erase-buffer) + (insert "#+STARTUP: overview indent\n#") + (cl-mapcar #'hnreader--print-frontpage-item things subtexts)))) + +(defun hnreader-frontpage () + "Testing." + (hnreader--prepare-buffer (hnreader--get-hn-buffer)) + (promise-chain (hnreader--promise-dom "https://news.ycombinator.com/news") + (then (lambda (result) + (message "got the dom") + (hnreader--print-frontpage result (hnreader--get-hn-buffer)))) + (promise-catch (lambda (reason) + (message "catch error in promise prontpage: %s" reason))))) diff --git a/test/frontpage.html b/test/frontpage.html new file mode 100644 index 0000000..e7e469f --- /dev/null +++ b/test/frontpage.html @@ -0,0 +1,1057 @@ + + + + + + + + + + Hacker News + + + +
+ + + + + + + + + + + + + +
+ + + + + + + + +
Hacker + News + new | past | comments + | ask | show | jobs | submit + + login +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
1. + + The most frequent 777 characters give + 90% coverage of Kanji in the wild + + (japanesecomplete.com) +
+ 97 points by + sova + + + 2 + hours ago + + + + | + hide + + | + + 47 comments + +
2.NOAA Data Confirms July Was Hottest + Month Ever Recorded (nytimes.com)
+ 113 points by + digital55 3 + hours ago | + hide + | 37 comments +
3.Alone in the Dark (filfre.net)
+ 33 points by + myth_drannon 2 + hours ago | + hide + | 6 comments +
4.Async-std: an async port of the Rust + standard library (async.rs)
+ 235 points by + JoshTriplett 9 + hours ago | + hide + | 169 comments +
5.Japan surpasses China as largest foreign + holder of US Treasurys + (cnbc.com)
+ 141 points by + hker 8 + hours ago | + hide + | 52 comments +
6.Free and open-source tools for analog + filmmaking (sixteenmillimeter.com) +
+ 45 points by + nessunodoro 4 + hours ago | + hide + | 3 comments +
7.Effortless Elixir Releases and + Deployment (alchemist.camp)
+ 41 points by + AlchemistCamp 3 + hours ago | + hide + | 6 comments +
8.Nixery: Transparently build and serve + containers using Nix (github.com)
+ 74 points by + kimburgess 5 + hours ago | + hide + | 12 comments +
9.Google Plans to Deprecate FTP URL + Support in Chrome (pulltech.net)
+ 78 points by + github-cat 3 + hours ago | + hide + | 89 comments +
10.I've reproduced 130 research papers + about “predicting the stock market” (reddit.com)
+ 337 points by + starpilot 7 + hours ago | + hide + | 112 comments +
11.Making email more modern with + JMAP (fastmail.blog)
+ 61 points by + mfsch 6 + hours ago | + hide + | 20 comments +
12.Key Negotiation of Bluetooth + Attack (knobattack.com)
+ 275 points by + Daviey 15 + hours ago | + hide + | 91 comments +
13.Exploring DNA with Deep + Learning (floydhub.com)
+ 91 points by + ReDeiPirati 9 + hours ago | + hide + | 11 comments +
14.Launch HN: SannTek (YC S19) – + Breathalyzer for Cannabis
+ 184 points by + Noah_SannTek 12 + hours ago | + hide + | 357 comments +
15.VMware Octant web-based platform to + better understand Kubernetes clusters (github.com)
+ 18 points by + nwrk 4 + hours ago | + hide + | 3 comments +
16.U.S. Farmers Stung by Tariffs Now Face a + $3.5B Corn Loss (bloomberg.com)
+ 198 points by + paulpauper 6 + hours ago | + hide + | 106 comments +
17.O Oberlin, My Oberlin (commentarymagazine.com) +
+ 44 points by + jseliger 7 + hours ago | + hide + | 12 comments +
18.Arcs of Seniority (stevanpopovic.com) +
+ 40 points by + zdw 7 + hours ago | + hide + | 19 comments +
19.Japanese anime studio Khara moving to + Blender (blender.org)
+ 788 points by + robin_reala 20 + hours ago | + hide + | 193 comments +
20.The Biggest Mistakes First-Time Founders + Make [video] (ycombinator.com) +
+ 56 points by + chrisa 11 + hours ago | + hide + | 2 comments +
21.Highlights from Git 2.23 (github.blog)
+ 90 points by + digitalnalogika 7 + hours ago | + hide + | 12 comments +
22.ECONcrete: Protection + from hydrodynamic forces while generating marine + habitat (econcretetech.com) +
+ 4 points by + driekwartappel 2 + hours ago | + hide + | 1 comment +
23.All Tridactyl installations might get + removed by Firefox on Aug 21 (github.com)
+ 90 points by + anoopelias 12 + hours ago | + hide + | 75 comments +
24.The Population Bust (foreignaffairs.com) +
+ 60 points by + ohaikbai 13 + hours ago | + hide + | 114 comments +
25.Show HN: Prophecy.io – Cloud Native Data + Engineering (medium.com)
+ 47 points by + ibains 9 + hours ago | + hide + | 20 comments +
26.Trauma Counselors Pressured to Divulge + Confidential Info About Facebook Mods (theintercept.com) +
+ 88 points by + jmsflknr 10 + hours ago | + hide + | 28 comments +
27.The subversive messages hidden in The + Wizard of Oz (bbc.com)
+ 122 points by + herendin2 13 + hours ago | + hide + | 98 comments +
28.Big Coal Plants Begin to Close (scientificamerican.com) +
+ 253 points by + artsandsci 12 + hours ago | + hide + | 145 comments +
29.A new clothing line confuses automated + license plate readers + (technologyreview.com) +
+ 14 points by + t23 2 + hours ago | + hide + | 1 comment +
30.The FCC Fined 'Jimmy Kimmel Live' 'The + Walking Dead' for Use of Emergency Tones (cnn.com)
+ 79 points by + LinuxBender 11 + hours ago | + hide + | 52 comments +
+
+ + + + + + +

+
Guidelines + | FAQ + | Support + | API + | Security + | Lists + | Bookmarklet + | Legal + | Apply to YC + | Contact

+
Search: + +
+
+
+
+ + + +
+ + -- cgit v1.2.3