-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_words.py
48 lines (39 loc) · 1.55 KB
/
add_words.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from pymongo import MongoClient, monitoring
import os, logging
import csv
DB_HOST = 'localhost'
DB_PORT = 27017
DB_MAX_POOL_SIZE = 300
DB_NAME = 'erundopel'
class CommandLogger(monitoring.CommandListener):
def started(self, event):
logging.info("Command {0.command_name} with request id "
"{0.request_id} started on server "
"{0.connection_id}".format(event))
def succeeded(self, event):
logging.info("Command {0.command_name} with request id "
"{0.request_id} on server {0.connection_id} "
"succeeded in {0.duration_micros} "
"microseconds".format(event))
def failed(self, event):
logging.info("Command {0.command_name} with request id "
"{0.request_id} on server {0.connection_id} "
"failed in {0.duration_micros} "
"microseconds".format(event))
mongo = MongoClient(host=DB_HOST, port=DB_PORT, connect=True,
event_listeners=[CommandLogger()],
maxPoolSize=DB_MAX_POOL_SIZE)
db = mongo[DB_NAME]
with open("words.csv", "r", encoding="utf8") as csvfile:
data = csv.DictReader(csvfile, delimiter=",", quotechar=" ")
words = {x["word"]: [x["answer"],
x["exp_1"], x['exp_2'],
x['exp_3']] for x in data}
for word in words:
print(word)
db.words.insert_one({
"word": word,
"a": words[word][0],
"e1": words[word][1],
"e2": words[word][2],
"e3": words[word][3]})