Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 113 lines (101 sloc) 3.121 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
6ecc1a8 @chriso Fix pagerank failure on empty response, closes #86
authored
27 data = data or ''
28
cbb1912 @chriso Added initial built-in modules
authored
29 if match = data.match /Rank_1:1:(10|[0-9])/
30 @emit input + ',' + match[1]
31 else
32 @emit input + ','
33
34 class UsageDetails extends nodeio.JobClass
d5779e6 @chriso Whitespace removal rampage
authored
35 input: ->
cbb1912 @chriso Added initial built-in modules
authored
36 @status usage
37 @exit()
38
39 @class = Pagerank
40 @job = {
41 pagerank: new Pagerank(options)
42 help: new UsageDetails()
43 }
44
45 `
cc1cc2d @chriso Another typo
authored
46 // BEGIN CODE FOR GENERATING GOOGLE PAGERANK CHECKSUMS
cbb1912 @chriso Added initial built-in modules
authored
47 //----------------------------------------------------------------------------------------------
48 function zF(a,b) {
49 var z = parseInt(80000000,16);
50 if (z & a) {
51 a = a>>1;
52 a &=~z;
53 a |= 0x40000000;
54 a = a>>(b-1);
55 } else {
56 a = a>>b;
57 }
58 return(a);
59 }
d5779e6 @chriso Whitespace removal rampage
authored
60 function mix(a,b,c) {
cbb1912 @chriso Added initial built-in modules
authored
61 a-=b; a-=c; a^=(zF(c,13));
62 b-=c; b-=a; b^=(a<<8);
63 c-=a; c-=b; c^=(zF(b,13));
64 a-=b; a-=c; a^=(zF(c,12));
65 b-=c; b-=a; b^=(a<<16);
66 c-=a; c-=b; c^=(zF(b,5));
67 a-=b; a-=c; a^=(zF(c,3));
68 b-=c; b-=a; b^=(a<<10);
69 c-=a; c-=b; c^=(zF(b,15));
70 return (new Array((a),(b),(c)));
71 }
72 function GoogleCH(url,length) {
73 if(arguments.length == 1) length=url.length;
74 var a=0x9E3779B9, b=0x9E3779B9, c=0xE6359A60, k=0, len=length, mx=new Array();
d5779e6 @chriso Whitespace removal rampage
authored
75 while(len>=12) {
cbb1912 @chriso Added initial built-in modules
authored
76 a+=(url[k+0]+(url[k+1]<<8)+(url[k+2]<<16)+(url[k+3]<<24));
77 b+=(url[k+4]+(url[k+5]<<8)+(url[k+6]<<16)+(url[k+7]<<24));
78 c+=(url[k+8]+(url[k+9]<<8)+(url[k+10]<<16)+(url[k+11]<<24));
79 mx=mix(a,b,c);
d5779e6 @chriso Whitespace removal rampage
authored
80 a=mx[0]; b=mx[1]; c=mx[2];
cbb1912 @chriso Added initial built-in modules
authored
81 k+=12; len-=12;
82 }
83 c+=length;
d5779e6 @chriso Whitespace removal rampage
authored
84 switch(len) {
cbb1912 @chriso Added initial built-in modules
authored
85 case 11: c+=url[k+10]<<24;
86 case 10: c+=url[k+9]<<16;
87 case 9:c+=url[k+8]<<8;
88 case 8:b+=(url[k+7]<<24);
89 case 7:b+=(url[k+6]<<16);
90 case 6:b+=(url[k+5]<<8);
91 case 5:b+=(url[k+4]);
92 case 4:a+=(url[k+3]<<24);
93 case 3:a+=(url[k+2]<<16);
94 case 2:a+=(url[k+1]<<8);
95 case 1:a+=(url[k+0]);
96 }
97 mx=mix(a,b,c);
98 if(mx[2]<0) {
99 return(0x100000000+mx[2]);
d5779e6 @chriso Whitespace removal rampage
authored
100 } else {
cbb1912 @chriso Added initial built-in modules
authored
101 return(mx[2]);
102 }
103 }
d5779e6 @chriso Whitespace removal rampage
authored
104 function strord(string) {
cbb1912 @chriso Added initial built-in modules
authored
105 var result=new Array();
106 for(i=0;i<string.length;i++){
107 result[i]=string[i].charCodeAt(0);
108 }
109 return(result);
110 }
111 //----------------------------------------------------------------------------------------------
d5779e6 @chriso Whitespace removal rampage
authored
112 `
Something went wrong with that request. Please try again.