一 天气预报
国内的天气预报数据,主要是国家气象局和国外两个来源(指数据来源)。
国外方面主要是雅虎(XML格式,谷歌已经停掉了自家的天气API);
国内数据由国家气象局提供( *** ON格式)。
在知乎看到过一篇专业人士评论,雅虎可以提供全球范围的且非常精细的天气数据(小时级更新),但主要是通过计算机自动生成。而国家气象局则是各地经验丰富的专家人士结合计算机综合分析得出,在准确性上更胜一筹。我就这样信了!
国家气象局接口资源及用法
气象局的天气预报主页:移动版普通版 ,仔细挖掘这两个地址可以发现很多好东西哦。
特点:接口多,来自weather.com.cn和mobile.weather.com.cn都有,次数不限制,服务稳定,功能全面,优先推荐。
百度API Key申请地址:
创建应用 如图:
提交后得到API Key ,运行结果如下:
扩展资料:
API(Application Programming Interface,应用程序编程接口)是一些预先定义的函数,目的是提供应用程序与开发人员基于某软件或硬件得以访问一组例程的能力,而又无需访问源码,或理解内部工作机制的细节。
API函数包含在Windows系统目录下的动态连接库文件中。Windows API是一套用来控制Windows的各个部件的外观和行为的预先定义的Windows函数。
参考资料:百度百科-api接口
使用搜索引擎可以得到很多的天气预报接口,这里以某个api为例
参数为city=城市名称
尝试获取南昌的天气预报
南昌
得到下面xml数据
?xml version="1.0" encoding="utf-8"?
resp
city南昌/city
updatetime16:55/updatetime
wendu5/wendu
fengli3级/fengli
shidu90%/shidu
fengxiang北风/fengxiang
sunrise_106:54/sunrise_1
sunset_117:19/sunset_1
sunrise_2/
sunset_2/
environment
aqi26/aqi
pm2513/pm25
suggest各类人群可自由活动/suggest
quality优/quality
MajorPollutants/
o344/o3
co1/co
pm1014/pm10
so24/so2
no227/no2
time16:00:00/time
/environment
yesterday
date_14日星期五/date_1
high_1高温 11℃/high_1
low_1低温 7℃/low_1
day_1
type_1阴/type_1
fx_1无持续风向/fx_1
fl_1微风/fl_1
/day_1
night_1
type_1小到中雨/type_1
fx_1北风/fx_1
fl_13-4级/fl_1
/night_1
/yesterday
forecast
weather
date5日星期六/date
high高温 7℃/high
low低温 5℃/low
day
type中到大雨/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/day
night
type小到中雨/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/night
/weather
weather
date6日星期天/date
high高温 10℃/high
low低温 5℃/low
day
type阴/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/day
night
type多云/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/night
/weather
weather
date7日星期一/date
high高温 13℃/high
low低温 6℃/low
day
type多云/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/day
night
type晴/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/night
/weather
weather
date8日星期二/date
high高温 13℃/high
low低温 7℃/low
day
type晴/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/day
night
type多云/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/night
/weather
weather
date9日星期三/date
high高温 13℃/high
low低温 10℃/low
day
type小雨/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/day
night
type小雨/type
fengxiang无持续风向/fengxiang
fengli微风级/fengli
/night
/weather
/forecast
zhishus
zhishu
name晨练指数/name
value不宜/value
detail有较强降水,请避免户外晨练,建议在室内做适当锻炼,保持身体健康。/detail
/zhishu
zhishu
name舒适度/name
value较舒适/value
detail白天有雨,人们会感到有些凉意,但大部分人完全可以接受。/detail
/zhishu
zhishu
name穿衣指数/name
value较冷/value
detail建议着厚外套加毛衣等服装。年老体弱者宜着大衣、呢外套加羊毛衫。/detail
/zhishu
zhishu
name感冒指数/name
value极易发/value
detail将有一次强降温过程,天气寒冷,且空气湿度较大,极易发生感冒,请特别注意增加衣服保暖防寒。/detail
/zhishu
zhishu
name晾晒指数/name
value不宜/value
detail有较强降水,不适宜晾晒。若需要晾晒,请在室内准备出充足的空间。/detail
/zhishu
zhishu
name旅游指数/name
value较不宜/value
detail天气稍凉,有微风,同时有有较强降水,会给出行产生很多麻烦,建议好还是多选择在室内活动!。/detail
/zhishu
zhishu
name紫外线强度/name
value最弱/value
detail属弱紫外线辐射天气,无需特别防护。若长期在户外,建议涂擦SPF在8-12之间的防晒护肤品。/detail
/zhishu
zhishu
name洗车指数/name
value不宜/value
detail不宜洗车,未来24小时内有雨,如果在此期间洗车,雨水和路上的泥水可能会再次弄脏您的爱车。/detail
/zhishu
zhishu
name运动指数/name
value较不宜/value
detail有较强降水,建议您选择在室内进行健身休闲运动。/detail
/zhishu
zhishu
name约会指数/name
value不适宜/value
detail较强降水天气会给室外约会增添许多麻烦,尽量不要外出约会,更好在室内促膝谈心。/detail
/zhishu
zhishu
name雨伞指数/name
value带伞/value
detail有较强降水,您在外出的时候一定要带雨伞,以免被雨水淋湿。/detail
/zhishu
/zhishus
/resp
得到数据后使用XML解析数据即可,更好是建立一个实体类来存储数据
下面是使用DOM方式解析部分数据代码
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
//is是 *** 连接得到的输入流
Document doc = builder.parse(is);
if(doc==null) throw new Exception();
Element element = doc.getDocumentElement();
NodeList childList = element.getChildNodes();
for(int i=0; ichildList.getLength(); i++){
Element e = (Element) childList.item(i);
String tag = e.getTagName();
String text = e.getTextContent();
if("city".equals(tag)){
//城市
}else if("updatetime".equals(tag)){
//更新时间
}else if("wendu".equals(tag)){
//即时温度
}else if("fengli".equals(tag)){
//风力
}else if("shidu".equals(tag)){
//湿度
}else if("fengxiang".equals(tag)){
//风向
}
}
找一个免费的天气预报API,它会以json格式返回数据,然后你自己取所需的数据就可以了
因微信公共号提供城市天气预报服务,发现网山天气预报接口和环境数据接口方面资料比较乱,而且有不少内容已经失效,下面内容由过程日志整理形成,希望可用得上。
一 天气预报
国内的天气预报数据,主要是国家气象局和国外两个来源(指数据来源)。
国外方面主要是雅虎(XML格式,谷歌已经停掉了自家的天气API);
国内数据由国家气象局提供( *** ON格式)。
在知乎看到过一篇专业人士评论,雅虎可以提供全球范围的且非常精细的天气数据(小时级更新),但主要是通过计算机自动生成。而国家气象局则是各地经验丰富的专家人士结合计算机综合分析得出,在准确性上更胜一筹。我就这样信了!
国家气象局接口资源及用法
气象局的天气预报主页:移动版普通版 ,仔细挖掘这两个地址可以发现很多好东西哦。
特点:接口多,来自weather.com.cn和mobile.weather.com.cn都有,次数不限制,服务稳定,功能全面,优先推荐。
1. 实时天气接口
有多个接口,好像差别不大:
实时天气1:
实时天气2:
实时天气3(带时间戳):
2. 一周天气预报接口
7天预报数据 URL:
该接口来源气象局移动版网站,目测数据最为精确,详细接口格式如下:
{"c":{"c1":"101010100","c2":"beijing","c3":"北京","c4":"beijing","c5":"北京","c6":"beijing","c7":"北京","c8":"china","c9":"中国","c10":"1","c11":"010","c12":"100000","c13":"116.391","c14":"39.904","c15":"33","c16":"AZ9010","c17":"+8"},
"f":{"f1":
[
{"fa":"01","fb":"03","fc":"10","fd":"5","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:21|17:40"},
{"fa":"07","fb":"07","fc":"19","fd":"12","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:22|17:38"},
{"fa":"02","fb":"00","fc":"15","fd":"5","fe":"8","ff":"8","fg":"3","fh":"1","fi":"06:23|17:37"},
{"fa":"00","fb":"00","fc":"16","fd":"4","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:24|17:35"},
{"fa":"00","fb":"00","fc":"18","fd":"7","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:25|17:34"},
{"fa":"00","fb":"01","fc":"18","fd":"8","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:26|17:32"},
{"fa":"01","fb":"01","fc":"16","fd":"6","fe":"0","ff":"0","fg":"0","fh":"0","fi":"06:27|17:31"}],
"f0":"201310121100"}}
详细接口分析如下:
//格式说明
var format={fa:图片1,fb:图片2,fc:温度1,fd:温度2,fe:风向1,ff:风向2,fg:风力1,fh:风力2,fi:日出日落};
//定义天气类型
var weatherArr={"00":"晴","01":"多云","02":"阴","03":"阵雨","04":"雷阵雨","05":"雷阵雨伴有冰雹","06":"雨夹雪","07":"小雨","08":"中雨","09":"大雨","10":"暴雨","11":"大暴雨","12":"特大暴雨","13":"阵雪","14":"小雪","15":"中雪","16":"大雪","17":"暴雪","18":"雾","19":"冻雨","20":"沙尘暴","21":"小到中雨","22":"中到大雨","23":"大到暴雨","24":"暴雨到大暴雨","25":"大暴雨到特大暴雨","26":"小到中雪","27":"中到大雪","28":"大到暴雪","29":"浮尘","30":"扬沙","31":"强沙尘暴","53":"霾","99":""};
//定义风向数组
var fxArr={"0":"无持续风向","1":"东北风","2":"东风","3":"东南风","4":"南风","5":"西南风","6":"西风","7":"西北风","8":"北风","9":"旋转风"};
//定义风力数组
var flArr={"0":"微风","1":"3-4级","2":"4-5级","3":"5-6级","4":"6-7级","5":"7-8级","6":"8-9级","7":"9-10级","8":"10-11级","9":"11-12级"};
6天预报数据 URL:
该接口来源 *** ,应该是一个流传比较久的接口,大发现准确性和稳定性可能不稳定。接口分析如下:
{"weatherinfo":{
#基本信息
"city":"北京","city_en":"beijing","date_y":"2013年9月24日","date":"","week":"星期二","fchh":"11","cityid":"101010100",
#6天温度范围
"temp1":"22℃~11℃","temp2":"25℃~11℃","temp3":"26℃~13℃","temp4":"25℃~15℃","temp5":"25℃~16℃","temp6":"24℃~16℃",
#6天温度范围(华氏)
"tempF1":"71.6℉~51.8℉","tempF2":"77℉~51.8℉","tempF3":"78.8℉~55.4℉","tempF4":"77℉~59℉","tempF5":"77℉~60.8℉","tempF6":"75.2℉~60.8℉",
#6天天气
"weather1":"多云转晴","weather2":"晴","weather3":"晴","weather4":"晴转多云","weather5":"阴转阵雨","weather6":"多云",
#6天天气图示(每天2张)
"img1":"1","img2":"0","img3":"0","img4":"99","img5":"0","img6":"99","img7":"0","img8":"1","img9":"2","img10":"3","img11":"1","img12":"99",
"img_single":"1",
#6天天气图示文字(每天2)
"img_title1":"多","img_title2":"晴","img_title3":"晴","img_title4":"晴","img_title5":"晴","img_title6":"晴","img_title7":"晴","img_title8":"多云","img_title9":"阴","img_title10":"阵雨","img_title11":"多云","img_title12":"多云",
"img_title_single":"多云",
#6天风
"wind1":"北风3-4级转微风","wind2":"微风","wind3":"微风","wind4":"微风","wind5":"微风","wind6":"微风",
"fx1":"北风","fx2":"微风",
#6天风力情况
"fl1":"3-4级转小于3级","fl2":"小于3级","fl3":"小于3级","fl4":"小于3级","fl5":"小于3级","fl6":"小于3级",
#24小时内
"index":"较冷","index_d":"建议着大衣、呢外套加毛衣、卫衣等服装。体弱者宜着厚外套、厚毛衣。因昼夜温差较大,注意增减衣服。",
#48小时内
"index48":"较舒适","index48_d":"建议着薄外套或牛仔衫裤等服装。年老体弱者宜着夹克衫、薄毛衣等。昼夜温差较大,注意适当增减衣服。",
#紫外 洗车 旅游 舒适指数 晨练 晾晒 过敏
"index_uv":"弱",
"index48_uv":"强",
"index_xc":"适宜",
"index_tr":"适宜",
"index_co":"舒",
"st1":"21","st2":"12","st3":"24","st4":"12","st5":"25","st6":"14", #不明
"index_cl":"较适宜",
"index_ls":"适宜",
"index_ag":"极易发"
}}
Hackernews 编译,转载请注明出处: SonicWall 发布了安全更新,其中包含一个跨多个防火墙设备的关键漏洞,未经身份验证的远程攻击者可以将其武器化,以执行任意代码并导致拒绝服务(DoS)情况。 根据CVE-2022-22274 (CVSS 得分: 9.4)的跟踪记录,...
在西方云计算供应商撤出俄罗斯后,俄罗斯面临严峻的IT存储危机,在数据存储耗尽之前,俄罗斯只剩下两个月的时间。这些解决方案是在数字转型部举行的一次会议上提出的,出席会议的有Sberbank、MTS、Oxygen、Rostelecom、Atom-Data、Croc和Yandex的代表。 据俄罗斯新闻媒...
网络安全公司F-Secure正在对其企业安全业务进行品牌重塑,新名称为WithSecure,并设计了时髦的新标志。WithSecure以前被称为F-Secure Business,它将专注于企业安全产品和解决方案,而消费者安全产品和服务仍以现有的F-Secure名称提供。 据路透社报道,被全球数千家...
据德国媒体报道,德国执法机构在最近的执法行动中扣押俄罗斯暗网市场Hydra的服务器,同时收缴价值2500万美元的比特币。不知道这个黑市的创始人是不是漫威的粉丝,所以才会起九头蛇这个名字。 目前访问该市场会弹出德国执法机构挂出的提示,而收缴的2500万美元比特币只是很小的一部分,具体来说是4月5日的一...
据调查,在近半年的时间里,英国国家卫生系统(NHS)的100多名员工的工作电子邮件帐户被多次用于网络钓鱼活动,其中一些活动旨在窃取Microsoft登录信息。在劫持合法的NHS电子邮件帐户后,这些攻击者于去年10月开始使用它们,并至少在今年4月之前将其继续用于网络钓鱼活动。据电子邮件安全INKY的...
Google发布了一份新的勒索软件报告,以色列是在此期间最大的样本提交者。这家科技巨头委托网络安全公司VirusTotal进行分析,这需要审查来自140个国家的8000万个勒索软件样本。根据该报告,以色列、韩国、越南、新加坡、印度、哈萨克斯坦、菲律宾、伊朗和英国等国家是根据VirusTotal审查的...