fork download
  1. #coding: utf-8
  2.  
  3. import twitter
  4. from t_key import tw_key
  5. import wx
  6. import urllib, urllib2
  7. import os
  8. import threading
  9.  
  10. api = twitter.Api(
  11. consumer_key = tw_key['cons_key'],
  12. consumer_secret = tw_key['cons_sec'],
  13. access_token_key = tw_key['acc_token'],
  14. access_token_secret = tw_key['acc_sec'],
  15. cache = None)
  16.  
  17. class myFrame(wx.Frame):
  18. def __init__(self, parent, title, file_pos):
  19. wx.Frame.__init__(self, parent, title=title)
  20. image = wx.Image(file_pos)
  21. self.bitmap = image.ConvertToBitmap()
  22. wx.StaticBitmap(self, -1, self.bitmap, (0,0), self.GetClientSize())
  23. self.SetSize(image.GetSize())
  24.  
  25. class pict_thread(threading.Thread):
  26. def __init__(self, file_name, file_pos):
  27. threading.Thread.__init__(self)
  28. self.file_name = file_name
  29. self.file_pos = file_pos
  30.  
  31. def run(self):
  32. picture_frame(self.file_name, self.file_pos)
  33.  
  34.  
  35. def picture_frame(file_name, file_pos):
  36. print file_name
  37. print file_pos
  38. app = wx.App(False)
  39. frame = myFrame(None, file_name, file_pos)
  40. frame.Show()
  41. app.MainLoop()
  42.  
  43. def main():
  44. try:
  45. timeline = api.GetHomeTimeline()
  46. except:
  47. print 'Rate Limit exceeded'
  48.  
  49. cwd = os.getcwd()
  50.  
  51. # 鍵垢は読み取れないが特に支障もないので放置
  52. for tweet in timeline:
  53. user_name = tweet.user.name.encode('utf-8')
  54. post_time = tweet.created_at
  55. text = tweet.text.encode('utf-8')
  56. print "----{0}({1})----\n{2}\n".format(user_name, post_time, text)
  57.  
  58. if 'http' in text:
  59. url_pos = text.find('http')
  60. url = text[url_pos:]
  61. try:
  62. page = urllib2.urlopen(url)
  63. except:
  64. pass
  65. else:
  66. if 'twitter.com' in page.geturl():
  67. html_data = page.read()
  68. file_start = html_data.find('https://p...content-available-to-author-only...g.com/media/')
  69. if not file_start == -1:
  70. file_end = html_data.find(':large')
  71. file_url = html_data[file_start:file_end]
  72. print file_url
  73. file_name = file_url[file_url.rfind('/')+1:]
  74. file_pos = cwd+'/'+file_name
  75.  
  76. urllib.urlretrieve(file_url, file_pos)
  77. #picture_frame(file_name, file_pos)
  78.  
  79. # ↓ここが問題
  80. thread = pict_thread(file_name, file_pos)
  81. thread.setDaemon(True)
  82. thread.start()
  83.  
  84. if __name__ == '__main__':
  85. main()
  86.  
Runtime error #stdin #stdout #stderr 0.01s 7848KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 3, in <module>
ImportError: No module named twitter