

def pagerank(url):
    'Return the PageRank number that would show for this URL in Google Toolbar.'
    import urllib

    def CheckHash(HashInt):
        HashStr = ('%u' % HashInt)
        Flag = 0
        CheckByte = 0
        i = (len(HashStr) - 1)
        while (i >= 0):
            Byte = int(HashStr[i])
            if (1 == (Flag % 2)):
                Byte *= 2
                Byte = ((Byte / 10) + (Byte % 10))
            CheckByte += Byte
            Flag += 1
            i -= 1
        CheckByte %= 10
        if (0 != CheckByte):
            CheckByte = (10 - CheckByte)
            if (1 == (Flag % 2)):
                if (1 == (CheckByte % 2)):
                    CheckByte += 9
                CheckByte >>= 1
        return (('7' + str(CheckByte)) + HashStr)

    def HashURL(Str):

        def IntStr(String, Integer, Factor):
            for i in range(len(String)):
                Integer *= Factor
                Integer &= 4294967295
                Integer += ord(String[i])
            return Integer
        C1 = IntStr(Str, 5381, 33)
        C2 = IntStr(Str, 0, 65599)
        C1 >>= 2
        C1 = (((C1 >> 4) & 67108800) | (C1 & 63))
        C1 = (((C1 >> 4) & 4193280) | (C1 & 1023))
        C1 = (((C1 >> 4) & 245760) | (C1 & 16383))
        T1 = ((C1 & 960) << 4)
        T1 |= (C1 & 60)
        T1 = ((T1 << 2) | (C2 & 3855))
        T2 = ((C1 & 4294950912) << 4)
        T2 |= (C1 & 15360)
        T2 = ((T2 << 10) | (C2 & 252641280))
        return (T1 | T2)
    hsh = CheckHash(HashURL(url))
    gurl = ('http://toolbarqueries.google.com/tbr?client=navclient-auto&features=Rank:&q=info:%s&ch=%s' % (urllib.quote(url), hsh))
    f = urllib.urlopen(gurl)
    st = f.read()
    st = st.lstrip().rstrip()
    st = st[9:]
    try:
        st = int(st)
    except:
        st = 0
    return st

dataset/ETHPy150Open miklevin/pipulate/common.py pagerank/original