def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.search_on = False self.ui = Ui_LR_Twitter_Dialog() self.ui.setupUi(self) self.ui.run_button.clicked.connect(self.startSearch) self.ui.stop_button.toggled.connect(self.stopSearch) self.searchTableModel = MyTableModel() self.ui.searchTableView.setModel(self.searchTableModel) self.search_worker = SearchWorker(self.searchUpdates) self.started_following_search = False ## connecting streaming search tab self.streaming_results_model = StreamModel() self.streamer = LRStream(self.streaming_results_model) self.streaming_on = False self.streaming_worker = StreamWorker() self.ui.filter1.editingFinished.connect(self.updateFilter1) self.ui.filter2.editingFinished.connect(self.updateFilter2) self.ui.filter3.editingFinished.connect(self.updateFilter3) self.ui.start_streaming.clicked.connect(self.startStreaming) self.ui.stop_streaming.clicked.connect(self.stopStreaming) self.ui.follow_streaming.clicked.connect(self.followStreamResults) self.ui.tweet_streaming.clicked.connect(self.tweetStreamResults) self.ui.tweet_at_streaming.clicked.connect(self.tweetAtStreamResults) self.ui.reply_to_streaming.clicked.connect(self.replyToStreamResults) self.ui.retweet_streaming.clicked.connect(self.retweetStreamResults) self.ui.random_interaction_streaming.clicked.connect(self.randomActionStreamResults) ## connecting setup tab (overlap not yet functional # self.ui.calc_overlap_button.clicked.connect(self.followersOverlapUpdate) self.ui.my_account.editingFinished.connect(self.setupMyUsername) if self.ui.my_account.text() != '': self.setupMyUsername() self.ui.user_account.editingFinished.connect(self.otherUserInfo) self.engine_set = False
class MainApp(QtGui.QDialog): def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.search_on = False self.ui = Ui_LR_Twitter_Dialog() self.ui.setupUi(self) self.ui.run_button.clicked.connect(self.startSearch) self.ui.stop_button.toggled.connect(self.stopSearch) self.searchTableModel = MyTableModel() self.ui.searchTableView.setModel(self.searchTableModel) self.search_worker = SearchWorker(self.searchUpdates) self.started_following_search = False ## connecting streaming search tab self.streaming_results_model = StreamModel() self.streamer = LRStream(self.streaming_results_model) self.streaming_on = False self.streaming_worker = StreamWorker() self.ui.filter1.editingFinished.connect(self.updateFilter1) self.ui.filter2.editingFinished.connect(self.updateFilter2) self.ui.filter3.editingFinished.connect(self.updateFilter3) self.ui.start_streaming.clicked.connect(self.startStreaming) self.ui.stop_streaming.clicked.connect(self.stopStreaming) self.ui.follow_streaming.clicked.connect(self.followStreamResults) self.ui.tweet_streaming.clicked.connect(self.tweetStreamResults) self.ui.tweet_at_streaming.clicked.connect(self.tweetAtStreamResults) self.ui.reply_to_streaming.clicked.connect(self.replyToStreamResults) self.ui.retweet_streaming.clicked.connect(self.retweetStreamResults) self.ui.random_interaction_streaming.clicked.connect(self.randomActionStreamResults) ## connecting setup tab (overlap not yet functional # self.ui.calc_overlap_button.clicked.connect(self.followersOverlapUpdate) self.ui.my_account.editingFinished.connect(self.setupMyUsername) if self.ui.my_account.text() != '': self.setupMyUsername() self.ui.user_account.editingFinished.connect(self.otherUserInfo) self.engine_set = False def updateFilter1(self): pass def updateFilter2(self): pass def updateFilter3(self): pass def followStreamResults(self): pass def tweetStreamResults(self): pass def tweetAtStreamResults(self): pass def replyToStreamResults(self): pass def retweetStreamResults(self): pass def randomActionStreamResults(self): funcs = [self.followStreamResults, self.tweetStreamResults, self.tweetAtStreamResults, self.replyToStreamResults, self.retweetStreamResults] funcs[random.randint(0, len(funcs))]() def followSearchResults(self): if not self.follow_on: print 'following results...' self.followWorker.setup(self.twitterEngine) def updateSearchOptions(self): self.twitterEngine.options.userId = self.ui.usernameLineEdit.text() self.twitterEngine.options.usernameUpdated = self.ui.usernameLineEdit.text() != '' self.twitterEngine.options.outputFile = self.ui.filenameLineEdit.text() self.twitterEngine.options.filenameUpdated = self.ui.filenameLineEdit.text() != '' num = self.ui.max_followers_box.value() self.twitterEngine.options.followSizes[1] = num if num < self.twitterEngine.options.followSizes[0]: self.ui.min_followers_box.setValue(self.twitterEngine.options.followSizes[1]) num = self.ui.min_followers_box.value() self.twitterEngine.options.followSizes[0] = num if num > self.twitterEngine.options.followSizes[1]: self.ui.max_followers_box.setValue(self.twitterEngine.options.followSizes[0]) self.twitterEngine.options.imNotFollowing = self.ui.im_not_following_checkbox.isChecked() self.twitterEngine.options.notFollowingMe = self.ui.not_following_me_checkbox.isChecked() self.twitterEngine.options.havePicture = self.ui.has_picture_checkbox.isChecked() self.twitterEngine.options.tweetsPerDay = max(0, self.ui.min_tweets_box.value()) def startSearch(self): if not self.search_on and self.search_worker: print 'running...' self.searchTableModel.clear() self.search_worker.update_emitter.connect(self.searchUpdates) def outputFunc(s, caller): print s self.updateSearchOptions() self.search_worker.outputFunc = functools.partial(outputFunc, caller=self) self.search_worker.setup(self.twitterEngine) self.search_on = True elif not self.search_on: print 'already running search!' else: print 'no twitter API authenticated!' def searchUpdates(self, newdata): for row in newdata[2:]: self.searchTableModel.appendRowWithData(row) self.ui.rate_label.setText('Filter Rate: %0.1f%%' % newdata[1]) def stopSearch(self): if self.search_on: print 'stopping search...' self.search_worker.stop() self.search_worker.exit() self.search_on = False else: print 'already stopped search!' def startStreaming(self): if not self.streaming_on: print 'starting streaming...' self.streaming_results_model.clearAllData() self.stream_worker.update_emitter.connect(self.streamUpdates) self.stream_worker.setup(self.twitterEngine, Stream(self.engine.getAuth(), self.streamer)) self.streaming_on = True else: print 'already running streaming!' def stopStreaming(self): if self.streaming_on: print 'stopping streaming...' self.streaming_worker.stop() self.streaming_worker.exit() self.streaming_on = False else: print 'already stopped streaming!' def setupMyUsername(self): self.current_username = self.ui.my_account.text() try: self.twitterEngine = RealTweet( str(self.current_username) ) self.engine_set = True self.ui.my_account.setStyleSheet(QtCore.QString.fromUtf8("background-color: rgb(0, 255, 25);")) self.ui.user_account.setReadOnly(False) self.ui.my_no_followers.setText( str(self.twitterEngine.user.followers_count) ) self.ui.my_no_following.setText( str(self.twitterEngine.user.friends_count) ) rls = self.twitterEngine.api.rate_limit_status() self.ui.api_status_friendships.setText( '%s friendships' % self.rateLimitToText(rls, 'resources', 'friendships', 'lookup') ) self.ui.api_status_followers.setText( '%s follower ids' % self.rateLimitToText(rls, 'resources', 'followers', 'ids') ) self.ui.api_status_timelines.setText( '%s status timelines' % self.rateLimitToText(rls, 'resources', 'statuses', 'user_timeline') ) self.ui.api_status_users.setText( '%s user lookups' % self.rateLimitToText(rls, 'resources', 'users', 'search') ) except: print 'could not connect a twitter engine with user %s; try again' % str(self.current_username) self.engine_set = False def otherUserInfo(self): other_sn = self.ui.user_account.text() if other_sn != '': other_user = self.twitterEngine.api.get_user( other_sn ) self.ui.user_no_followers.setText( str(other_user.followers_count) ) self.ui.user_following.setText( str(other_user.friends_count) ) self.ui.user_profile.setText(other_user.description) self.ui.user_tweets_per_day.setText( '%.2f' % self.twitterEngine.tweetFrequency(other_user) ) tweets = [status.text for status in other_user.timeline()[0:3]] self.ui.last_tweets.setText( '\n----------\n'.join(tweets) ) else: print 'no screen name entered' def followersOverlapUpdate(self): other_sn = str(self.ui.user_account.text()) if other_sn != '': other_user = self.twitterEngine.api.get_user(other_sn) self.ui.pct_followers_overlap.setText( '%.2f\%' % self.twitterEngine.pctFollowerIntersect(self.twitterEngine.user, other_user) ) else: print 'no screen name set for other user' @staticmethod def rateLimitToText(rate_limit, depth1, depth2, depth3 ): depth3 = '/%s/%s' % (depth2, depth3) return '%i/%i remaining' % (rate_limit[depth1][depth2][depth3]['remaining'], rate_limit[depth1][depth2][depth3]['limit']) def exitApp(self): pass