Example #1
0
def expand(shorted_url):
    """
    return the real url associated to a short url and increase the number of click
    
    Params 
        shorted_url - a shorted url
    
    Return 
        url - the real url to redirect
    """
    parsed_url = urlparse(sanitize(shorted_url))
    domain_frag, shorting_frag = parsed_url.path[1:].split('/')
    
    domain = db.Query(Domain).filter('name = ', domain_frag).get()
    if not domain:
        domain = db.Query(Domain).filter('friendly_name = ', domain_frag).get()

    q = db.Query(UrlBox)
    q.filter('shorting_frag = ', shorting_frag)
    q.filter('active = ', True)
    q.filter('domain = ', domain)
    urlbox = q.get()
    
    urlbox.click+=1 
    db.put(urlbox) 
    return urlbox.url
Example #2
0
def url_already_shorted(url, include_inactives=True):
    '''Check if an url was already shorted
    
    Params
        url - url to check: string
        include_inactives - extend query to inactive UrlBoxes
    
    Return
        whether the url was already shorted: boolean
    '''
    url = sanitize(url)

    q = db.Query(UrlBox, keys_only=True).filter('_url = ', url)
    if not include_inactives:
        q.filter('active = ', True)
    
    return q.get() is not None