예제 #1
0
def short():
    back_btn = ReturnToMainButton()
    if back_btn.validate_on_submit():
        return redirect('/')

    long_url = request.args['url']

    protocol, long_url = UrlParser.parse(long_url)
    is_url_valid = UrlVerifier.is_url_valid(protocol, long_url)

    if not is_url_valid:
        return redirect_invalid('I will only shorten valid URLs')

    short_url = request.args['short_url']
    if short_url is not '':
        if url_manager.is_short_url_exists(short_url):
            return redirect_invalid('Short URL taken')
        else:
            url_manager.set_short_url(long_url, short_url)
    elif short_url is '':
        short_url = url_manager.get_short_url(long_url)

    short_url = WEBSITE + short_url
    return render_template('result.html', title=APP_TITLE, 
                           short_url=short_url, back_btn=back_btn)
예제 #2
0
def read_url():
    url = 'https://www.allrecipes.com/recipe/279934/air-fryer-apricot-glazed-chicken-breasts/'
    up = UrlParser(url)
    up.extract_recipe()
예제 #3
0
 def test_parse_valid_http_invalid_site(self):
     result = UrlParser.parse("http://www.randomnonexistentsite.com")
     self.assertEqual(result,
                      (UrlParser.HTTP, "www.randomnonexistentsite.com"))
예제 #4
0
 def test_parse_invalid(self):
     result = UrlParser.parse("apples")
     self.assertEqual(result, (UrlParser.HTTP, "apples"))
예제 #5
0
 def test_parse_valid_no_protocol(self):
     result = UrlParser.parse("www.google.com")
     self.assertEqual(result, (UrlParser.HTTP, "www.google.com"))
예제 #6
0
 def test_parse_valid_https(self):
     result = UrlParser.parse("https://www.google.com")
     self.assertEqual(result, (UrlParser.HTTPS, "www.google.com"))