here2share

# webbrowser_google_images_demo2.py

May 11th, 2015
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.78 KB | None | 0 0
  1. # webbrowser_google_images_demo2.py >>> Time Filter added
  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 tlim(cr):
  18.     if   cr == 1: cr = 'd'
  19.     elif cr == 2: cr = 'w'
  20.     elif cr == 3: cr = 'm'
  21.     elif cr == 4: cr = 'y'
  22.     else:
  23.         return False
  24.     return cr
  25.    
  26.  
  27. def googleimagesearch():
  28.     query = raw_input("Please enter your search query: ")
  29.     yn = raw_input("Would you like that search to be in quotes? ")
  30.     if verify(yn):
  31.         query='"'+query+'"'
  32.     yn = raw_input("Would you like your search to be 1280 width and 800 height? ")
  33.     if verify(yn):
  34.         image_url = "&newwindow=1&biw=1368&bih=632&tbs=islt:xga,isz:ex,iszw:1280,iszh:800&tbm=isch&source=lnt"
  35.     else:
  36.         image_url = image_default
  37.     yn = raw_input("Would you like to refine your search? ")
  38.     if verify(yn):
  39.         refine = raw_input("Refine: ")
  40.         query+=' '+refine
  41.     cr = raw_input("Within (1) the 24hr mark, (2) the week, (3) the month, (4) the year? ")
  42.     try:cr=tlim(int(cr))
  43.     except:pass
  44.     print
  45.     if '1280' in image_url:
  46.         if cr:
  47.             image_url = "&newwindow=1&biw=1368&bih=632&tbs=qdr:"+cr+",isz:ex,iszw:1280,iszh:800&tbm=isch&source=lnt"
  48.     else:
  49.         if cr:
  50.             image_url = "&newwindow=1&tbs=isz:l,qdr:"+cr+"&tbm=isch&source=lnt&sa=X&ei=ZZZQVZZZZZZZyZZZZZGIDQ&ved=0CBMQpwU&dpr=1&biw=1368&bih=632"
  51.     link = base_url + quote(query) + image_url
  52.     webbrowser.open(link)
  53.     yn = raw_input("Would you like to do another image search? ")
  54.     if verify(yn):
  55.         googleimagesearch()
  56.  
  57. googleimagesearch()
Add Comment
Please, Sign In to add comment