- 积分
- 7
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2018-6-14
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
# -*- coding: utf-8 -*-
import urllib2
import os
import string
import sys
def getData(temp_path,strTime):
strTime1 = strTime.replace('-','')+"000000"
URL = "http://10.104.89.55/cimiss-web/api"
dicts = ([('userId', 'BCWH_BFJU_JZSQXXXGXPT'),\
('pwd', '9654321'),\
('interfaceId','getSurfEleInRegionByTime'),\
('dataCode','SURF_CHN_MUL_MON'),\
('times',strTime1),\
('adminCodes','421000'),\
('elements','Lat'+','+'Lon'+','+'Year'+','+'Mon'+','+'PRS_Avg'+','+'TEM_Avg'+','+'RHU_Avg'+','+'PRE_Time_2020'+','+'WIN_S_2mi_Avg'),\
('dataFormat','')])
item=dicts
urls="?"
for i in item:
(key,value)=i
temp_str = key+"="+value
urls = urls + temp_str+"&"
urls = urls[:len(urls)-1]
baseUrl = URL + urls
dataFormat = 'text'
req = urllib2.Request(baseUrl + dataFormat)
response = urllib2.urlopen(req)
data = response.read()
# ID1 = uuid.uuid1()
with open(temp_path+"\\temp.txt","w") as f:
f.write(data)
f.close()
ffile = open(temp_path+"\\temp.txt","r")
outfiles=open(temp_path+"/"+strTime.replace('-','')+"0000.txt","w")
line_num = 0
while 1:
line = ffile.readline()
line_num += 1
if (line_num != 1):
if (line ==''):
break
elif(line =='\n' or (line.find("9999")!=-1)):
continue
else:
# line = line.replace(' ',',')
line = line.replace('\r','')
outfiles.write(line)
# ID2 = uuid.uuid1()
ffile.close()
outfiles.close()
# line_num = 0
# for line in ffile.readlines() :
# line_num += 1
# if (line_num != 1):
# outfiles.write(line)
#
#
# outfiles.close()
if __name__ == '__main__':
# strTime = sys.argv[1]
# var = sys.argv[2]
# txt_root = sys.argv[3]
strTime = "2018-04-01"
temp_path = "D:/test"
getData(temp_path,strTime)
|
|