Advertisement
here2share

# Create_HTML_links.py

Apr 21st, 2017
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. # Create_HTML_links.py
  2.  
  3. import re
  4. import tempfile
  5. import webbrowser
  6. try:
  7.     # Python2
  8.     from Tkinter import *
  9.     from urllib2 import urlopen
  10. except ImportError:
  11.     # Python3
  12.     from tkinter import *
  13.     from urllib.request import urlopen
  14. #
  15.  
  16. srcfilename=tempfile.mktemp(".html", "demo_")
  17.  
  18. root=Tk()
  19. root.geometry('500x40+0+0')
  20. root.title('Create HTML links')
  21.  
  22. Frame3=LabelFrame(root,height=30,borderwidth=0)
  23. Frame3.pack(fill=X)
  24. Frame3.pack_propagate(False)
  25.  
  26. ok='''<a href="@" target="_blank">@</a>''' # alt to target="_self"
  27.  
  28. web="""<html>
  29. <head></head>
  30. <body>@</body>
  31. </html>"""
  32.  
  33. urls=[]
  34. def cpbd():
  35.     global urls
  36.     urls=root.clipboard_get().split('\n')
  37. #
  38. def hyperlinks():
  39.     global urls
  40.     cpbd()
  41.     t=[]
  42.     for url in urls:
  43.         url=url.strip()
  44.         url=ok.replace('@',url)
  45.         if url and url not in t: t.append(url)
  46.     urls='<br>'.join(t)
  47.     print urls
  48.     temp=open(srcfilename, 'w')
  49.     temp.write(web.replace('@',urls))
  50.     temp.close()
  51.     webbrowser.open_new_tab(srcfilename)
  52. #
  53. cpb=Button(Frame3,text="Links",width=16,command=hyperlinks)
  54. cpb.pack(side=LEFT)
  55.  
  56. lbl=Label(Frame3)
  57. lbl.pack(side=LEFT)
  58.  
  59. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement