Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 111 lines (100 sloc) 3.088 kb
cbb1912 @chriso Added initial built-in modules
authored
1 usage = '''
2 This module checks a URL's Google pagerank (rate limits apply)
3
4 1. To find the pagerank of a URL:
d5779e6 @chriso Whitespace removal rampage
authored
5 $ echo "mastercard.com" | node.io -s pagerank
cbb1912 @chriso Added initial built-in modules
authored
6 => mastercard.com,7
7 '''
8
9 nodeio = require 'node.io'
10
11 options = {
12 timeout: 10
13 retries:3
14 }
15
16 class Pagerank extends nodeio.JobClass
17 run: (input) ->
18 url = input
710ac50 @chriso Updated README and fixed pagerank bug
authored
19 if url.indexOf('http://') is -1 then url = 'http://' + url
d5779e6 @chriso Whitespace removal rampage
authored
20
cbb1912 @chriso Added initial built-in modules
authored
21 # Generate the URL checksum
22 ch = '6' + GoogleCH strord 'info:' + url
d5779e6 @chriso Whitespace removal rampage
authored
23
8e7ef44 @oncletom Fixing rank calculation, cf. #74
oncletom authored
24 @get 'http://toolbarqueries.google.com/tbr?client=navclient-auto&ch='+ch+'&features=Rank&q=info:'+encodeURIComponent(url), (err, data) =>
cbb1912 @chriso Added initial built-in modules
authored
25 if err? then return @retry()
d5779e6 @chriso Whitespace removal rampage
authored
26
cbb1912 @chriso Added initial built-in modules
authored
27 if match = data.match /Rank_1:1:(10|[0-9])/
28 @emit input + ',' + match[1]
29 else
30 @emit input + ','
31
32 class UsageDetails extends nodeio.JobClass
d5779e6 @chriso Whitespace removal rampage
authored
33 input: ->
cbb1912 @chriso Added initial built-in modules
authored
34 @status usage
35 @exit()
36
37 @class = Pagerank
38 @job = {
39 pagerank: new Pagerank(options)
40 help: new UsageDetails()
41 }
42
43 `
cc1cc2d @chriso Another typo
authored
44 // BEGIN CODE FOR GENERATING GOOGLE PAGERANK CHECKSUMS
cbb1912 @chriso Added initial built-in modules
authored
45 //----------------------------------------------------------------------------------------------
46 function zF(a,b) {
47 var z = parseInt(80000000,16);
48 if (z & a) {
49 a = a>>1;
50 a &=~z;
51 a |= 0x40000000;
52 a = a>>(b-1);
53 } else {
54 a = a>>b;
55 }
56 return(a);
57 }
d5779e6 @chriso Whitespace removal rampage
authored
58 function mix(a,b,c) {
cbb1912 @chriso Added initial built-in modules
authored
59 a-=b; a-=c; a^=(zF(c,13));
60 b-=c; b-=a; b^=(a<<8);
61 c-=a; c-=b; c^=(zF(b,13));
62 a-=b; a-=c; a^=(zF(c,12));
63 b-=c; b-=a; b^=(a<<16);
64 c-=a; c-=b; c^=(zF(b,5));
65 a-=b; a-=c; a^=(zF(c,3));
66 b-=c; b-=a; b^=(a<<10);
67 c-=a; c-=b; c^=(zF(b,15));
68 return (new Array((a),(b),(c)));
69 }
70 function GoogleCH(url,length) {
71 if(arguments.length == 1) length=url.length;
72 var a=0x9E3779B9, b=0x9E3779B9, c=0xE6359A60, k=0, len=length, mx=new Array();
d5779e6 @chriso Whitespace removal rampage
authored
73 while(len>=12) {
cbb1912 @chriso Added initial built-in modules
authored
74 a+=(url[k+0]+(url[k+1]<<8)+(url[k+2]<<16)+(url[k+3]<<24));
75 b+=(url[k+4]+(url[k+5]<<8)+(url[k+6]<<16)+(url[k+7]<<24));
76 c+=(url[k+8]+(url[k+9]<<8)+(url[k+10]<<16)+(url[k+11]<<24));
77 mx=mix(a,b,c);
d5779e6 @chriso Whitespace removal rampage
authored
78 a=mx[0]; b=mx[1]; c=mx[2];
cbb1912 @chriso Added initial built-in modules
authored
79 k+=12; len-=12;
80 }
81 c+=length;
d5779e6 @chriso Whitespace removal rampage
authored
82 switch(len) {
cbb1912 @chriso Added initial built-in modules
authored
83 case 11: c+=url[k+10]<<24;
84 case 10: c+=url[k+9]<<16;
85 case 9:c+=url[k+8]<<8;
86 case 8:b+=(url[k+7]<<24);
87 case 7:b+=(url[k+6]<<16);
88 case 6:b+=(url[k+5]<<8);
89 case 5:b+=(url[k+4]);
90 case 4:a+=(url[k+3]<<24);
91 case 3:a+=(url[k+2]<<16);
92 case 2:a+=(url[k+1]<<8);
93 case 1:a+=(url[k+0]);
94 }
95 mx=mix(a,b,c);
96 if(mx[2]<0) {
97 return(0x100000000+mx[2]);
d5779e6 @chriso Whitespace removal rampage
authored
98 } else {
cbb1912 @chriso Added initial built-in modules
authored
99 return(mx[2]);
100 }
101 }
d5779e6 @chriso Whitespace removal rampage
authored
102 function strord(string) {
cbb1912 @chriso Added initial built-in modules
authored
103 var result=new Array();
104 for(i=0;i<string.length;i++){
105 result[i]=string[i].charCodeAt(0);
106 }
107 return(result);
108 }
109 //----------------------------------------------------------------------------------------------
d5779e6 @chriso Whitespace removal rampage
authored
110 `
Something went wrong with that request. Please try again.