예제 #1
0
 def find_favourite_word(self, wordcloud=True):
     statements = self.statement_set.filter(procedural=False)
     if self.current_member:
         # For current members, we limit to the last two years for better
         # comparison, and require at least 2,500 total words.
         statements = statements.filter(time__gte=datetime.datetime.now() - datetime.timedelta(weeks=100))
         min_words = 2500
     else:
         # For ex-members, we use everything they said
         min_words = 5000
     total_words = sum((s.wordcount for s in statements))
     if total_words < min_words:
         self.del_info('favourite_word')
         self.del_info('wordcloud')
         return
     self.set_info('favourite_word', text_utils.most_frequent_word(statements))
     if wordcloud:
         image = text_utils.statements_to_cloud(statements)
         path = os.path.join(self.WORDCLOUD_PATH, "%s.png" % (self.slug if self.slug else self.id))
         fullpath = os.path.join(settings.MEDIA_ROOT, path)
         with open(fullpath, 'wb') as f:
             f.write(image)
         self.set_info('wordcloud', path)
예제 #2
0
 def generate_wordcloud(self):
     image = text_utils.statements_to_cloud(self.statement_set.all())
     self.wordcloud.save("%s.png" % self.date, ContentFile(image), save=True)
     self.save()