コード例 #1
0
def convert_csv():
    MongoDBUtil.connect()

    query = {}
    rets = MongoDBUtil.query(query)

    for ret in rets:
        print(ret)
        if ret["fund_name"] == "list":
            continue

        with open("D:\\临时文件\\基金数据\\%s.csv" % ret["fund_number"],
                  'w',
                  newline='') as csvfile:
            fieldnames = ["time", "earn", "IF", "SSE"]
            writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
            writer.writeheader()
            for data in ret["data"]:
                for key in data:
                    print("write ",
                          str(key).replace('/', '-'), " ", data[key][0], " ",
                          data[key][1], " ", data[key][2])
                    writer.writerow({
                        "time": str(key).replace('/', '-'),
                        "earn": data[key][0],
                        "IF": data[key][1],
                        "SSE": data[key][2],
                    })

    MongoDBUtil.close()
コード例 #2
0
ファイル: Fund.py プロジェクト: s-s-e-of-life/fund
def get_fund_data(number):
    MongoDBUtil.connect()

    query = {"fund_number": "%06d" % int(number)}
    if number == "":
        query = {}

    rets = MongoDBUtil.query(query)
    MongoDBUtil.close()

    return rets[0]["data"]