Esempio n. 1
0
                '\n') + baseUrl3
            req = request.Request(baseUrl)
            response = urlopen(req).read().decode("utf-8")
            f2.write(response.strip('\n'))
        print('  【实况站点资料已下载完成】')
    except Exception as e:
        print('  【实况站点资料未能下载,原因为:】')
        print(e)
        with open(logPath + '实况资料获取报错_' + getTimeOb.nowBJTStr + '.log',
                  'w+') as logfo:
            logfo.writelines(str(e))
    # 下载实况格点资料
    print('  【开始获取实况格点数据】')
    check_dir_mkdir(finalSaveGPath)  #######新建当前日期GRIBT文件夹
    check_dir_mkdir(finalSaveTPath)  #######新建当前日期M4文件夹
    ftpOb = FtpLoad(ftpHost, ftpPort, ftpUsr,
                    ftpPwd)  ################建立连接FTP对象
    ftpConnect = ftpOb.ftpConnet  #####################连接FTP
    fileList = ftpConnect.nlst(ftpFilePath)  ################遍历ftpFilePath文件夹目录
    for eEle in eleList:  ###########分不同要素下载
        listtemp1 = []
        for eFile in fileList:
            eleTemp = eFile.split('_')[10]
            eleName = eleTemp.split('-')
            # eleName[7]为SCMOC_TXXXX,[8]为起报时间
            if eEle == eleName[1]:
                if eleName[2][:-5] == nowTime[:-2]:
                    sizeOfFile = ftpConnect.size(ftpFilePath + '\\' + eFile)
                    # 判断该文件是否大于1m,小于1m的文件可能是坏文件,不下载
                    if sizeOfFile > 1000:
                        listtemp1.append(eFile)
Esempio n. 2
0
 ftpHost = '10.181.8.180'
 ftpPort = 21
 ftpUsr = '******'
 ftpPwd = 'forecast'
 ftpBasePath = '\\Temperature\\'
 localBasePath = 'F:\\work\\2020Correct\\data\\'
 fangFa = [
     'TM_Result_Grid_20\\', 'TM_Result_DA\\', 'TM_Result_StaionAdd\\DA\\',
     'TM_Result_StaionAdd\\MB\\'
 ]
 fangfa1h = 'TM_Result_Grid_1h\\'
 logPath = 'F:\\work\\2020Correct\\data\\log\\'
 listEle = ['TMAX', 'TMIN', 'TMP']
 getTimeOb = GetNowTime('2020100108')
 nowTime = getTimeOb.qiBaoShiJian
 ftpOb = FtpLoad(ftpHost, ftpPort, ftpUsr, ftpPwd)
 ftpConnect = ftpOb.ftpConnet
 for i in listEle:
     if i == 'TMAX' or i == 'TMIN':
         for eFangFa in fangFa:
             try:
                 ftpOb.ftp_upload(
                     localBasePath + eFangFa + i + '\\' + nowTime[2:-2] +
                     '.024', ftpBasePath + eFangFa + i + '\\' +
                     nowTime[2:-2] + '.024')
             except Exception as e:
                 print('无法上传文件,原因为:')
                 print(e)
                 with open(
                         logPath + '上传资料报错_' + getTimeOb.nowBJTStr + '.log',
                         'a+') as logfo: