Advertisement
here2share

# Tk_pinterest_monthly_link_automator.py

Dec 10th, 2016
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. # Tk_pinterest_monthly_link_automator.py
  2. # as launched March 2010
  3.  
  4. try:
  5.     # Python2
  6.     from Tkinter import *
  7.     from urllib2 import urlopen
  8. except ImportError:
  9.     # Python3
  10.     from tkinter import *
  11.     from urllib.request import urlopen
  12. import webbrowser
  13. import time
  14. from datetime import datetime, timedelta
  15. import tempfile
  16. srcfilename=tempfile.mktemp(".html", "demo_")
  17.  
  18. web="""<!DOCTYPE html><b>@"""
  19.  
  20. root=Tk()
  21. root.geometry('270x24+0+0')
  22. root.title('Pinterest Monthly')
  23.  
  24. w='300'
  25. h='750'
  26. def url_text():
  27.     html='https://www.google.ca/search?q=site%3Apinterest.com+glamour+face'
  28.     td=datetime.now()
  29.     # max='%s-%s-%s' %(td.year,td.month,td.day)
  30.     links=[]
  31.     line=''
  32.     mm=td.month
  33.     yy=td.year
  34.     while 1:
  35.         mm-=1
  36.         if not mm:
  37.             mm=12
  38.             yy-=1
  39.         if (yy <= 2010 and mm < 3) or len(links) > 10000: break
  40.         ttt='%02d-%02d' %(yy,mm)
  41.         tmp=html+'&hl=en&biw=1361&bih=604&tbs=cdr:1,cd_min:'+ttt+'-01,cd_max:'+ttt+'-15,isz:l&tbm=isch'
  42.         tmp="<a href='"+tmp+"'>"+ttt+"</a>&nbsp;&nbsp;"
  43.         tx=datetime(yy,mm,1)+timedelta(days=32)
  44.         tx=str(datetime(tx.year,tx.month,1)-timedelta(days=1))[:10]
  45.         ttt=html+'&hl=en&biw=1361&bih=604&tbs=cdr:1,cd_min:'+ttt+'-16,cd_max:'+tx+',isz:l&tbm=isch'
  46.         line+=tmp+"<a href='"+ttt+"'>+</a>"
  47.         if mm in (1,7):
  48.             links.append(line); line=''
  49.         else: line+='&nbsp;&nbsp;&nbsp;&nbsp;'
  50.  
  51.     print len(links)
  52.     links='<br><br>'.join(links)
  53.     temp=open(srcfilename, 'w')
  54.     temp.write(web.replace('@',links))
  55.     temp.close()
  56.     webbrowser.open_new_tab(srcfilename)
  57. #
  58.  
  59. btn=Button(root,text="Show List",width=8,command=url_text)
  60. btn.pack(side=LEFT)
  61.  
  62. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement