def get_new_words_from_file(filename, existing_words=None): words = [] with open(filename, 'rb') as csvfile: reader = csv.reader(csvfile) for row in reader: word = skritter.normalize(row[0].decode('utf-8')) if existing_words is not None and word in existing_words: continue words.append(word) return words
else: vocablist = skritter.get_vocablist_details(session, vocablist_id) print 'Processing: %s' % vocablist['name'] existing_words = skritter.get_vocablist_words(session, vocablist) print 'Found %d words in current list' % len(existing_words) new_words = get_new_words_from_file(filename, existing_words) unique_new_words = set(new_words) print 'Getting ids for %d new words to be added' % len(unique_new_words) new_word_ids = skritter.get_ids_for_words(session, unique_new_words) print 'Adding %d unique word ids to %s' % (len(new_word_ids), vocablist['name']) add_word_ids_to_vocablist(session, vocablist, new_word_ids) if __name__ == '__main__': if len(sys.argv) < 3: sys.exit('usage: %s <list name> <filename>' % sys.argv[0]) else: list_name = skritter.normalize(sys.argv[1].decode('utf-8')) filename = sys.argv[2] # TODO(gmwils): load these from the command line username = os.environ.get('SKRITTER_USER', 'iamuser') password = os.environ.get('SKRITTER_PASSWORD', 'secret') main(username, password, list_name, filename)
return else: vocablist = skritter.get_vocablist_details(session, vocablist_id) print 'Processing: %s' % vocablist['name'] existing_words = skritter.get_vocablist_words(session, vocablist) print 'Found %d words in current list' % len(existing_words) new_words = get_new_words_from_file(filename, existing_words) unique_new_words = set(new_words) print 'Getting ids for %d new words to be added' % len(unique_new_words) new_word_ids, unknown_ids = skritter.get_ids_for_words(session, unique_new_words) print 'Adding %d unique word ids to %s' % (len(new_word_ids), vocablist['name']) add_word_ids_to_vocablist(session, vocablist, new_word_ids) if __name__ == '__main__': if len(sys.argv) < 3: sys.exit('usage: %s <list name> <filename>' % sys.argv[0]) else: list_name = skritter.normalize(sys.argv[1].decode('utf-8')) filename = sys.argv[2] # TODO(gmwils): load these from the command line username = os.environ.get('SKRITTER_USER', 'iamuser') password = os.environ.get('SKRITTER_PASSWORD', 'secret') main(username, password, list_name, filename)