コード例 #1
0
ファイル: service.py プロジェクト: jkamuda/UrlTypoProtector
    def GET(self, domain):
        trimmed_domain = domain.replace(".com", "")
        r_server = redis.StrictRedis(connection_pool=CONNECTION_POOL)
        intended_domain_id = r_server.hget(r_utils.get_typo_key(trimmed_domain), 'intended')
        if intended_domain_id is None:
            return ''

        intended_domain = r_server.hget(r_utils.get_domain_key(intended_domain_id), 'url')
        return URL_CORRECTION_FORMAT.format(intended_domain)
コード例 #2
0
def add_permutations_for_domain(domain):
    r_server = get_redis_connection()

    domain_id = add_domain(r_server, domain)

    domain_typo_permutations = permutation_tools.get_permutations(domain)
    for typo in domain_typo_permutations:
        typo_key = r_utils.get_typo_key(typo)
        identify_conflict(r_server, domain, typo)
        if typo == domain:
            continue
        r_server.hset(typo_key, 'intended', domain_id)
コード例 #3
0
def identify_conflict(r_server, domain, typo):
    typo_key = r_utils.get_typo_key(typo)
    if r_server.exists(typo_key):
        domain_id = r_server.hget(typo_key, 'intended')
        intended_domain = r_server.hget(r_utils.get_domain_key(domain_id), 'url')
        print 'conflict for ' + domain + ' on ' + typo + ' (' + intended_domain + ')'