fork(2) download
  1. # -*- coding: utf-8 -*-
  2. """ Parser image from 2ch """
  3.  
  4. import urllib
  5. import json
  6. from Tkinter import *
  7. import ttk
  8.  
  9.  
  10. def check_value(er=1):
  11. if not entry1.get():
  12. label1['text'] = u"Enter url"
  13. elif not '2ch.hk' in entry1.get():
  14. label1['text'] = u"Enter url 2ch.hk v1"
  15. else:
  16. parser()
  17.  
  18. def parser():
  19. try:
  20. urli = entry1.get().replace('html','json')
  21. req = json.load(urllib.urlopen(urli))
  22. thread = req['threads'][0]['posts']
  23.  
  24. l = []
  25. for x in thread:
  26. if ('files' in x) and (('png' in x['files'][0]['path']) or ('jpg' in x['files'][0]['path'])):
  27. l.append(urli[:urli.index('hk/')+3] + urli[urli.index('hk/')+3:].split('/',1)[0] + '/' + x['files'][0]['path'])
  28. #print urli[:urli.index('hk/')+3] + urli[urli.index('hk/')+3:].split('/',1)[0] + '/' + x['files'][0]['path']
  29. label1['text'] = 'open ' + str(urli[:urli.index('hk/')+3] + urli[urli.index('hk/')+3:].split('/',1)[0] + '/' + x['files'][0]['path'])
  30. root.update()
  31. for x in l:
  32. label1['text'] = 'download ' + str(x)
  33. urllib.urlretrieve(x, x.rsplit('/',1)[1])
  34. root.update()
  35.  
  36.  
  37. label1.configure(text = "Good work")
  38.  
  39. #label1.after(200, label1.configure(text = "Enter url"))
  40.  
  41. #label1.after(2000, label1.configure(text = "Enter url"))
  42. root.update()
  43. except:
  44. label1['text'] = "Dont open url"
  45.  
  46.  
  47.  
  48.  
  49. root=Tk()
  50. root.title("2ch parser image")
  51. root.minsize(width = 300, height = 185)
  52.  
  53. fra1 = Frame(root,width=300,height=30)
  54. fra1.pack()
  55.  
  56. # input field------------------------------------------------
  57.  
  58. #text1=Text(root,height=7,width=7,font='Arial 14',wrap=WORD)
  59. entry1 = Entry(root, width=25, font='Arial 14')
  60. entry1.focus()
  61. entry1.bind('<Return>', check_value)
  62. entry1.pack()#pack
  63.  
  64.  
  65. # output field------------------------------------------------
  66. label1 = Label(root, text = u"Enter url", font='arial 7', relief ='groove', width=46)
  67. label1.pack()#pack
  68.  
  69.  
  70. fra2 = Frame(root,width=300,height=30)
  71. fra2.pack()
  72.  
  73.  
  74. # button------------------------------------------------------
  75. button1 = Button(root, text=u"parser",font='arial 12', command=check_value)
  76.  
  77. button1.pack()#pack
  78.  
  79.  
  80. fra3 = Frame(root,width=300,height=30)
  81. fra3.pack()
  82.  
  83. label2 = Label(root, text = u"s0k1ll", font='arial 7')
  84. label2.pack(side='left')#pack
  85. # run main loop-----------------------------------------------
  86. root.mainloop()
  87.  
Runtime error #stdin #stdout #stderr 0.24s 29136KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 49, in <module>
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1712, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable