class SilverEye: def __init__(self, server_ip, server_port, database): self.client = MongoClient(server_ip, server_port, connect=True) self.database = database self.twitter_controller = TwitterController(self) self.analysis_controller = AnalysisController(self.client, database) self.dao_collection_tags = DAOTags(self.client, self.database) def start(self): keywords = self.dao_collection_tags.get_array_of_the_name_of_classified_tags() self.twitter_controller.start(keywords) def stop(self): self.twitter_controller.stop() def analyze_tweet(self, tweet): self.analysis_controller.analyze_tweet(tweet) def analyse_temporal_time(self, init_time=0): self.analysis_controller.analyse_temporal_lines(init_time) def analyze_global_results(self): self.analysis_controller.overall_analysis()
def __init__(self, server_ip, server_port, database): self.client = MongoClient(server_ip, server_port, connect=True) self.database = database self.twitter_controller = TwitterController(self) self.analysis_controller = AnalysisController(self.client, database) self.dao_collection_tags = DAOTags(self.client, self.database)
def main(): # Parse the command line arguments to determine what to tweet parser = OptionParser() imgController = ImgurController() twController = TwitterController() cmdParser = CommandParser(imgController, twController) parser.add_option("-e", "--exec-direct-messages", dest="exec_direct_messages", default=False, action="store_true", help="Check direct messages for commands") parser.add_option("-n", "--number", dest="number", default=1, help="Specify the number of images to post") parser.add_option("-g", "--gallery", dest="gallery", default="random", help="Specify a gallery to get images from") (options, args) = parser.parse_args() if options.exec_direct_messages: # Parse direct messages and execute their commands cmdParser.parse_commands() elif options.gallery != "random": # Print images from specific gallery messages = imgController.get_formatted_gallery_messages(options.gallery, numImages=int(options.number)) twController.tweet_messages(messages) else: # just post random images for i in range(int(options.number)): message = imgController.get_formatted_random_image_message() twController.tweet_message(message)
def main(): # Parse the command line arguments to determine what to tweet parser = OptionParser() imgController = ImgurController() twController = TwitterController() cmdParser = CommandParser(imgController, twController) parser.add_option( "-e", "--exec-direct-messages", dest="exec_direct_messages", default=False, action="store_true", help="Check direct messages for commands", ) parser.add_option("-n", "--number", dest="number", default=1, help="Specify the number of images to post") parser.add_option("-g", "--gallery", dest="gallery", default="random", help="Specify a gallery to get images from") (options, args) = parser.parse_args() if options.exec_direct_messages: # Parse direct messages and execute their commands cmdParser.parse_commands() elif options.gallery != "random": # Print images from specific gallery messages = imgController.get_formatted_gallery_messages(options.gallery, numImages=int(options.number)) twController.tweet_messages(messages) else: # just post random images for i in range(int(options.number)): message = imgController.get_formatted_random_image_message() twController.tweet_message(message)
class Tweet: controller = TwitterController() def __init__(self, status): self.status = status self.replies = [] self.created_at = datetime.strptime(self.status.created_at, '%a %b %d %H:%M:%S %z %Y') self.max_date = self.created_at + timedelta(days=1) check = True current_id = 1 while check: tweets = [] if current_id != 1: tweets = Tweet.controller.search( self.status.user.screen_name, self.created_at.strftime('%Y-%m-%d'), self.max_date.strftime('%Y-%m-%d'), self.status.id - 1, current_id - 1) else: tweets = Tweet.controller.search( self.status.user.screen_name, self.created_at.strftime('%Y-%m-%d'), self.max_date.strftime('%Y-%m-%d'), self.status.id - 1) tweets.reverse() print(len(tweets)) first = True for tweet in tweets: if first: first = False current_id = tweet.id if tweet.in_reply_to_status_id == self.status.id: self.replies.append(Tweet(tweet)) check = len(tweets) > 0 @classmethod def from_id(self, id): return Tweet(Tweet.controller.obtain_tweet(id)) def save(self): with open("data/data_" + str(self.status.id) + ".json", "w") as file: file.write(json.dumps(self.tweet_to_json(self))) def get_sentiment(self, tweet): analyzer = SentimentIntensityAnalyzer() vs = analyzer.polarity_scores(tweet.status.text) return vs['compound'] def tweet_to_json(self, tweet): json_replies = [] for reply in tweet.replies: json_replies.append(self.tweet_to_json(reply)) root = { "id": tweet.status.id, "screen_name": tweet.status.user.screen_name, "text": tweet.status.text, "num_replies": len(tweet.replies), "replies": json_replies, "sentiment": self.get_sentiment(tweet), "num_retweet": tweet.status.retweet_count, "num_fav": tweet.status.favorite_count } return root