Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. from urllib2 import Request, urlopen, URLError
  2. from flask import Flask, render_template, request, redirect
  3.  
  4. def is_valid_url(url):
  5.     req = Request(url, headers={'User-Agent' : "Magic Browser"})
  6.     try:
  7.         response = urlopen(req)
  8.     except URLError, e:
  9.         return False
  10.     else:
  11.         return True
  12.  
  13. errors = []
  14. word = 'linkedin.com'
  15. if is_valid_url(word):
  16.     print 'valid url'
  17.  
  18. else:
  19.     errors.append("- Something's fishy with that URL")
  20.  
  21.  
  22. @app.route('/')
  23. def hello_world():
  24.     author = "Gil"
  25.     return render_template('index.html', author=author)
  26.  
  27. @app.route('/textcheck', methods = ['POST'])
  28. def signup():
  29.     all_good = False
  30.     message = request.form['text']
  31.  
  32.     print len(message)
  33.     errors, all_good = split_them(message)
  34.     if errors == []:
  35.         all_good = True
  36.     return render_template('text-result1.html', errors=errors, text=message, all_good=all_good)
  37.  
  38. @app.route('/text-result1.html')
  39. def tweets():
  40.     return render_template('text-result1.html', errors=errors, text=message, all_good=all_good)
  41.  
  42. if __name__ == '__main__':
  43.     app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement