コード例 #1
0
    def handle(self, *args, **options):
        print "we are starting.."
       
        parent_directory = os.path.abspath(os.path.join(os.getcwd(), os.pardir))
        fixed_words_file = "%s/Resource/fixed_words.txt" % parent_directory

        lines = open(fixed_words_file, "r").readlines()
        for line in lines:
            fixed_word = line.strip()
            try:
                db_entry = WordList.objects.get(word=fixed_word)
            except WordList.DoesNotExist:
                obj = WordList(word=fixed_word)
                obj.save()
コード例 #2
0
 def handle(self, *args, **options):
     for filename in options['filename']:
         try:
             file = open(filename, 'r')
             for line in file:
                 word = line.lower()
                 word = re.sub(r'[^a-z0-9]+', '', word)
                 w = WordList.objects.filter(word=word)
                 if w:
                     w = WordList.objects.get(pk=w[0].pk)
                     self.stdout.write(self.style.SUCCESS('"%s" already existed in the wordbank. Continues to next word.' % w.word))
                 else:
                     w = WordList(word=word)
                     w.usage = False
                     w.save()
                     self.stdout.write(self.style.SUCCESS('Successfully added word "%s"' % w.word))
             file.close()
         except IOError:
             print "Cannot open %s" % filename
コード例 #3
0
def wordlist_load():
    words = ["scope", "improper", "collagen", "coin"]
    for word in words:
        w = WordList(word=word)
        w.save()