Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 6422e6abef3c5f29873a1cacad708d5b919b2f98 get committed Mar 14, 2013
Showing with 13,468 additions and 0 deletions.
  1. +34 −0 README.md
  2. +1 −0 cmd.bat
  3. +130 −0 myrss.js
  4. +6 −0 node_modules/xml2js/.npmignore
  5. +5 −0 node_modules/xml2js/.travis.yml
  6. +19 −0 node_modules/xml2js/LICENSE
  7. +239 −0 node_modules/xml2js/README.md
  8. +283 −0 node_modules/xml2js/lib/xml2js.js
  9. +10 −0 node_modules/xml2js/node_modules/sax/AUTHORS
  10. +23 −0 node_modules/xml2js/node_modules/sax/LICENSE
  11. +216 −0 node_modules/xml2js/node_modules/sax/README.md
  12. +8,002 −0 node_modules/xml2js/node_modules/sax/examples/big-not-pretty.xml
  13. +41 −0 node_modules/xml2js/node_modules/sax/examples/example.js
  14. +58 −0 node_modules/xml2js/node_modules/sax/examples/get-products.js
  15. +4 −0 node_modules/xml2js/node_modules/sax/examples/hello-world.js
  16. +8 −0 node_modules/xml2js/node_modules/sax/examples/not-pretty.xml
  17. +74 −0 node_modules/xml2js/node_modules/sax/examples/pretty-print.js
  18. +2 −0 node_modules/xml2js/node_modules/sax/examples/shopping.xml
  19. +870 −0 node_modules/xml2js/node_modules/sax/examples/strict.dtd
  20. +45 −0 node_modules/xml2js/node_modules/sax/examples/switch-bench.js
  21. +15 −0 node_modules/xml2js/node_modules/sax/examples/test.html
  22. +1,254 −0 node_modules/xml2js/node_modules/sax/examples/test.xml
  23. +1,016 −0 node_modules/xml2js/node_modules/sax/lib/sax.js
  24. +64 −0 node_modules/xml2js/node_modules/sax/package.json
  25. +25 −0 node_modules/xml2js/node_modules/sax/test/buffer-overrun.js
  26. +47 −0 node_modules/xml2js/node_modules/sax/test/case.js
  27. +11 −0 node_modules/xml2js/node_modules/sax/test/cdata-chunked.js
  28. +15 −0 node_modules/xml2js/node_modules/sax/test/cdata-end-split.js
  29. +28 −0 node_modules/xml2js/node_modules/sax/test/cdata-fake-end.js
  30. +15 −0 node_modules/xml2js/node_modules/sax/test/cdata-multiple.js
  31. +10 −0 node_modules/xml2js/node_modules/sax/test/cdata.js
  32. +86 −0 node_modules/xml2js/node_modules/sax/test/index.js
  33. +43 −0 node_modules/xml2js/node_modules/sax/test/issue-23.js
  34. +24 −0 node_modules/xml2js/node_modules/sax/test/issue-30.js
  35. +15 −0 node_modules/xml2js/node_modules/sax/test/issue-35.js
  36. +13 −0 node_modules/xml2js/node_modules/sax/test/issue-47.js
  37. +31 −0 node_modules/xml2js/node_modules/sax/test/issue-49.js
  38. +28 −0 node_modules/xml2js/node_modules/sax/test/parser-position.js
  39. +12 −0 node_modules/xml2js/node_modules/sax/test/script.js
  40. +40 −0 node_modules/xml2js/node_modules/sax/test/self-closing-child-strict.js
  41. +40 −0 node_modules/xml2js/node_modules/sax/test/self-closing-child.js
  42. +25 −0 node_modules/xml2js/node_modules/sax/test/self-closing-tag.js
  43. +17 −0 node_modules/xml2js/node_modules/sax/test/stray-ending.js
  44. +17 −0 node_modules/xml2js/node_modules/sax/test/trailing-non-whitespace.js
  45. +17 −0 node_modules/xml2js/node_modules/sax/test/unquoted.js
  46. +67 −0 node_modules/xml2js/node_modules/sax/test/xmlns-issue-41.js
  47. +59 −0 node_modules/xml2js/node_modules/sax/test/xmlns-rebinding.js
  48. +71 −0 node_modules/xml2js/node_modules/sax/test/xmlns-strict.js
  49. +15 −0 node_modules/xml2js/node_modules/sax/test/xmlns-unbound.js
  50. +30 −0 node_modules/xml2js/node_modules/sax/test/xmlns-xml-default-ns.js
  51. +35 −0 node_modules/xml2js/node_modules/sax/test/xmlns-xml-default-prefix-attribute.js
  52. +20 −0 node_modules/xml2js/node_modules/sax/test/xmlns-xml-default-prefix.js
  53. +40 −0 node_modules/xml2js/node_modules/sax/test/xmlns-xml-default-redefine.js
  54. +112 −0 node_modules/xml2js/package.json
  55. +30 −0 package.json
  56. +11 −0 test.js
