here2share

# webbrowser_google_images_demo.py

May 11th, 2015
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.17 KB | None | 0 0
  1. # webbrowser_google_images_demo.py
  2.  
  3. from urllib import quote
  4. import webbrowser
  5.  
  6. base_url = "https://www.google.ca/search?q="
  7. image_default = "&newwindow=1&tbm=isch&source=lnt&tbs=isz:l&sa=X&ei=ZZZQVZZZZZZZyZZZZZGIDQ&ved=0CBQQpwU&dpr=1&biw=1368&bih=632"
  8.  
  9. def verify(yn):
  10.     while 1:
  11.         if yn in ['y','yes']:
  12.             return True
  13.         elif yn in ['n','no']:
  14.             return False
  15.         yn = raw_input('Unverified Command. Please Answer with a Yes or No: ')
  16.  
  17. def googleimagesearch():
  18.     query = raw_input("Please enter your search query: ")
  19.     yn = raw_input("Would you like that search to be in quotes? ")
  20.     if verify(yn):
  21.         query='"'+query+'"'
  22.     yn = raw_input("Would you like your search to be 1280 width and 800 height? ")
  23.     if verify(yn):
  24.         image_url = "&newwindow=1&biw=1368&bih=632&tbs=islt:xga,isz:ex,iszw:1280,iszh:800&tbm=isch&source=lnt"
  25.     else:
  26.         image_url = image_default
  27.     yn = raw_input("Would you like to refine your search? ")
  28.     if verify(yn):
  29.         refine = raw_input("Refine: ")
  30.         query+=' '+refine
  31.     link = base_url + quote(query) + image_url
  32.     webbrowser.open(link)
  33.     yn = raw_input("Would you like to do another image search? ")
  34.     if verify(yn):
  35.         googleimagesearch()
  36.  
  37. googleimagesearch()
Add Comment
Please, Sign In to add comment