#coding: utf-8
import twitter
from t_key import tw_key
import wx
import urllib, urllib2
import os
import threading
api = twitter.Api(
consumer_key = tw_key['cons_key'],
consumer_secret = tw_key['cons_sec'],
access_token_key = tw_key['acc_token'],
access_token_secret = tw_key['acc_sec'],
cache = None)
class myFrame(wx.Frame):
def __init__(self, parent, title, file_pos):
wx.Frame.__init__(self, parent, title=title)
image = wx.Image(file_pos)
self.bitmap = image.ConvertToBitmap()
wx.StaticBitmap(self, -1, self.bitmap, (0,0), self.GetClientSize())
self.SetSize(image.GetSize())
class pict_thread(threading.Thread):
def __init__(self, file_name, file_pos):
threading.Thread.__init__(self)
self.file_name = file_name
self.file_pos = file_pos
def run(self):
picture_frame(self.file_name, self.file_pos)
def picture_frame(file_name, file_pos):
print file_name
print file_pos
app = wx.App(False)
frame = myFrame(None, file_name, file_pos)
frame.Show()
app.MainLoop()
def main():
try:
timeline = api.GetHomeTimeline()
except:
print 'Rate Limit exceeded'
cwd = os.getcwd()
# 鍵垢は読み取れないが特に支障もないので放置
for tweet in timeline:
user_name = tweet.user.name.encode('utf-8')
post_time = tweet.created_at
text = tweet.text.encode('utf-8')
print "----{0}({1})----\n{2}\n".format(user_name, post_time, text)
if 'http' in text:
url_pos = text.find('http')
url = text[url_pos:]
try:
page = urllib2.urlopen(url)
except:
pass
else:
if 'twitter.com' in page.geturl():
html_data = page.read()
file_start = html_data.find('https://p...content-available-to-author-only...g.com/media/')
if not file_start == -1:
file_end = html_data.find(':large')
file_url = html_data[file_start:file_end]
print file_url
file_name = file_url[file_url.rfind('/')+1:]
file_pos = cwd+'/'+file_name
urllib.urlretrieve(file_url, file_pos)
#picture_frame(file_name, file_pos)
# ↓ここが問題
thread = pict_thread(file_name, file_pos)
thread.setDaemon(True)
thread.start()
if __name__ == '__main__':
main()
I2NvZGluZzogdXRmLTgKCmltcG9ydCB0d2l0dGVyCmZyb20gdF9rZXkgaW1wb3J0IHR3X2tleQppbXBvcnQgd3gKaW1wb3J0IHVybGxpYiwgdXJsbG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AgZWxzZTogCiAgICAgICAgICAgICAgICBpZiAndHdpdHRlci5jb20nIGluIHBhZ2UuZ2V0dXJsKCk6CiAgICAgICAgICAgICAgICAgICAgaHRtbF9kYXRhID0gcGFnZS5yZWFkKCkKICAgICAgICAgICAgICAgICAgICBmaWxlX3N0YXJ0ID0gaHRtbF9kYXRhLmZpbmQoJ2h0dHBzOi8vcC4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci1vbmx5Li4uZy5jb20vbWVkaWEvJykKICAgICAgICAgICAgICAgICAgICBpZiBub3QgZmlsZV9zdGFydCA9PSAtMToKICAgICAgICAgICAgICAgICAgICAgICAgZmlsZV9lbmQgPSBodG1sX2RhdGEuZmluZCgnOmxhcmdlJykKICAgICAgICAgICAgICAgICAgICAgICAgZmlsZV91cmwgPSBodG1sX2RhdGFbZmlsZV9zdGFydDpmaWxlX2VuZF0KICAgICAgICAgICAgICAgICAgICAgICAgcHJpbnQgZmlsZV91cmwKICAgICAgICAgICAgICAgICAgICAgICAgZmlsZV9uYW1lID0gZmlsZV91cmxbZmlsZV91cmwucmZpbmQoJy8nKSsxOl0KICAgICAgICAgICAgICAgICAgICAgICAgZmlsZV9wb3MgPSBjd2QrJy8nK2ZpbGVfbmFtZQogICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgdXJsbGliLnVybHJldHJpZXZlKGZpbGVfdXJsLCBmaWxlX3BvcykKICAgICAgICAgICAgICAgICAgICAgICAgI3BpY3R1cmVfZnJhbWUoZmlsZV9uYW1lLCBmaWxlX3BvcykKICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICMg4oaT44GT44GT44GM5ZWP6aGMCiAgICAgICAgICAgICAgICAgICAgICAgIHRocmVhZCA9IHBpY3RfdGhyZWFkKGZpbGVfbmFtZSwgZmlsZV9wb3MpCiAgICAgICAgICAgICAgICAgICAgICAgIHRocmVhZC5zZXREYWVtb24oVHJ1ZSkKICAgICAgICAgICAgICAgICAgICAgICAgdGhyZWFkLnN0YXJ0KCkKCmlmIF9fbmFtZV9fID09ICdfX21haW5fXyc6CiAgICBtYWluKCkK