File tree 2 files changed +10
-12
lines changed
2 files changed +10
-12
lines changed Original file line number Diff line number Diff line change 2
2
import psycopg2
3
3
import json
4
4
from tqdm import tqdm
5
+ from config import *
5
6
# 连接到 MongoDB
6
- mongo_client = pymongo .MongoClient ("mongodb://root:JIwb158.@localhost:27017/" )
7
- mongo_db = mongo_client ["hotday" ]
8
- mongo_collection = mongo_db ["your_collection" ]
7
+ mongo_client = pymongo .MongoClient (MONGODB_URI )
8
+ mongo_db = mongo_client [MONGODB_DB_NAME ]
9
9
10
10
# 连接到 PostgreSQL
11
- pg_conn = psycopg2 .connect (" dbname=postgres user=admin password=securepassword " )
11
+ pg_conn = psycopg2 .connect (f"host= { PG_HOST } port= { PG_PORT } dbname={ PG_DB } user={ PG_USER } password={ PG_PASSWORD } " )
12
12
pg_cursor = pg_conn .cursor ()
13
- collection_names = [
14
- "acfun" ,
15
- "openeye" ,
16
- "tencent_news" ,
17
- "woshipm" ,
18
- "wx_read_rank" ,
19
- "zongheng" ,
20
- ]
13
+
14
+ collection_names = mongo_db .list_collection_names ()
21
15
# 从 MongoDB 中读取数据
22
16
for collection_name in tqdm (collection_names ):
23
17
mongo_collection = mongo_db [collection_name ]
46
40
data = document ['books' ]
47
41
elif collection_name == "zongheng" :
48
42
data = document ['result' ]
43
+ else :
44
+ if "data" not in document :
45
+ continue
46
+ data = document ['data' ]
49
47
insert_time = document ['insert_time' ]
50
48
51
49
# 将数据插入到 PostgreSQL
You can’t perform that action at this time.
0 commit comments