@@ -0,0 +1,34 @@
+#MYRSS
+
+##Introduction
+
+google reader will close?
+
+we just want to get RSS
+
+##Installation
+
+ npm install myrss
+
+##API
+
+ var url = "http://cn.engadget.com/";
+
+ myrss(url,function(result){
+ console.log(result);
+ })
+
+##TODO
+
+There is too many bugs
+
+1. cannot afford redirect
+
+2. only support Atom and RSS version 2.0
+
+and so on
+
+###License
+
+Released under the license of MIT, welcome to enjoy open source.
+
@@ -0,0 +1 @@
+cmd.exe
@@ -0,0 +1,130 @@
+var http = require('http');
+var path = require('path');
+var URL = require('url');
+var parseString = require('xml2js').parseString;
+
+module.exports = function(url,callback){
+ getRSS(url,function(result){
+ for(var key in result){
+ console.log(key);
+ }
+ })
+}
+
+function getRSS(url,callback){
+ get_rss_xml(url,function(xml){
+ var type = '';
+ if(xml.rss && xml.rss['$'] && xml.rss['$'].version == '2.0'){
+ type = '2.0';
+ }
+ if(xml.feed && xml.feed['$'] && [xml.feed['$'].xmlns] && xml.feed['$'].xmlns.toLowerCase().indexOf('atom') !== -1){
+ type = 'atom';
+ }
+ var result;
+ switch(type){
+ case '2.0':
+ result = {
+ title: xml.rss.channel[0].title,
+ link: xml.rss.channel[0].link,
+ posts: xml.rss.channel[0].item
+ }
+ break;
+ case 'atom':
+ //console.log(xml.feed);
+ result = {
+ title: xml.feed.title,
+ link: xml.feed.link,
+ posts: xml.feed.entry
+ }
+ break;
+ }
+ if(typeof result.link !== 'string'){
+ result.link = url;
+ }
+
+ for(var i = 0; i < result.posts.length; i++){
+ for(var key in result.posts[i]){
+ if(typeof result.posts[i][key] === 'object'){
+ result.posts[i][key] = result.posts[i][key][0];
+ }
+ if(key === 'link'){
+ if( result.posts[i]['link']['$'] && result.posts[i]['link']['$'].href){
+ result.posts[i]['link'] = result.posts[i]['link']['$'].href;
+ }
+ }
+ }
+ }
+ callback(result);
+ });
+}
+
+function get_rss_xml(url,callback){
+ get_rss_url(url,function(rss_url){
+ getHTML(rss_url,function(xml){
+ //console.log(xml);
+ parseString(xml,function(err,result){
+ if(err)console.log(err);
+ callback(result);
+ })
+ })
+ });
+}
+
+function get_rss_url(url,callback){
+ var result = [];
+ getHTML(url,function(html){
+ var htmlarr = html.split('\n');
+ for(var i = 0; i < htmlarr.length; i++){
+ if(htmlarr[i].indexOf('<link') !== -1){
+ var line = htmlarr[i].toLowerCase();
+ if(line.indexOf('rss') !== -1){
+ var linearr = line.split(' ');
+ linearr.forEach(function(l){
+ if(l.indexOf('href') !== -1){
+ var larr = l.split('"');
+ if(larr.length === 1){
+ larr = l.split('\'');
+ }
+ result.push(larr[1]);
+ }
+ });
+
+ }
+ }
+ }
+ var min = 99;
+ var rss_url = null;
+ result.forEach(function(x){
+ if(x.length < min){
+ min = x.length;
+ rss_url = x;
+ }
+ });
+ if(rss_url.indexOf('http://') === -1){//relative path
+ rss_url = url + rss_url;
+ }
+ //console.log(rss_url);
+ callback(rss_url);
+ });
+}
+
+function getHTML(url,callback){
+ var hostname = URL.parse(url).hostname;
+ var pathname = URL.parse(url).path;
+ var opts = {
+ hostname: hostname,
+ path: pathname,
+ method: 'GET'
+ }
+ //console.log(opts);
+ var html = "";
+ var req = http.request(opts,function(res){
+ res.on('data',function(data){
+ html += data;
+ });
+ res.on('end',function(){
+ callback(html);
+ });
+ });
+ req.end();
+}
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 6422e6a

Please sign in to comment.