12345678910111213141516171819202122232425262728293031323334 |
- # 下载数据
- import sys
- from LIB.BACKEND import DBManager
- from LIB.BACKEND.OPENAPI import OpenApi
- import datetime
- import os
- # 从开放平台获取资产列表及相关信息
- openApi = OpenApi.OpenApi()
- df_all_sn = openApi.get_asset()
- write_path = r'D:\Develop\Data\\'
- dbManager = DBManager.DBManager()
- start_time = '2021-11-10 00:00:00'
- end_time = '2021-12-13 00:00:00'
- st=datetime.datetime.strptime(start_time, '%Y-%m-%d %H:%M:%S')
- et = st + datetime.timedelta(days=1)
- while et <= datetime.datetime.strptime(end_time, '%Y-%m-%d %H:%M:%S'):
- time_dir = st.strftime('%Y-%m-%d %H:%M:%S')[0:10]
- if not os.path.exists(write_path+time_dir):
- os.mkdir(write_path+time_dir)
- filenames = os.listdir(write_path+time_dir)
- for sn in df_all_sn['sn'].tolist():
- if sn+".csv" in filenames:
- print("skip")
- continue
- df_data = dbManager.get_data(sn=sn, start_time=st.strftime('%Y-%m-%d %H:%M:%S'), end_time=et.strftime('%Y-%m-%d %H:%M:%S'), data_groups=['bms'])
- df_data['bms'].to_csv(write_path+time_dir+'\\'+sn+'.csv', index=False)
- st = et
- et = st + datetime.timedelta(days=1)
- print(sn+'下载完成')
|