-
Notifications
You must be signed in to change notification settings - Fork 0
/
insert_mongo.py
66 lines (42 loc) · 1.75 KB
/
insert_mongo.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import pymongo
import json
def insert_mongo(collection,data):
with open("C:/Users/Jimin/PycharmProjects/graduation/server_info.json","r",encoding="utf-8") as f :
info = json.load(f)
ip = info.get("ip")
port = info.get("port")
conn = pymongo.MongoClient("mongodb://{}:{}".format(ip,port))
novel = conn['novel']
conn_collection = novel[collection]
conn_collection.insert(data)
print("============INSERT DATA============")
# 어쩔 수 없는 선택이었따..
def insert_mongo_meta():
with open("C:/Users/Jimin/PycharmProjects/graduation/server_info.json","r",encoding="utf-8") as f :
info = json.load(f)
ip = info.get("ip")
port = info.get("port")
conn = pymongo.MongoClient("mongodb://{}:{}".format(ip,port))
novel = conn['novel']
novel_meta = novel['meta']
with open("C:/Users/Jimin/PycharmProjects/graduation/data/novel_url.json","r", encoding='utf-8') as f:
meta_data = json.load(f)
for data in meta_data:
novel_meta.insert(data)
print(f"==========META FINISH==========")
def insert_mongo_contents():
with open("C:/Users/Jimin/PycharmProjects/graduation/server_info.json","r",encoding="utf-8") as f :
info = json.load(f)
ip = info.get("ip")
port = info.get("port")
conn = pymongo.MongoClient("mongodb://{}:{}".format(ip,port))
novel = conn['novel']
novel_meta = novel['contents']
with open("C:/Users/Jimin/PycharmProjects/graduation/data/novel_contents.json","r", encoding='utf-8') as f:
contents_data = json.load(f)
for data in contents_data:
novel_meta.insert(data)
print(f"==========CONTENTS FINISH==========")
if __name__ == "__main__":
insert_mongo_meta()
insert_mongo_contents()