def create_twitter_video(video_id, user, email, format='ogg'): print("Creating video") update_work_progress(video_id, key='status', val=f"Generating images from {user}'s tweets") image_path = create_image_dir() print(f"{datetime.now()} -- Worker ({current_process()}) making {video_id} for @{user}") tweets = get_tweets(user) threads = [] for n, tweet in enumerate(tweets): t = threading.Thread(target=tweet_to_image, args=( tweet, f"{image_path}/tweet{n}")) threads.append(t) t.start() for t in threads: t.join() print('Finished making images...') update_work_progress(video_id, key='status', val="Creating video from tweets") convert_images_to_video(image_path, video_id) rmtree(image_path) if email is not None: print(f"Sending email... {email}") send_email(email, video_id) update_work_progress(video_id, key='status', val=f"Video finished!") update_work_progress(video_id, key='finished', val=True) print(f"{datetime.now()} -- Worker finished {video_id} for @{user}")
def get(self, args): tweets = get_tweets(args['user']) for tweet in tweets: for image in tweet.images: image_content = download_image(image['url']) objects = detect_objects(image_content) image.update({"objects": objects}) print(image) tweets = [tweet.to_json() for tweet in tweets] return tweets
def test_create_twitter_video(): orig_func = worker.get_tweets worker.get_tweets = MagicMock(return_value=fake_tweets) tweets = twitter_handler.get_tweets('elonmusk') assert tweets is not None worker.create_twitter_video('test-video', 'user', None) assert os.path.exists(f"{base_dir}/videos/test-video.ogg") worker.get_tweets = orig_func os.unlink(f"{base_dir}/videos/test-video.ogg")
def do_it(): print 'Entering do_it().' tweets = twitter_handler.get_tweets() print 'Got tweets.' map = MainMap() process_all_tweets(map, tweets) print 'Processed all tweets.' first_word = map.generate_first_word() currWord = map.generate_next(first_word) char_count = len(currWord) new_sentence = [] while currWord is not 'ENDOFSENTENCE': if not ('http' in currWord): new_sentence.append(currWord) currWord = map.generate_next(currWord) char_count += len(currWord) if '.' in currWord: break print 'Created sentence.' capitalize_first_word(new_sentence) final_sentence = turn_arr_to_sentence(new_sentence) twitter_handler.publish_tweet(final_sentence) print 'Tweet published.' return final_sentence
def test_tweet_to_image(): tweets = twitter_handler.get_tweets('elonmusk') assert tweets is not None img_path = f"{base_dir}/images/test_image" twitter_handler.tweet_to_image(tweets[0], img_path) assert os.path.exists(img_path + '.png')
def test_twitter_api(): tweets = twitter_handler.get_tweets('elonmusk') assert tweets is not None
def test_twitter_api(): from twitter_handler import get_tweets tweets = get_tweets('elonmusk') assert tweets is not None