def test_twitter_engagement(self): test_string = "Worst song ever." response = twitter_engagement(test_string) self.assertIsInstance(response, float) self.assertTrue(response <= 1) self.assertTrue(response >= 0)
def test_batch_twitter_engagement(self): test_string = "Worst song ever." response = twitter_engagement([test_string, test_string]) self.assertTrue(isinstance(response, list)) self.assertIsInstance(response[0], float) self.assertEqual(response[0], response[1])
def __init__(self, handle, tweet): self.handle = handle self.tweet = tweet self.twitter_engagement = indicoio.twitter_engagement(tweet) self.personality_scores = self.get_personality() self.political_scores = self.get_political_scores() self.keywords = self.generate_keywords() for x in range(0, len(self.keywords)): self.keywords[x] = self.keywords[x].encode('utf-8')
def get_virality(): if request.method == 'POST': data = dict(request.form)['data_to_analyze'] return json.dumps({ 'virality': indicoio.twitter_engagement(data) })