请选择 进入手机版 | 继续访问电脑版
爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 7790|回复: 0

[源代码] cimiss

[复制链接]

新浪微博达人勋

发表于 2018-6-14 10:15:47 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

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)





密码修改失败请联系微信:mofangbao
您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表