Permalink
Browse files

Added hackernews.submitted.xml datatable based on hackernews.frontpag…

…e.xml
  • Loading branch information...
1 parent 6d3ebc7 commit a736fdc03dc04986b47dd58e265a2da4acf803bd @scotu scotu committed Apr 10, 2011
Showing with 61 additions and 0 deletions.
  1. +61 −0 hackernews/hackernews.submitted.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
+ <meta>
+ <sampleQuery>select * from {table} where username = 'hn_username';</sampleQuery>
+ <author>Matteo Scotuzzi (@scotu, matteo.scotuzzi@gmail.com), based on hackernews.frontpage.xml Tom Hughes-Croucher (@sh1mmer, croucher@yahoo-inc.com)</author>
+ </meta>
+ <bindings>
+ <select itemPath="stories.story" produces="XML">
+ <urls>
+ <url>http://news.ycombinator.com/submitted</url>
+ </urls>
+ <inputs>
+ <key id='username' type='xs:string' paramType='variable' required="true" />
+ </inputs>
+ <execute><![CDATA[
+ url = "http://news.ycombinator.com/submitted?id="+username;
+ page = y.query("select * from html where url='" + url + "'").results;
+ table = page..table[2];
+ rows = table..tr;
+
+ output = <stories></stories>
+ if(rows){
+ /*
+ * iterate three TRs at a time
+ * each triplet represents one story
+ * i is the title row, i+1 is the meta info, i+2 is a spacer
+ */
+ for(var i=0;i<90;i=i+3) {
+ titleRow = rows[i]
+ metaRow = rows[i+1]
+ if(titleRow == undefined || metaRow == undefined){break;}
+ title = titleRow..td[2].a;
+ url = titleRow..td[2].a.@href;
+ submitter = metaRow..a[0]
+
+ score = /^\d+/.exec(metaRow..span[0].toString())[0]
+
+ comments = /^\d+/.exec(metaRow..a[1].toString())
+ if(comments) {
+ comments = comments[0]
+ } else {
+ comments = 0;
+ }
+
+ id = /\d+$/.exec(metaRow..a[1].@href.toString())[0]
+
+ story = <story></story>
+ story.id = id;
+ story.title = title.toString();
+ story.url = url;
+ story.submitter = submitter.toString();
+ story.score = score;
+ story.comments = comments;
+ output.stories += story;
+ }
+ }
+ response.object = output;
+ ]]></execute>
+ </select>
+ </bindings>
+</table>

0 comments on commit a736fdc

Please sign in to comment.