Over a million developers have joined DZone.

Get A Jaiku Personal_key Given A Username And Password

Logs into Jaiku and then gets the personal_key for using the API.

def GetJaikuPersonalKey(user, password):
  """Finds the Jaiku API personal_key from a username and password.

  One day I'll learn to use urllib2 properly and cookie parsing and stuff.

  # login and find a cookie
  login_url = "http://jaiku.com/login"
  request_body = urllib.urlencode({'log': user,
                                   'pwd': password,
                                   'rememberme': '1'})
  # Open a connection to the authentication server.
  auth_connection = httplib.HTTPConnection('jaiku.com')
  # Begin the POST request to the client login service.
  auth_connection.putrequest('POST', '/login')
  # Set the required headers for an Account Authentication request.
  auth_connection.putheader('Content-Length', str(len(request_body)))
  auth_response = auth_connection.getresponse()
  if auth_response.status == 303:
    cookie_str = auth_response.getheader("set-cookie")
    # TODO(ark) parse this properly!
    res = re.search("(jaikuuser_[^;]*).*(jaikupass_[^;]*)", cookie_str)
    if res:
      auth_cookie = "%s; %s" % (res.group(1), res.group(2))
      apikey_url = "http://api.jaiku.com/key"
      req = urllib2.Request(url=apikey_url)
      req.add_header('Cookie', auth_cookie)
      f = urllib2.urlopen(req)
      return f.read()

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}