telegram-init/insert/main.py

15 lines
506 B
Python
Raw Normal View History

2024-07-16 20:20:04 +00:00
def create_insert_many_command(input_file: str, output_file: str):
with open(input_file, 'r', encoding='utf-8') as file:
words = file.readlines()
formatted_words = [f" {{ word: '{word.strip()}' }}" for word in words]
command = "db.words.insertMany([\n" + ",\n".join(formatted_words) + "\n]);"
with open(output_file, 'w', encoding='utf-8') as file:
file.write(command)
input_file = 'words.txt'
output_file = 'out.txt'
create_insert_many_command(input_file, output_file)