class twtrManager(StreamListener): """ A listener handles tweets that are received from the stream. This is a basic listener that just prints received tweets to stdout. """ def on_status(self, status): self.db_manager = DatabaseManager(self) screenName = status.author.screen_name createDate = str(status.created_at) txt = status.text # self.db_manager.storeTweets(screenName,txt,createDate) check = self.db_manager.checkTweets(screenName,txt,createDate) if (check): #If not, add to DB self.db_manager.storeTweets(screenName,txt,createDate) self.sendTweet(txt) # print(status.author.screen_name) # print(str(status.created_at)) print(txt) return True def on_error(self, status): print(status) def sendTweet(self, text): # api.update_status("@" + usr + " " + text) print "demo!" # print ("@" + usr + " " + text) print text return
class twtrManager: def __init__(self): self.db_manager = DatabaseManager(self) self.main() def main(self): ckey = 'rlee33vXmHIlmR5tQljIX0ucD' csecret = 'cUiIFESIXSSin9YJHYwLnVwnHpS64Ytj7csY9yFqshvAlkcaPg' atoken = '2836017980-DxYDsgHqGMyRIq1yH3Uf3Ar63eYCFhqawJAWGOw' asecret = 'SruNXYjh0BpY4GQhiflXaxbB2XUhrCMslBrmrH2ViULnu' auth = tweepy.OAuthHandler(ckey, csecret) auth.set_access_token(atoken, asecret) api = tweepy.API(auth) auth = OAuthHandler(ckey, csecret) def homeTimeline(self): while True: ckey = 'rlee33vXmHIlmR5tQljIX0ucD' csecret = 'cUiIFESIXSSin9YJHYwLnVwnHpS64Ytj7csY9yFqshvAlkcaPg' atoken = '2836017980-DxYDsgHqGMyRIq1yH3Uf3Ar63eYCFhqawJAWGOw' asecret = 'SruNXYjh0BpY4GQhiflXaxbB2XUhrCMslBrmrH2ViULnu' auth = tweepy.OAuthHandler(ckey, csecret) auth.set_access_token(atoken, asecret) api = tweepy.API(auth) auth = OAuthHandler(ckey, csecret) timeline=api.home_timeline(COUNT=0) try: for tweet in timeline: user=tweet.user name=tweet.user.name.encode('utf-8') text=tweet.text.encode('utf-8') date=tweet.created_at if "@DunSuciRun" in text: #checks if special text in field text = text[11:] check = self.db_manager.checkTweets(name, text, date) if (check): #If not, add to DB self.db_manager.storeTweets(name, text, date) return text break else: print "wait a minute" time.sleep(60) pass else: print "nothing valid. Waiting" time.sleep(60) pass except Exception, e: print "not valid. Lets wait a minute!" time.sleep(60) pass return text
def on_status(self, status): self.db_manager = DatabaseManager(self) self.game_manager = GameManager() # Status object holds all twitter user info objects screenName = status.author.screen_name createDate = str(status.created_at) txt = status.text txt = txt.replace("@DunSuRu","") print(txt) try: # Takes data and starts new thread. th = threading.Thread(target=self.handleChoice(txt, screenName,createDate,)) th.start() except: print("unable to start thread")
def on_status(self, status): self.db_manager = DatabaseManager(self) self.game_manager = GameManager() # Status object holds all twitter user info objects screenName = status.author.screen_name createDate = str(status.created_at) txt = status.text txt = txt.replace("@DunSuRu", "") print(txt) try: # Takes data and starts new thread. th = threading.Thread(target=self.handleChoice(txt, screenName, createDate)) th.start() except: print("unable to start thread")
def on_status(self, status): self.db_manager = DatabaseManager(self) screenName = status.author.screen_name createDate = str(status.created_at) txt = status.text # self.db_manager.storeTweets(screenName,txt,createDate) check = self.db_manager.checkTweets(screenName,txt,createDate) if (check): #If not, add to DB self.db_manager.storeTweets(screenName,txt,createDate) self.sendTweet(txt) # print(status.author.screen_name) # print(str(status.created_at)) print(txt) return True
class twtrManager(StreamListener): # def __init__(self): # self.db_manager = DatabaseManager(self) # self.game_manager = GameManager() """ A listener handles tweets that are received from the stream. This is a basic listener that just prints received tweets to stdout. # """ def on_status(self, status): self.db_manager = DatabaseManager(self) self.game_manager = GameManager() # Status object holds all twitter user info objects screenName = status.author.screen_name createDate = str(status.created_at) txt = status.text txt = txt.replace("@DunSuRu","") print(txt) try: # Takes data and starts new thread. th = threading.Thread(target=self.handleChoice(txt, screenName,createDate,)) th.start() except: print("unable to start thread") def on_error(self, status): print(status) def handleChoice(self, input, userName,createDate): check = self.db_manager.checkTweets(userName,input,createDate) if (check): #If not, add to DB self.db_manager.storeTweets(userName,input,createDate) choice = input.lower() while True: if "new" in choice or "begin" in choice or "start" in choice: reslt = self.game_manager.new_game(userName) elif "about" in choice or "info" in choice or "information" in choice or "what" in choice: reslt = self.game_manager.instructions(userName) elif "who" in choice: reslt = self.game_manager.player_stats(userName) elif "continue" in choice: rndchoice = random.randint(0,4) if rndchoice == 0: reslt = self.game_manager.dungeon_pick(userName) elif rndchoice == 1: reslt = self.game_manager.ruins_people(userName) elif rndchoice == 2: reslt = self.game_manager.ruins_monster(userName) elif rndchoice == 3: reslt = self.game_manager.the_road_monster(userName) else: reslt = self.game_manager.the_road_people(userName) elif "test0" in choice: reslt = self.game_manager.dungeon_pick(userName) elif "test1" in choice: reslt = self.game_manager.ruins_people(userName) elif "test2" in choice: reslt = self.game_manager.ruins_monster(userName) elif "test3" in choice: reslt = self.game_manager.the_road_monster(userName) elif "test4" in choice: reslt = self.game_manager.the_road_people(userName) else: reslt = self.game_manager.player_options(userName) try: return reslt break except: pass
class twtrManager(StreamListener): # def __init__(self): # self.db_manager = DatabaseManager(self) # self.game_manager = GameManager() """ A listener handles tweets that are received from the stream. This is a basic listener that just prints received tweets to stdout. # """ def on_status(self, status): self.db_manager = DatabaseManager(self) self.game_manager = GameManager() # Status object holds all twitter user info objects screenName = status.author.screen_name createDate = str(status.created_at) txt = status.text txt = txt.replace("@DunSuRu", "") print(txt) try: # Takes data and starts new thread. th = threading.Thread(target=self.handleChoice(txt, screenName, createDate)) th.start() except: print("unable to start thread") def on_error(self, status): print(status) def handleChoice(self, input, userName, createDate): check = self.db_manager.checkTweets(userName, input, createDate) if check: # If not, add to DB self.db_manager.storeTweets(userName, input, createDate) choice = input.lower() while True: if "new" in choice: reslt = self.game_manager.new_game(userName) elif "about" in choice: reslt = self.game_manager.instructions(userName) elif "who" in choice: reslt = self.game_manager.player_stats(userName) elif "continue" in choice: rndchoice = random.randint(0, 4) if rndchoice == 0: reslt = self.game_manager.dungeon_pick(userName) elif rndchoice == 1: reslt = self.game_manager.ruins_people(userName) elif rndchoice == 2: reslt = self.game_manager.ruins_monster(userName) elif rndchoice == 3: reslt = self.game_manager.the_road_monster(userName) else: reslt = self.game_manager.the_road_people(userName) elif "test0" in choice: reslt = self.game_manager.dungeon_pick(userName) elif "test1" in choice: reslt = self.game_manager.ruins_people(userName) elif "test2" in choice: reslt = self.game_manager.ruins_monster(userName) elif "test3" in choice: reslt = self.game_manager.the_road_monster(userName) elif "test4" in choice: reslt = self.game_manager.the_road_people(userName) else: reslt = self.game_manager.player_options(userName) try: return reslt break except: pass
def __init__(self): self.db_manager = DatabaseManager(self) self.main()
class twtrManager: def __init__(self): self.db_manager = DatabaseManager(self) self.main() def main(self): SCREEN_NAME = 'Jen_B_Mart' ckey = 'rlee33vXmHIlmR5tQljIX0ucD' csecret = 'cUiIFESIXSSin9YJHYwLnVwnHpS64Ytj7csY9yFqshvAlkcaPg' atoken = '2836017980-DxYDsgHqGMyRIq1yH3Uf3Ar63eYCFhqawJAWGOw' asecret = 'SruNXYjh0BpY4GQhiflXaxbB2XUhrCMslBrmrH2ViULnu' auth = tweepy.OAuthHandler(ckey, csecret) auth.set_access_token(atoken, asecret) api = tweepy.API(auth) auth = OAuthHandler(ckey, csecret) # self.homeTimeline() # def mainMenu(ckey,csecret,atoken,asecret,auth,api, self): # name = raw_input("Enter name \n") # text = raw_input("Enter text \n") # date = datetime.datetime.now().time() # db_manager.storeTweets(name, text, date) # # thing = input("Type anything to continue") # # if thing != "j2hde": # # homeTimeline(ckey,csecret,atoken,asecret,auth,api) def homeTimeline(self): while True: ckey = 'rlee33vXmHIlmR5tQljIX0ucD' csecret = 'cUiIFESIXSSin9YJHYwLnVwnHpS64Ytj7csY9yFqshvAlkcaPg' atoken = '2836017980-DxYDsgHqGMyRIq1yH3Uf3Ar63eYCFhqawJAWGOw' asecret = 'SruNXYjh0BpY4GQhiflXaxbB2XUhrCMslBrmrH2ViULnu' auth = tweepy.OAuthHandler(ckey, csecret) auth.set_access_token(atoken, asecret) api = tweepy.API(auth) auth = OAuthHandler(ckey, csecret) timeline=api.home_timeline(COUNT=0) try: # auth = tweepy.OAuthHandler(ckey, csecret) # auth.set_access_token(atoken, asecret) # api = tweepy.API(auth) # auth = OAuthHandler(ckey, csecret) # timeline=api.home_timeline(COUNT=0) for tweet in timeline: user=tweet.user name=tweet.user.name.encode('utf-8') text=tweet.text.encode('utf-8') date=tweet.created_at # name = 'jen' # text = '1' # date = '222' # print("name: " + name +"\n"+ "tweet: " + text+"\n"+ "date: " + date) # print("\n") if "@DunSuciRun" in text: #checks if special text in field text = text[11:] check = self.db_manager.checkTweets(name, text, date) if (check): #If not, add to DB self.db_manager.storeTweets(name, text, date) break else: print "wait a minute" time.sleep(5) pass # self.executeSomething() else: print "nothing valid. Waiting" time.sleep(5) pass except Exception, e: print "not valid. Lets wait a minute!" time.sleep(5) pass return text