def save_user_word(group_id, word): """ Save user's words in DB :param group_id: group id :param word: target word """ group = Group.objects.filter(id=group_id)[0] store_data = SpamWordList(word=word, group=group, status='user') store_data.save()
def init_db(group): """ save standard word from spam.txt to database when initialize database :param group: group object """ data_set = [line.strip() for line in open("analysis/texts/spam.txt", 'r')] words = SpamWordList.objects.filter(group=group) for i in data_set: if i in words: continue store_data = SpamWordList(word=i, group=group, status='filter') store_data.save()
def update_words_level(group): """ change temp and deleted status of words which are greater than critical point to filter status :param group: group object """ words_db = SpamWordList.objects.filter(group=group, status='temp', count__gte=10) for i in words_db: word = SpamWordList(group=group, word=i.word) word.status = 'filter' word.save() words = SpamWordList.objects.filter(group=group, status='deleted', count__gte=30) if words is not None: for i in words: word = SpamWordList(group=group, word=i.word) word.status = 'filter' word.save()