def fetch_proofs(profile, username, profile_ver=2, refresh=False): """ Get proofs for a profile and: a) check cached entries b) check which version of profile we're using """ if MEMCACHED_ENABLED and not refresh: log.debug("Memcache get proofs: %s" % username) proofs_cache_reply = mc.get("proofs_" + str(username)) else: proofs_cache_reply = None if proofs_cache_reply is None: if profile_ver == 3: proofs = profile_v3_to_proofs(profile, username) else: proofs = profile_to_proofs(profile, username) if MEMCACHED_ENABLED or refresh: log.debug("Memcache set proofs: %s" % username) mc.set("proofs_" + str(username), json.dumps(proofs), int(time() + MEMCACHED_TIMEOUT)) else: proofs = json.loads(proofs_cache_reply) return proofs
def test_proofs(self): """ Check twitter proof """ for username in test_users: profile, zone_file = get_profile(username) if zone_file is not None: proofs = profile_v3_to_proofs(profile, username) else: proofs = profile_to_proofs(profile, username) for proof in proofs: if proof['service'] in check_proofs: self.assertTrue(proof['valid'])
def test_proofs(self): """ Check twitter proof """ for username in test_users: profile, zone_file = get_profile(username) if not is_profile_in_legacy_format(zone_file): proofs = profile_v3_to_proofs(profile, username + '.id') else: proofs = profile_to_proofs(profile, username + '.id') for proof in proofs: print proof if proof['service'] in check_proofs: self.assertTrue(proof['valid'])
def format_profile(profile, username, address): """ Process profile data and 1) Insert verifications 2) Check if profile data is valid JSON """ data = {} # save the original profile, in case it's a zone file zone_file = profile if 'error' in profile: data['profile'] = {} data['error'] = profile['error'] data['verifications'] = [] return data try: profile = resolve_zone_file_to_profile(profile, address) except: if 'message' in profile: data['profile'] = json.loads(profile) data['verifications'] = [] return data if profile is None: data['profile'] = {} data['error'] = "Malformed profile data." data['verifications'] = [] else: if not is_profile_in_legacy_format(profile): data['zone_file'] = zone_file data['profile'] = profile data['verifications'] = profile_v3_to_proofs( data['profile'], username) else: data['profile'] = json.loads(profile) data['verifications'] = profile_to_proofs(data['profile'], username) return data
def get_proofs(username, profile): check_proofs = proofs_cache.find_one({"username": username}) if check_proofs is None: try: proofs = profile_to_proofs(profile, username) except: proofs = [] new_entry = {} new_entry['username'] = username new_entry['proofs'] = proofs proofs_cache.save(new_entry) else: print "hitting cache!" proofs = check_proofs['proofs'] return proofs
def fetch_proofs(profile, username, address, profile_ver=2, zonefile=None): """ Get proofs for a profile and: a) check cached entries b) check which version of profile we're using """ if 'account' not in profile: return [] # fix up missing proofUrls for account in profile['account']: if ('proofType' in account and account['proofType'] == 'http' and 'proofUrl' not in account): site_data_to_fixed_proof_url(account, zonefile) if profile_ver == 3: proofs = profile_v3_to_proofs(profile, username, address=address) else: proofs = profile_to_proofs(profile, username, address=address) return proofs
def fetch_proofs(profile, username, profile_ver=2, zonefile=None, refresh=False): """ Get proofs for a profile and: a) check cached entries b) check which version of profile we're using """ if MEMCACHED_ENABLED and not refresh: log.debug("Memcache get proofs: %s" % username) proofs_cache_reply = mc.get("proofs_" + str(username)) else: proofs_cache_reply = None if 'account' not in profile: return [] # fix up missing proofUrls for account in profile['account']: if ('proofType' in account and account['proofType'] == 'http' and 'proofUrl' not in account): site_data_to_fixed_proof_url(account, zonefile) if proofs_cache_reply is None: if profile_ver == 3: proofs = profile_v3_to_proofs(profile, username) else: proofs = profile_to_proofs(profile, username) if MEMCACHED_ENABLED or refresh: log.debug("Memcache set proofs: %s" % username) mc.set("proofs_" + str(username), json.dumps(proofs), int(time() + MEMCACHED_TIMEOUT)) else: proofs = json.loads(proofs_cache_reply) return proofs
def fetch_proofs(profile, username, profile_ver=2, zonefile = None, refresh=False): """ Get proofs for a profile and: a) check cached entries b) check which version of profile we're using """ if MEMCACHED_ENABLED and not refresh: log.debug("Memcache get proofs: %s" % username) proofs_cache_reply = mc.get("proofs_" + str(username)) else: proofs_cache_reply = None if 'account' not in profile: return [] # fix up missing proofUrls for account in profile['account']: if ('proofType' in account and account['proofType'] == 'http' and 'proofUrl' not in account): site_data_to_fixed_proof_url(account, zonefile) if proofs_cache_reply is None: if profile_ver == 3: proofs = profile_v3_to_proofs(profile, username) else: proofs = profile_to_proofs(profile, username) if MEMCACHED_ENABLED or refresh: log.debug("Memcache set proofs: %s" % username) mc.set("proofs_" + str(username), json.dumps(proofs), int(time() + MEMCACHED_TIMEOUT)) else: proofs = json.loads(proofs_cache_reply) return proofs