|
from pymongo import MongoClient |
|
import pandas as pd |
|
import os |
|
import datetime |
|
|
|
client = MongoClient( |
|
"mongodb://wth000:wth000@43.159.47.250:27017/dbname?authSource=wth000") |
|
db = client["wth000"] |
|
|
|
name="COIN" |
|
collection = db[f"{name}"] |
|
|
|
df = pd.DataFrame(list(collection.find())) |
|
print("数据读取成功") |
|
|
|
|
|
|
|
|
|
|
|
|
|
file_path = os.path.abspath(__file__) |
|
|
|
dir_path = os.path.dirname(file_path) |
|
|
|
dir_path = os.path.dirname(os.path.dirname(dir_path)) |
|
file_path = os.path.join(dir_path, f"{name}.csv") |
|
df.to_csv(file_path, index=False) |
|
|