Logic-Gate - 2013-05-30

update 30/06/2013

UPDATE An early version is available for Penbang 0.0.3

You could also download it penbang-scripts
You will need to change the paths to get it working correctly.


Callerpy is a truecaller name retriever.

Since my request for the API was rejected, I commenced using python parsing libraries.

Callerpy emulates the process one would encounter if using a web-browser.

The procedure

callerpy.py

:::python

.
..
...
def Run():
    current_date = datetime.datetime.now()
    print clr.YEL
    proceed = raw_input("shall I proceed? Y/N ")
    print clr.ENDC
    if proceed in ('yes', 'y', 'Y', 'YES'):
        html = open('twill_output', 'r')
        a = html.read()
        bs = BeautifulSoup(a)
        if '<p class="sr-name">' in  a:
                print 'Result Ready\n'
                for num in bs.find_all('p',{"class":"sr-name"}):
                    #print num
                p = re.split(r'<.*?>', str(num))
                for i in p:
                    print i
                hist = open('history.log', 'a')
                hist.write('On %s ----- [[%s]] \n' %(current_date, p))
                hist.close()
    elif 'http://www.truecaller.com/social_auth/?p=social_auth_index' in a:
            print clr.RED
            print 'Something went wrong'
            print clr.ENDC
            hist = open('history.log', 'a')
            hist.write('On %s ----- %s \n' %(current_date, 'No match was found'))
            hist.close()
        html.close()
    elif proceed in ('no', 'n', 'N', 'NO'):
        KeyboardInterrupt
        print 'Goodbye'

if __name__ == "__main__":
    if len(sys.argv) > 1: callerpyFunc=sys.argv[1]
    if callerpyFunc == '-hist':
        history()
    if callerpyFunc == '-ph':
        print 'Please wait...'
        auth.AUTH()
        Run()

When the script runs, it will call auth.AUTH()


auth.py

:::python

    CallerUrl = "http://www.truecaller.com/"
    # The first part of the function will get twitter's oauth_token.
    def AUTH():
        dele = open('twill_output', 'r+') # needed to insure that twill_output stays clean
        dele.truncate()
        # connect to truecaller and retrieve twitter's oauth_token hash using re.split
        print clr.MOV
        print '\nPlease wait while I get the Token\n'
        print clr.ENDC
        AuthURL = "social_auth/?p=social_auth_index"
        twitterAuthURL = "&action=login&type=twitter"
        httpIt = CallerUrl + AuthURL + twitterAuthURL
        http = httplib2.Http()
        status, response = http.request(httpIt)
        bs = BeautifulSoup(response)
        for num in bs.find_all(re.compile("a")):
            if num.has_attr('href') == True:
                if len(num['href']) > 50: #Constant links are less than 48
                    #print num.get('href') + clr.ENDC + '\n'
                    print 'Twitter token hash:\n' + clr.YEL
                    a = re.split('=', num.get('href'))
                    for token in a:
                        if len(token) > 38:
                            print token
                    print clr.ENDC
        # connect to twitter and submit the token
        print clr.MOV
        print '\nPlease wait while I get the Token\n'
        print clr.ENDC
        twitter_URL = 'https://api.twitter.com/oauth/authorize?oauth_token='
        twitter_authURL = twitter_URL + token
        print 'Twitter oauth_token link:\n' + clr.YEL
        print twitter_authURL
        print clr.ENDC
        urlRedirect.truecaller_from_twitter(url=twitter_authURL)
        return

The current mean of logging in into truecaller is by twitter.

auth.py will connect to truecaller and follow the authentication process to twitter. It will then retrieve oauth_token and send it to urlRedirect.py


urlRedirect.py

:::python

def truecaller_from_twitter(url):
    time.sleep(0.5)
    try:
        op = open('twill_output', 'w+')
        twill.set_output(op)
        #redirect_output('twill_output') # Will only write after script has finished due to missing close() in commands.py
    except:
        print 'Could not write to file'
    go(url)
    showforms() #For testing
    formclear('1')
    fv("1", "session[username_or_email]", "USERNAME") #change username/password to string for hardcoded creds
    fv("1", "session[password]", "PASSWORD")
    fv("1", "None", "1")
    print '\n'
    showforms() #For testing
    submit('6')
    save_cookies('cookie_session_twitter')
    time.sleep(1)
    number = raw_input('Please enter number: ')
    go('http://www.truecaller.com')
    showforms()
    formclear('1')
    fv('1','q', str(number))
    submit('3')
    showforms()
    info()
    show()
    op.close()

urlRedirect.py will submit your credentials to twitter and authorise truecaller. It will then save the cookie as cookie_session_twitter and submit the truecaller form.

NOTE:
save__cookies() and cookie_session_twitter are part of a previous testing version. Currently they have no use.


Example of cookie_session_twitter
:::cookie

#LWP-Cookies-2.0
Set-Cookie3: _twitter_sess="BAh7CjoQc3RheV9zZWN1cmVUOgl1c2VyaQSP%252BHcYOgxjc3JmX2lkIiViYWRm%250AMjdhZTg3NjRjNjY0YjQwZmM4OTRiODU3NThlOToPY3JlYXRlZF9hdGwrCOOB%250AdfA%252BAToHaWQiJWIwMzY5ZDBjNjNiMGRlMzQxN2YzMTE5MGM3ZWU5ZTlh--c26936f7ea42dff0012e4b97357ce416f9a6b981"; path="/"; domain=".twitter.com"; path_spec; domain_dot; discard; HttpOnly=None; version=0
Set-Cookie3: auth_token=a00055e12db25a31c158b4217e4cf170e88b21fe; path="/"; domain=".twitter.com"; path_spec; domain_dot; secure; discard; HttpOnly=None; version=0
Set-Cookie3: guest_id="v1%3A136983383282559723"; path="/"; domain=".twitter.com"; path_spec; domain_dot; expires="2015-05-29 13:23:52Z"; version=0
Set-Cookie3: remember_checked=0; path="/"; domain=".twitter.com"; path_spec; domain_dot; expires="2023-05-30 01:23:55Z"; version=0
Set-Cookie3: remember_checked_on=0; path="/"; domain=".twitter.com"; path_spec; domain_dot; expires="2023-05-30 01:23:55Z"; version=0
Set-Cookie3: secure_session=true; path="/"; domain=".twitter.com"; path_spec; domain_dot; discard; version=0
Set-Cookie3: twid="u%3D410515599%7CbvH4XZtFayBUN66GW%2FqIRFmA5TA%3D"; path="/"; domain=".twitter.com"; path_spec; domain_dot; secure; discard; version=0
Set-Cookie3: twll="l%3D1369833835"; path="/"; domain=".twitter.com"; path_spec; domain_dot; expires="2023-05-30 01:23:55Z"; version=0
Set-Cookie3: lang=en; path="/"; domain="api.twitter.com"; path_spec; discard; version=0
Set-Cookie3: PHPSESSID=u9dl02j304jp4jfg5o0l2kv2q0; path="/"; domain="www.truecaller.com"; path_spec; discard; version=0
Set-Cookie3: SocialAuth="YToxMTp7czo0OiJ0eXBlIjtzOjc6InR3aXR0ZXIiO3M6NToiZW1haWwiO3M6ODoiTWFkX19EZXYiO3M6NDoiZGF0YSI7czo4OiJBLk1hZGFuaSI7czo0OiJuYW1lIjtzOjg6IkEuTWFkYW5pIjtzOjEwOiJhY2NvdW50X2lkIjtpOjQxMDUxNTU5OTtzOjc6ImZyaWVuZHMiO2k6OTtzOjk6ImZvbGxvd2VycyI7aTozMDtzOjk6ImxvZ2dlZF9pbiI7YjoxO3M6MjI6InNvY2lhbF9hdXRoX3JlZ2lzdGVyaWQiO3M6ODoiMTgzNTA0OTYiO3M6OToic3VzcGVuZGVkIjtpOjA7czoxMToic2Vzc2lvbl9rZXkiO3M6NDA6ImQyYjBmNjc3ZDI1NTI3NDM3OWViODlmMjUwMmY2ZDcyNmI1YmI4OGUiO30%3D"; path="/"; domain="www.truecaller.com"; path_spec; expires="2013-06-28 13:23:58Z"; version=0
Set-Cookie3: XLBS="XLBS|UaYBc|UaYBc"; path="/"; domain="www.truecaller.com"; path_spec; discard; version=0
Set-Cookie3: oauth_token="410515599-EfZiAaJRmuWWOznRMgChQs3BpZZFKaWAZ8g0qifH"; path="/social_auth"; domain="www.truecaller.com"; discard; version=0
Set-Cookie3: oauth_token_secret=2e5gOko7PDhBnsGvyZehmFXRRWNN0cuRXn0gFIp4o; path="/social_auth"; domain="www.truecaller.com"; discard; version=0\

All of your "lookups" will be stored in history.log using the following format


:::history.log

    On 2013-05-31 03:59:51.415839 ----- [[['', 'John Doe  ', '12345678990', '', '\n', 'Planet Earth', '', '']]]

 

Last edit: Logic-Gate 2013-06-29