-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoath_window_pin.py
executable file
·90 lines (72 loc) · 3.12 KB
/
oath_window_pin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#last update:2014/10/10
import tweepy
import sys
import codecs
import os
import webbrowser
import wx
#.rstrip("\n")
sys.stdout = codecs.getwriter('utf_8')(sys.stdout)
global Verifier
Verifier=0
#GUIいじりその1----------------------------------------------------------------------------------------------------------------------------
applicationoath = wx.App()
frame = wx.Frame(None,wx.ID_ANY,u"認証", style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN,size=(400,225))#デフォは横400、たて220ちょい
frame.SetBackgroundColour("#e8e8e8")
panel = wx.Panel(frame,wx.ID_ANY,pos=(50,80),size=(300,30))
text = wx.TextCtrl(panel,wx.ID_ANY,u"ブラウザに表示されるPIN番号を入力してください",size=(300,20))
#GUIいじりその1-----------------------------------------------------------------------------------------------------------------------------------
def pinsend(event):
global Verifier
Verifier=text.GetValue()
print text.GetValue()
wx.Exit()
frame.Destroy()
#Close()
def oath(CK,CS):
auth = tweepy.OAuthHandler(CK, CS)
access=os.path.exists("./access.txt")
if access==False:
try:
redirect_url = auth.get_authorization_url()
print "Redirect URL: " + redirect_url
webbrowser.open(redirect_url)
except tweepy.TweepError:
print "Error! Failed to get request token."
# Example w/o callback (desktop)
#verifier = raw_input("Verifier: ")
# Get access token
if access==False:
#verifier = raw_input("Verifier: ")
#----------------------------------------------GUIいじり2---------------------------------------------------------------------------
PIN_panel = wx.Panel(frame,wx.ID_ANY,pos=(160,150),size=(80,20))
button_PIN = wx.Button(PIN_panel,wx.ID_ANY,u"送信",size=(80,20))
#Verifier=text.GetValue()
button_PIN.Bind(wx.EVT_BUTTON,pinsend)
frame.Show()
applicationoath.MainLoop()
#-----------------------------------------------GUIいじり2-------------------------------------------------------------------------------
print Verifier
auth.get_access_token(Verifier)
key=auth.access_token.key
f = open("access.txt", "a")
f.write(key.encode('base64'))
f.close()
key = auth.access_token.key
print "OAuth access token (key): " + key
secret = auth.access_token.secret
f = open("access.txt", "a")
f.write(secret.encode('base64'))
f.close()
print "OAuth access token (secret): " + secret
else:
f = open("access.txt","r")
line=f.readlines()
key,secret=line[0].rstrip("\n"),line[1]
key=key.decode('base64')
secret=secret.decode('base64')
f.close()
return key,secret
#auth.set_access_token(oath(consumer_key,consumer_secret))これはダメ(返り値が二つの値のペアになってるため?)