4603| 13
|
[项目] 掌控板查天气 |
本帖最后由 潘虹辉 于 2019-7-30 06:10 编辑 这几天在试用掌握板,在Mind+里有个查天气的扩展模块,调用很方便,但是查出来的天气不准确。 在网上找了个免费免注册的查天气的网站API,试着用mPython X编了个掌控板查天气的程序,分享给大家 1、硬件 掌控板1块 2、软件 mPython X 0.3.3 3、查天气API 网址:http://www.tianqiapi.com 我使用的是查当天的天气,对应的参数是v6,七天的是v1,网站上有说明,有兴趣的可以自己去查。 接口使用的方法,访问网址: http://www.tianqiapi.com/api/?version=v6&city=北京 返回的数据如下: {"cityid":"101010100","date":"2019-07-29","week":"\u661f\u671f\u4e00","update_time":"21:30","city":"\u5317\u4eac","cityEn":"beijing","country":"\u4e2d\u56fd","countryEn":"China","wea":"\u9634","wea_img":"yin","tem":"23","tem1":"30","tem2":"22","win":"\u897f\u5357\u98ce","win_speed":"2\u7ea7","win_meter":"\u5c0f\u4e8e12km\/h","humidity":"92%","visibility":"4.65km","pressure":"997","air":"20","air_pm25":"20","air_level":"\u4f18","air_tips":"\u7a7a\u6c14\u5f88\u597d\uff0c\u53ef\u4ee5\u5916\u51fa\u6d3b\u52a8\uff0c\u547c\u5438\u65b0\u9c9c\u7a7a\u6c14\uff0c\u62e5\u62b1\u5927\u81ea\u7136\uff01","alarm":{"alarm_type":"","alarm_level":"","alarm_content":""}} 返回的 "country":"\u6fb3\u5927\u5229\u4e9a", 这种是Unicode编码 对应的数据如下 { "cityid":"101010100", "date":"2019-07-29", "week":"星期一", "update_time":"21:30", "city":"北京", "cityEn":"beijing", "country":"中国", "countryEn":"China", "wea":"阴", "wea_img":"yin", "tem":"23", "tem1":"30", "tem2":"22", "win":"西南风", "win_speed":"2级", "win_meter":"小于12km/h", "humidity":"92%", "visibility":"4.65km", "pressure":"997", "air":"20", "air_pm25":"20", "air_level":"优", "air_tips":"空气很好,可以外出活动,呼吸新鲜空气,拥抱大自然!", "alarm":{ "alarm_type":"", "alarm_level":"", "alarm_content":"" } } 对应的数据结构是字典 4、没有其它的接线,只用一块掌控板,程序如下 我没有设置城市,显示的就是当前IP所在城市的天气 为了方便查更多的城市天气,我在此基础上做了一个翻页的查天气程序,通过按键翻页,查找元组中所有城市的天气。 |
6.03 KB, 下载次数: 4455
源程序
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed