- Smart Personal Cloud

Build Your Own 'Show HN' Digest and Tools

1

If you are not fully satisfied with the Hacker News interface and tools. MyEzApp provides you HackerNews API, so you can create your own tools easily.

HackerNews API allows you to retrieve Hacker News' top stories and latest news. Combined with other APIs such as Task Scheduling API, which allows you to schedule periodic tasks and Email/Phone API which allows you to send notifications. You can build powerful tools that monitor hacker news, filter stories, and send you hourly/daily news digest. With MyEzApp, you can do all of these without any software download, dev environment setup, server procurement and monitoring. It's easy and fun!

This tutorial will show you three example use cases. The source code of the examples can be installed through the application marketplace.

2

If you want to receive an hourly notification on all the 'Show HN' stories. Below is an example. Please replace the variable 'myemail' with your real email address.

// please name this script showhn_digest.ws, we need the name when scheduling hourly task. use /api/hackernews use /api/mail var myemail = "user1@example.com" var news = hackernews.getNewest()                              // get hacker news top story var msg = "" for i = 1 to news.length                                       // iterate through hacker news stories   var n = news[i]   if not n.title.startsWith("Show HN:") or not n.time.contains("minute") then      continue    end      msg = msg + genStory(n) next if msg <> "" then                                              // empty content? don't send the email   mail.notify(myemail, "Show HN Digest", msg) end func genStory(s as hackernews.story) as string   var u = s.url    if u.startsWith("item?id=") then u = "http://news.ycombinator.com/" + u end   return     <div>       <a style="font-weight:bold;" href=("http://news.ycombinator.com/item?id="+s.item_id)>Discuss</a>       <a href=u>s.title</a>     </div> end

You will need to create a scheduled task to trigger the above script every hour. Below is the scheduling code. Notice in the scheduling code, the string "showhn_diguest" needs to match the name of the previous script. If you want to stop a scheduling task. You can use the Tasks tab.

use /sys/task task.scheduleHourly("hndemo", "example1", "showhn_digest", 0)                   // schedule task
3

You can create a simple Hacker News UI in less than 40 lines of code. Below is the source code of the example. You can try it out live here.

use /comp/ezpage use /comp/tabs use /comp/dtable use /api/hackernews use /web/http <ezpage>  <tabs>   <tab title="Top Story">    <newstable news=hackernews.getTopStory()/>   </tab>   <tab title="Latest Story">    <newstable news=hackernews.getNewest()/>   </tab>  </tabs> </ezpage> func newstable(news as hackernews.story[])  <dtable displayLength="100">   <thead>     <tr><th></th><th>Title</th><th>User</th><th>Score</th><th>Time</th><th>Comment</th><th>History</th></tr>   </thead>   for i = 1 to news.length    var n = news[i]    <tr>     <td>i</td>     <td>      var url = n.url      if url.startsWith("item?") then url = "http://news.ycombinator.com/" + n.url end      <a class='wsa' href=url/>http.escapeHtml(n.title)</a>     </td>     <td><a class='wsa' href=("http://news.ycombinator.com/user?id="+n.user)>n.user</a></td>     <td>n.score</td>     <td>n.time</td>     <td><a class='wsa' href=("http://news.ycombinator.com/item?id="+n.item_id)>n.comments</a></td>     <td><a class='wsa' href=("item_history.ws?item_id="+n.item_id)>View</a></td>    </tr>   next  </dtable> end

Below is the screenshot of the simple UI.

The simple UI includes a URL reference to the page called 'item_history.ws', which is another script that displays the ranking history of a hackernews post. If you click the 'History->View' link you can further drill down to the history page.

Example 2 is just a starting point. The spirit of MyEzApp is Do It Yourself. You are encouraged to enhance/customize it to make it your own.

4

'Show HN' stories that makes to the Hacker News homepage deserve a little more publicity. Let's automatically post them to Blogger. Plus, if you are away or getting lazy for a few days, it's easier for you to catch up.

This example is more complex and feature rich. It shows you how to capture screen shots and grant permissions on the myezapp.com service.

Note: before running the script, please replace variables in the credentials section with your real blogger credential.

use /api/hackernews use /api/blogger use /api/webshot use /util/url use /web/http /////////////////////// credentials ////////////////////////////// var bloggeruser = "username" var bloggerpwd = "password" var blogname = "blogname" /////////////////////// batch logic ////////////////////////////// var news = hackernews.getNewest()                              // get hacker news top story var c = blogger.newClient(bloggeruser, bloggerpwd, blogname)     // create blogger client var p = c.getPostSince(system.currentTime() - 7*24*3600*1000)      // load posts in the last week for i = 1 to news.length                                         // iterate through all hacker news story   var n = news[i]   if not n.title.startsWith("Show HN:") then continue end        // skip none Show HN items   var shouldPost = true   for j = 1 to p.length                                          // de-dup, don't post the same thing twice     if p[j].title.trim() == n.title.trim() then        shouldPost = false        break     end   next   var shouldCapture = not n.url.startsWith("item?id=")   if shouldPost then     if shouldCapture then       webshot.take(n.url, "pics/"+getImageName(n)) // take screen shot of page     end     var nil = c.post(n.title, genPost(n, shouldCapture))          // publish the page to blogger   end next func getImageName(s as hackernews.story) as string   return url.parse(s.url).host+".png" end func getImageUrl(s as hackernews.story) as string   return http.toUrl("pics/")+ getImageName(s) end func genPost(s as hackernews.story, capture as bool) as string   return      <div>       if capture then         <a href=getImageUrl(s)>           <img border="0" height="171" src=getImageUrl(s) width="320" />         </a><br/>       end       <a href=("http://news.ycombinator.com/item?id="+s.item_id)><span>Discuss</span></a>     </div> end

If you want to run the script periodically, you will need to call the below script to schedule the task.

use /sys/task task.scheduleHourly("hndemo", "example3", "hn2blogger", 0)                               // schedule task     
5

With the Hacker News API, you can build your own custom tools around the Hacker News content. If you need any additional API functions, please feel free to contact us.

All of the above examples can be installed from the application marketplace. The applications you installed are immediately usable. However, they are not necessarily the final application you will use. You are encouraged to tinker and tweek with the applications to make it exactly what you want.

MyEzApp.com provides services and tools for you to build web applications. With MyEzApp service, you don't need to worry about downloading software, setup your dev environment, or setup/monitoring your own servers. MyEzApp.com provides you a fully integrated environment for developing and runing your own web applications online. Just login to your account and create your script. It is ready to go!