here2share

# Tk_google_image_search_link_automator.py ^ 2016.06

Nov 2nd, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.76 KB | None | 0 0
  1. # Tk_google_image_search_link_automator.py ^ 2016.01
  2. import re
  3.  
  4. def xdates(z):
  5.     r=re.findall('(?:19|20)\d\d-(?:[0][1-9]|[1][012])-(?:[0][1-9]|[12]\d|[3][01])',z)
  6.     return r
  7.  
  8. try:
  9.     # Python2
  10.     from Tkinter import *
  11.     from urllib2 import urlopen
  12. except ImportError:
  13.     # Python3
  14.     from tkinter import *
  15.     from urllib.request import urlopen
  16. import webbrowser
  17. import time
  18. from datetime import datetime
  19.  
  20. html='?????'
  21. zmax=''
  22. w,h = '299','749'
  23.  
  24. root=Tk()
  25. root.geometry('1280x654+0+0')
  26. root.title('Google Image Search Link Automator')
  27.  
  28. topFrame=LabelFrame(root,text="",height=600)
  29. topFrame.pack(fill=X)
  30. topFrame.pack_propagate(False)
  31.  
  32. Frame2=LabelFrame(root,height=24,borderwidth=0)
  33. Frame2.pack(fill=X)
  34. Frame2.pack_propagate(False)
  35.  
  36. Frame3=LabelFrame(root,height=30,borderwidth=0)
  37. Frame3.pack(fill=X)
  38. Frame3.pack_propagate(False)
  39.  
  40. ffff=Listbox(topFrame,selectmode=SINGLE)
  41. ffff.pack(fill=BOTH,expand=YES,side=LEFT)
  42. ffff.configure(selectmode=SINGLE)
  43.  
  44. def dblclk(event):
  45.     html=ffff.curselection()
  46.     html=links[int(html[0])]
  47.     webbrowser.open(html)
  48. ffff.bind("<Double-Button-1>", dblclk)
  49.  
  50. scroll=Scrollbar(topFrame)
  51. scroll.pack(side=RIGHT,fill=Y,expand=NO)
  52.  
  53. scroll.configure(command=ffff.yview)
  54. ffff.configure(yscrollcommand=scroll.set)
  55.  
  56. items=[]
  57. links=[]
  58.  
  59. #
  60. def update_list(items):
  61.     ffff.delete(0, END)
  62.     for item in items:
  63.         ffff.insert(END,item)
  64.     root.update()
  65. update_list(items) # None
  66. #
  67. def from_clipboard():
  68.     data = root.clipboard_get()
  69.     url.set(data)
  70.     root.update()
  71.     url_text()
  72. #
  73. def url_text():
  74.     global html, links, items
  75.     html=url.get()
  76.     #print html
  77.     print
  78.     try:
  79.         zmax=min(xdates(html))
  80.         #print zmax
  81.     except:
  82.         print "!!! timestamp not found -- default now set"
  83.         td=datetime.now()
  84.         zmax='%s-%s-%s' %(td.year,td.month,td.day)
  85.     ### s1='https://www.google.com/search?q='
  86.     s2='&newwindow=1&biw=1354&bih=637&source=lnt&tbs=isz%3Al%2Ccdr%3A1%2Ccd_min%3A'
  87.     s3='%2Ccd_max%3A'
  88.     s4='&tbm=isch'
  89.     links=[]
  90.     items=[]
  91.     t=''
  92.     i=2
  93.     year,month,day=zmax.split('-')
  94.     try:
  95.         req=html.split('&gs_l=img.')[0]
  96.         req.split('&newwindow=')[0]
  97.         print req
  98.         while 1:
  99.             yr,mo=divmod(int(month)+(int(year)*12)-i, 12)
  100.             if yr < 1992 or len(links) > 399: break
  101.             zmin='%s-%s-01' %(yr,mo+1)
  102.             link=req+s2+zmin+s3+zmax+s4
  103.             #print link
  104.             links.append(link)
  105.             items.append(zmin+"   >>>   "+zmax)
  106.             t+=link+'\n\n'
  107.             zmax=zmin
  108.             i+=1
  109.         #print t
  110.         print
  111.         update_list(items)
  112.     except: print ">>> Wrong Data Entry <<<"
  113. #
  114.  
  115. btn=Button(Frame2,text="Enter URL",width=16,command=url_text)
  116. btn.pack(side=LEFT)
  117.  
  118. url=StringVar()
  119. ent=Entry(Frame2,width="160",textvariable=url)
  120. ent.pack(side=LEFT)
  121.  
  122. cpb=Button(Frame3,text="Clipboard",width=16,command=from_clipboard)
  123. cpb.pack(side=LEFT)
  124.  
  125. lbl=Label(Frame3)
  126. lbl.pack(side=LEFT)
  127.  
  128. root.mainloop()
Add Comment
Please, Sign In to add comment