def test_emptyTweets(): tweet = [] media = MediaUtility() media_ex = media.tweet_2_image(tweet) assert media_ex is None
def test_wrongFormatTweet(): tweet = ["hello"] media = MediaUtility() media_ex = media.tweet_2_image(tweet) assert media_ex == "<h1>Tweets from API not formatted correctly</h1>"
def __init__(self, process_id, use_verbose_logging, should_check_videos, event_queue, task_queue): super(HashWorker, self).__init__() self._media_utility = MediaUtility(use_verbose_logging) self._logger = Logger() self._process_id = process_id self._should_check_videos = should_check_videos self._event_queue = event_queue self._task_queue = task_queue self._use_verbose_logging = use_verbose_logging
def test_removeOnlyPNG(): testPNG = "tweet_0.png" testMP4 = "test.mp4" testFile = "test.txt" os.system("touch " + testPNG) os.system("touch " + testMP4) os.system("touch " + testFile) media = MediaUtility() media.png_cleanup() assert os.path.isfile(testPNG) is False assert os.path.isfile(testMP4) is True assert os.path.isfile(testFile) is True
def __init__(self, file_handler, use_verbose_logging, should_check_videos, process_count): super().__init__(file_handler, process_count, use_verbose_logging) self._hash_event_handler = HashEventHandler(self._use_verbose_logging) self._use_verbose_logging = self._use_verbose_logging self._should_check_videos = should_check_videos self._media_utility = MediaUtility(self._use_verbose_logging)
def runProcess(): # get from queue - can recieve username here job = config.q.get() username = job["user"] media = MediaUtility() twitter = TwitterUtility() auth_exception = twitter.get_auth("keys") if auth_exception: return auth_exception tweets = twitter.get_tweets(username) if not tweets: html = "<h1>User has no tweets within the past 24 hours,\ try another user.</h1>" return html # error case for undefined user elif isinstance(tweets, str): return tweets video_exception = media.tweet_2_image(tweets) if video_exception: return video_exception media.create_video(username) # run task done for the thread here config.q.task_done() config.queuedJobs[config.index - 1]["status"] = "done"
def get(self): # clears pictures and videos from prior call media = MediaUtility() media.media_cleanup() # uses overwatchleague twitter if none found in url try: username = request.args['user'] if username == '': html = "<h1>Please specify a user in the URL arguments</h1>" return html except Exception: html = "<h1>Please specify a user in the URL arguments</h1>" return html twitter = TwitterUtility() auth_exception = twitter.get_auth("keys") if auth_exception: return auth_exception tweets = twitter.get_tweets(username) if not tweets: html = "<h1>User has no tweets within the past 24 hours,\ try another user.</h1>" return html # error case for undefined user elif isinstance(tweets, str): return tweets # add the username to the queue here else: # if there are no errors authenticating and getting tweets, # queue the video creation for that user job = { "user": username, "id": config.index, "status": "in progress" } config.queuedJobs.append(job) config.index += 1 config.q.put(job) # wait until queue is empty before returning the video config.q.join() media.png_cleanup() return send_file(f"{username}_tweet_video.mp4")
class HashWorker(Process): _media_utility = None _process_id = 0 _event_queue = None _task_queue = None _file_list = [] _should_check_videos = False _logger = None _use_verbose_logging = False def __init__(self, process_id, use_verbose_logging, should_check_videos, event_queue, task_queue): super(HashWorker, self).__init__() self._media_utility = MediaUtility(use_verbose_logging) self._logger = Logger() self._process_id = process_id self._should_check_videos = should_check_videos self._event_queue = event_queue self._task_queue = task_queue self._use_verbose_logging = use_verbose_logging def run(self): self.__execute() def __execute(self): while True: filepath = self._task_queue.get() if (filepath == -1): break elif isinstance(filepath, str): self.__log_verbose( str(self._process_id) + ": processing filepath " + filepath) self.__handle_filepath(filepath) else: self._logger.print_log( str(self._process_id) + " picked up something strange from the queue" + str(filepath)) def __handle_filepath(self, filepath): if self._media_utility.is_image_file(filepath): self.__handle_valid_image(filepath) elif self._should_check_videos and self._media_utility.is_video_file( filepath): self.__handle_valid_video(filepath) else: self.__handle_no_valid_media_found(filepath) def __handle_valid_image(self, filepath): image_model = self._media_utility.get_media_model_for_image(filepath) self.__handle_valid_media(filepath, image_model) def __handle_valid_video(self, filepath): video_model = self._media_utility.get_media_model_for_video(filepath) self.__handle_valid_media(filepath, video_model) def __handle_valid_media(self, filepath, media_model): if media_model == None: self.__handle_no_valid_media_found(filepath) else: self.__add_to_queue(EventType.FILE_HASHED, media_model) def __handle_no_valid_media_found(self, filepath): self.__add_to_queue(EventType.SKIPPED_FILE_HASH, filepath) def __add_to_queue(self, event_type, event_data): self._event_queue.put(Event(event_type, event_data, self._process_id)) def __log_verbose(self, message): if self._use_verbose_logging == True: self._logger.print_log(message)