code: def parse_diaspora_webfinger(document):
      
      webfinger = {
          "hcard_url": None,
      }
      try:
          doc = json.loads(document)
          for link in doc["links"]:
              if link["rel"] == "http://microformats.org/profile/hcard":
                  webfinger["hcard_url"] = link["href"]
                  break
          else:
              logger.warning("parse_diaspora_webfinger: found JSON webfinger but it has no hcard href")
              raise ValueError
      except Exception:
          try:
              xrd = XRD.parse_xrd(document)
              webfinger["hcard_url"] = xrd.find_link(rels="http://microformats.org/profile/hcard").href
          except xml.parsers.expat.ExpatError:
              logger.warning("parse_diaspora_webfinger: found XML webfinger but it fails to parse (ExpatError)")
              pass
      return webfinger
docs: Parse Diaspora webfinger which is either in JSON format (new) or XRD (old).
  
      https://diaspora.github.io/diaspora_federation/discovery/webfinger.html