def __init__(self): global current_dir global target_dir current_dir = os.path.dirname(os.path.abspath(__file__)) target_dir = current_dir + "/tweetiton/" global api QtGui.QWidget.__init__(self) self.ui = Ui_Form() self.ui.setupUi(self) self.setWindowTitle("Please authorize the application") self.btn = self.ui.pushButton consumer_key='XYfKbAUjpylvR80ySI7veg' consumer_secret='BlSFRfv2Ty4VI5LuZkCvcaOtCXLvkUxu6AIJumJTIJ4' self.auth = tweepy.OAuthHandler(consumer_key,consumer_secret) self.auth_url = self.auth.get_authorization_url() self.ui.webView.setUrl(QtCore.QUrl(self.auth_url)) QtCore.QObject.connect(self.ui.lineEdit, QtCore.SIGNAL("textChanged(QString)"), self.enable_button) QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.get_tokens)
class MyForm(QtGui.QWidget): def __init__(self): global current_dir global target_dir current_dir = os.path.dirname(os.path.abspath(__file__)) target_dir = current_dir + "/tweetiton/" global api QtGui.QWidget.__init__(self) self.ui = Ui_Form() self.ui.setupUi(self) self.setWindowTitle("Please authorize the application") self.btn = self.ui.pushButton consumer_key='XYfKbAUjpylvR80ySI7veg' consumer_secret='BlSFRfv2Ty4VI5LuZkCvcaOtCXLvkUxu6AIJumJTIJ4' self.auth = tweepy.OAuthHandler(consumer_key,consumer_secret) self.auth_url = self.auth.get_authorization_url() self.ui.webView.setUrl(QtCore.QUrl(self.auth_url)) QtCore.QObject.connect(self.ui.lineEdit, QtCore.SIGNAL("textChanged(QString)"), self.enable_button) QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.get_tokens) def enable_button(self): self.btn.setEnabled(True) a = len(self.ui.lineEdit.text()) if a == 0: self.btn.setEnabled(False) def get_tokens(self): a = self.ui.lineEdit.text() self.auth.get_access_token(a) access_key = self.auth.access_token.key access_secret = self.auth.access_token.secret os.makedirs(target_dir) FILE = open("access_channel", "w") write_this = access_key + "\n" + access_secret FILE.write(write_this) FILE.close() file_a = current_dir + "/access_channel" shutil.move(file_a,target_dir) self.set_tokens(1) def set_tokens(self,para): file_a = target_dir + "access_channel" FILE = open(file_a, "r") access_key = FILE.readline() access_key = access_key.strip() access_secret = FILE.readline() access_secret = access_secret.strip() self.auth.set_access_token(access_key,access_secret) global api api = tweepy.API(self.auth) self.final_step(para) def return_api(self): return api def final_step(self, para): if para == 0: self.close() app2 = one.MyForm1() app2.show() appli = QtGui.QApplication.instance() sys.exit(appli.exec_()) else: self.close() app2 = one.MyForm1() app2.show() sys.exit(appli.exec_())