Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_google_image_search_link_automator.py ^ 2016.01
- import re
- def xdates(z):
- r=re.findall('(?:19|20)\d\d-(?:[0][1-9]|[1][012])-(?:[0][1-9]|[12]\d|[3][01])',z)
- return r
- try:
- # Python2
- from Tkinter import *
- from urllib2 import urlopen
- except ImportError:
- # Python3
- from tkinter import *
- from urllib.request import urlopen
- import webbrowser
- import time
- from datetime import datetime
- html='?????'
- zmax=''
- w,h = '299','749'
- root=Tk()
- root.geometry('1280x654+0+0')
- root.title('Google Image Search Link Automator')
- topFrame=LabelFrame(root,text="",height=600)
- topFrame.pack(fill=X)
- topFrame.pack_propagate(False)
- Frame2=LabelFrame(root,height=24,borderwidth=0)
- Frame2.pack(fill=X)
- Frame2.pack_propagate(False)
- Frame3=LabelFrame(root,height=30,borderwidth=0)
- Frame3.pack(fill=X)
- Frame3.pack_propagate(False)
- ffff=Listbox(topFrame,selectmode=SINGLE)
- ffff.pack(fill=BOTH,expand=YES,side=LEFT)
- ffff.configure(selectmode=SINGLE)
- def dblclk(event):
- html=ffff.curselection()
- html=links[int(html[0])]
- webbrowser.open(html)
- ffff.bind("<Double-Button-1>", dblclk)
- scroll=Scrollbar(topFrame)
- scroll.pack(side=RIGHT,fill=Y,expand=NO)
- scroll.configure(command=ffff.yview)
- ffff.configure(yscrollcommand=scroll.set)
- items=[]
- links=[]
- #
- def update_list(items):
- ffff.delete(0, END)
- for item in items:
- ffff.insert(END,item)
- root.update()
- update_list(items) # None
- #
- def from_clipboard():
- data = root.clipboard_get()
- url.set(data)
- root.update()
- url_text()
- #
- def url_text():
- global html, links, items
- html=url.get()
- #print html
- print
- try:
- zmax=min(xdates(html))
- #print zmax
- except:
- print "!!! timestamp not found -- default now set"
- td=datetime.now()
- zmax='%s-%s-%s' %(td.year,td.month,td.day)
- ### s1='https://www.google.com/search?q='
- s2='&newwindow=1&biw=1354&bih=637&source=lnt&tbs=isz%3Al%2Ccdr%3A1%2Ccd_min%3A'
- s3='%2Ccd_max%3A'
- s4='&tbm=isch'
- links=[]
- items=[]
- t=''
- i=2
- year,month,day=zmax.split('-')
- try:
- req=html.split('&gs_l=img.')[0]
- req.split('&newwindow=')[0]
- print req
- while 1:
- yr,mo=divmod(int(month)+(int(year)*12)-i, 12)
- if yr < 1992 or len(links) > 399: break
- zmin='%s-%s-01' %(yr,mo+1)
- link=req+s2+zmin+s3+zmax+s4
- #print link
- links.append(link)
- items.append(zmin+" >>> "+zmax)
- t+=link+'\n\n'
- zmax=zmin
- i+=1
- #print t
- print
- update_list(items)
- except: print ">>> Wrong Data Entry <<<"
- #
- btn=Button(Frame2,text="Enter URL",width=16,command=url_text)
- btn.pack(side=LEFT)
- url=StringVar()
- ent=Entry(Frame2,width="160",textvariable=url)
- ent.pack(side=LEFT)
- cpb=Button(Frame3,text="Clipboard",width=16,command=from_clipboard)
- cpb.pack(side=LEFT)
- lbl=Label(Frame3)
- lbl.pack(side=LEFT)
- root.mainloop()
Add Comment
Please, Sign In to add comment