Advertisement
here2share

# Tk_sort_web_images_by_height.py

Mar 7th, 2019
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.33 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. # Tk_google_images_sort_by_height.py
  3.  
  4. import re
  5. import tempfile
  6. import webbrowser
  7. import random
  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. #
  17.  
  18. srcfilename=tempfile.mktemp(".html", "demo_")
  19.  
  20. root=Tk()
  21. root.geometry('500x40+0+0')
  22. root.title('Google Images Sort By Height')
  23.  
  24. Frame3=LabelFrame(root,height=30,borderwidth=0)
  25. Frame3.pack(fill=X)
  26. Frame3.pack_propagate(False)
  27.  
  28. web="""<html>
  29. <head></head>
  30. <body>@</body>
  31. </html>"""
  32.  
  33. top=[[5120, 3200],
  34. [1800, 3200],
  35. [4096, 3072],
  36. [4500, 3000],
  37. [2000, 3000],
  38. [1440, 2960],
  39. [5120, 2880],
  40. [1800, 2880],
  41. [1620, 2880],
  42. [1440, 2880],
  43. [900, 2880],
  44. [1920, 2560],
  45. [1800, 2560],
  46. [1700, 2560],
  47. [1600, 2560],
  48. [1440, 2560],
  49. [1080, 2560],
  50. [1080, 2538],
  51. [1125, 2436],
  52. [3840, 2400],
  53. [3200, 2400],
  54. [1440, 2304],
  55. [5120, 2160],
  56. [4096, 2160],
  57. [3840, 2160],
  58. [3240, 2160],
  59. [1440, 2160],
  60. [1080, 2160],
  61. [2800, 2100],
  62. [3200, 2048],
  63. [2732, 2048],
  64. [2560, 2048],
  65. [1536, 2048],
  66. [1280, 2048],
  67. [1152, 2048],
  68. [1080, 2048],
  69. [3000, 2000],
  70. [2000, 2000],
  71. [2560, 1920],
  72. [1920, 1920],
  73. [1440, 1920],
  74. [1400, 1920],
  75. [1280, 1920],
  76. [1200, 1920],
  77. [1080, 1920],
  78. [1392, 1856],
  79. [2736, 1824],
  80. [3200, 1800],
  81. [2880, 1800],
  82. [2560, 1800],
  83. [1800, 1800],
  84. [1440, 1800],
  85. [1344, 1792],
  86. [1000, 1776],
  87. [2304, 1728],
  88. [2560, 1700],
  89. [1700, 1700],
  90. [1050, 1680],
  91. [2880, 1620],
  92. [1620, 1620],
  93. [3840, 1600],
  94. [2560, 1600],
  95. [1600, 1600],
  96. [1280, 1600],
  97. [1200, 1600],
  98. [1024, 1600],
  99. [900, 1600],
  100. [768, 1600],
  101. [2048, 1536],
  102. [2256, 1504],
  103. [3440, 1440],
  104. [2960, 1440],
  105. [2880, 1440],
  106. [2560, 1440],
  107. [2304, 1440],
  108. [2160, 1440],
  109. [1920, 1440],
  110. [1800, 1440],
  111. [1440, 1440],
  112. [1080, 1440],
  113. [1024, 1440],
  114. [960, 1440],
  115. [900, 1440],
  116. [1920, 1400],
  117. [1400, 1400],
  118. [1050, 1400],
  119. [1856, 1392],
  120. [768, 1366],
  121. [1792, 1344],
  122. [750, 1334],
  123. [2048, 1280],
  124. [1920, 1280],
  125. [1600, 1280],
  126. [1280, 1280],
  127. [1024, 1280],
  128. [960, 1280],
  129. [854, 1280],
  130. [800, 1280],
  131. [768, 1280],
  132. [1920, 1200],
  133. [1600, 1200],
  134. [1200, 1200],
  135. [1080, 1200],
  136. [800, 1200],
  137. [2048, 1152],
  138. [1152, 1152],
  139. [900, 1152],
  140. [864, 1152],
  141. [768, 1152],
  142. [2436, 1125],
  143. [1125, 1125],
  144. [832, 1120],
  145. [2560, 1080],
  146. [2538, 1080],
  147. [2160, 1080],
  148. [2048, 1080],
  149. [1920, 1080],
  150. [1440, 1080],
  151. [1200, 1080],
  152. [1080, 1080],
  153. [1680, 1050],
  154. [1400, 1050],
  155. [1050, 1050],
  156. [1600, 1024],
  157. [1440, 1024],
  158. [1280, 1024],
  159. [1024, 1024],
  160. [800, 1024],
  161. [768, 1024],
  162. [1776, 1000],
  163. [1000, 1000],
  164. [1440, 960],
  165. [1280, 960],
  166. [960, 960],
  167. [2880, 900],
  168. [1600, 900],
  169. [1440, 900],
  170. [1152, 900],
  171. [900, 900],
  172. [1152, 864],
  173. [864, 864],
  174. [1280, 854],
  175. [854, 854],
  176. [1120, 832],
  177. [832, 832],
  178. [1280, 800],
  179. [1200, 800],
  180. [1024, 800],
  181. [800, 800],
  182. [1600, 768],
  183. [1366, 768],
  184. [1280, 768],
  185. [1152, 768],
  186. [1024, 768],
  187. [768, 768],
  188. [1334, 750],
  189. [750, 750]]
  190.  
  191. def cpbd():
  192.     data=root.clipboard_get()
  193.     xfor='Search results for '
  194.     try:
  195.         x1=data.index(xfor)
  196.         x2=data.index(' on Yandex.Images')
  197.     except:
  198.         print "Invalid Entry"
  199.         return '',[]
  200.     search=data[x1+len(xfor):x2]
  201.     for z in '& amp;'.split():
  202.         search=search.replace(z,'')
  203.     search=search.replace('quot;','"')[1:-1]
  204.     print search
  205.     return search, data.split('.jpg","fileSizeInBytes":')[1:]
  206. #
  207. def hyperlinks():
  208.     def xypx(x,y):
  209.         if [x,y] not in ttt:
  210.             print x,y
  211.             print
  212.             ttt.append([x,y])
  213.     search,urls=cpbd()
  214.     ttt=top[:]
  215.     if urls:
  216.         for url in urls:
  217.             url=url.split('}')[0]
  218.             url=url.replace(',"w":','@')
  219.             url=url.replace(',"h":','@')
  220.             url=url.split('@')
  221.             w=int(url[1])
  222.             h=int(url[2])
  223.             if h > 749 and w > 249:
  224.                 xypx(w,h)
  225.                 if w > 749: xypx(h,w)
  226.         0
  227.         b='https://www.google.ca/search?q='
  228.         ttt.sort()
  229.         for t in range(len(ttt)):
  230.             h,w=ttt[t]
  231.             q=search.replace(' ','+')
  232.             q=q.replace('"','%22')
  233.             # if 'inurl:' not in q: q='inurl:'+q
  234.             ttt[t]='<a href="{0}{3}&tbs=isz:ex,iszw:{1},iszh:{2}&tbm=isch" target="_blank">{1}x{2}</a> * abroad'.format(b,w,h,q) # alt to target="_self"
  235.             ttt.append(ttt[t].replace(q,'inurl:'+q).replace('</a> * abroad','</a>'))
  236.         0
  237.         urls='<br>'.join(ttt[::-1])
  238.         temp=open(srcfilename, 'w')
  239.         temp.write(web.replace('@',urls))
  240.         temp.close()
  241.         webbrowser.open_new_tab(srcfilename)
  242. #
  243. cpb=Button(Frame3,text="Links",width=16,command=hyperlinks)
  244. cpb.pack(side=LEFT)
  245.  
  246. lbl=Label(Frame3)
  247. lbl.pack(side=LEFT)
  248.  
  249. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement