break a time, with break the c0de…

pagerankchecker.py


kemarin setelah tadi jalan – jalan di google , eh ketemu sama google pagerank .
lalu saya punya ide buat memparsingnya, dan ternyata ada hash tersendiri di pagerank checker tersebut.
yah lumayan tapi akhirnya saya bisa juga memparsingnya horeeee :D
ok silahkan test saja program dibawah ini :

#!/usr/bin/python
# -*- coding: utf-8 -*-
#
#  Script for getting Google Page Rank of page
#  Google Toolbar 3.0.x/4.0.x Pagerank Checksum Algorithm
#
#  by gunslinger_ - 2010




import urllib, sys, time


def get_pagerank(url):
    hsh = cek_hash(hash_url(url))
    gurl = 'http://www.google.com/search?client=navclient-auto&features=Rank:&q=info:%s&ch=%s' % (urllib.quote(url), hsh)
    try:
        f = urllib.urlopen(gurl)
        rank = f.read().strip()[9:]
    except Exception:
        rank = 'N/A'
    if rank == '':
        rank = '0'
    return rank
    
    
def  int_str(string, integer, faktor):
    for i in range(len(string)) :
        integer *= faktor
        integer &= 0xFFFFFFFF
        integer += ord(string[i])
    return integer


def hash_url(string):
    c1 = int_str(string, 0x1505, 0x21)
    c2 = int_str(string, 0, 0x1003F)

    c1 >>= 2
    c1 = ((c1 >> 4) & 0x3FFFFC0) | (c1 & 0x3F)
    c1 = ((c1 >> 4) & 0x3FFC00) | (c1 & 0x3FF)
    c1 = ((c1 >> 4) & 0x3C000) | (c1 & 0x3FFF)

    t1 = (c1 & 0x3C0) << 4
    t1 |= c1 & 0x3C
    t1 = (t1 << 2) | (c2 & 0xF0F)

    t2 = (c1 & 0xFFFFC000) << 4
    t2 |= c1 & 0x3C00
    t2 = (t2 << 0xA) | (c2 & 0xF0F0000)

    return (t1 | t2)


def cek_hash(hash_int):
    hash_str = '%u' % (hash_int)
    bendera = 0
    cek_byte = 0

    i = len(hash_str) - 1
    while i >= 0:
        byte = int(hash_str[i])
        if 1 == (bendera % 2):
            byte *= 2;
            byte = byte / 10 + byte % 10
        cek_byte += byte
        bendera += 1
        i -= 1

    cek_byte %= 10
    if 0 != cek_byte:
        cek_byte = 10 - cek_byte
        if 1 == bendera % 2:
            if 1 == cek_byte % 2:
                cek_byte += 9
            cek_byte >>= 1

    return '7' + str(cek_byte) + hash_str



if __name__ == '__main__':
    print '''                                                     __               __                  __                 
.-----..---.-..-----..-----.    .----..---.-..-----.|  |--.    .----.|  |--..-----..----.|  |--..-----..----.
|  _  ||  _  ||  _  ||  -__|    |   _||  _  ||     ||    <     |  __||     ||  -__||  __||    < |  -__||   _|
|   __||___._||___  ||_____|    |__|  |___._||__|__||__|__|    |____||__|__||_____||____||__|__||_____||__|  
|__|          |_____|                                                                        by gunslinger_                
'''
    host = raw_input("Please input site you want to check : ")
#    print int(get_pagerank(host))  
    for x in range(int(get_pagerank(host))):
      x += 1
      time.sleep(1)
      sys.stdout.write("\rCalculating score --> %d" % x)
      sys.stdout.flush()
    else:
      sys.stdout.write("\n%s score is %d\n" % (host,x))

lalu hasilnya akan seperti ini :

semoga bermanfaat untuk menambahkan aplikasi lainnya :)

Advertisements

One response

  1. This is just the piece of code I was looking for. Thanks guy for this sharing !

    November 20, 2010 at 4:56 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s