File size: 1,217 Bytes
b2e325f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
import re
from re import sub
import smtplib
import matplotlib.pyplot as plt
from itertools import product
from tqdm import tqdm_notebook, tqdm, trange
import time
import warnings
from datetime import datetime
import csv

def save_database_info(filepath, database_name, date):
    # 读取CSV文件
    # with open(f'./database_name.csv', 'r', encoding='utf-8') as file:
    with open(filepath, 'r', encoding='utf-8') as file:
        
        # 创建CSV读取器
        reader = csv.reader(file)

        # 将内容存储到列表中
        rows = []
        for row in reader:
            rows.append(row)

    # 添加新行
    # new_row = ['New Data 1', 'New Data 2'] # 新行的数据
    new_row = [database_name, date] # 新行的数据
    rows.append(new_row)

    # 写入CSV文件
    # with open('./database_name.csv', 'w', newline='', encoding='utf-8') as file:
    with open(filepath, 'w', newline='', encoding='utf-8') as file:
        
        # 创建CSV写入器
        writer = csv.writer(file)
        # 写入所有行
        writer.writerows(rows)
    
    # close the file to save the data. 
    file.close()

    return None