03-高德天气
前言
日常出行,掌握天气情况是十分有必要的。本节教程跟着我们的指引,来制作一个可以获取天气状况的手表
积木说明
序号 | 积木 | 说明 |
---|---|---|
01 | 高德天气的使用API,需要注册使用 | |
02 | 获取指定城市的天气实况 读取之后,更新得到的天气数据情况 | |
03 | 读取指定城市的天气预报,可以指定天数读取之后,更新得到的天气数据情况 | |
04 | 实况天气的各项数据,天气状况、温度、风向、风力等级、湿度 | |
05 | 天气预报的各项情况,天气状况、温度、风向、风力等级,白天和晚上数据都可以查询 |
高德天气注册
🚀 高德开放平台地址:https://developer.amap.com/
- 按照下图步骤进行个人开发者账号注册
- 注册成功后登录,打开——Web服务API,申请Key
- 申请Key需要先创建应用
- 得到Key
程序案例
示例程序📋:实况天气
#/bin/python
from future import *
from time import sleep
from kwatch import *
x = 0
screen.sync = 0
sleep(3)
if not wifi.sta.isconnected():
wifi.connect(str("xxx"), "xxx")
sleep(1)
weather = Weather("xxx")
weather.getActual("深圳")
while True:
screen.fill((0, 0, 0))
screen.textCh(str("天气状况:")+str(weather.condition()),5,10,1,(0, 119, 255))
screen.textCh(str("温度:")+str(weather.temp()),5,35,1,(0, 119, 255))
screen.textCh(str("风向:")+str(weather.winddir()),5,60,1,(0, 119, 255))
screen.textCh(str("风力等级:")+str(weather.windpw()),5,85,1,(0, 119, 255))
screen.textCh(str("湿度:")+str(weather.humi()),5,110,1,(0, 119, 255))
screen.refresh()
sleep(1)
实物效果图
示例程序📋:天气预报
#/bin/python
from future import *
from time import sleep
from kwatch import *
x = 1
screen.sync = 0
sleep(3)
if not wifi.sta.isconnected():
wifi.connect(str("xxx"), "xxx")
sleep(1)
weather = Weather("xxx")
weather.getForecast("深圳",1)
x = 1
while True:
if sensor.btnValue('a'):
x = (x * -1)
screen.fill((0, 0, 0))
if x == 1:
screen.textCh(str("天气状况:")+str(weather.dayweather()),5,10,1,(0, 119, 255))
screen.textCh(str("温度:")+str(weather.daytemp()),5,35,1,(0, 119, 255))
screen.textCh(str("风向:")+str(weather.daywind()),5,60,1,(0, 119, 255))
screen.textCh(str("风力等级:")+str(weather.daypower()),5,85,1,(0, 119, 255))
else:
screen.textCh(str("天气状况:")+str(weather.nightweather()),5,10,1,(0, 119, 255))
screen.textCh(str("温度:")+str(weather.nighttemp()),5,35,1,(0, 119, 255))
screen.textCh(str("风向:")+str(weather.nightwind()),5,60,1,(0, 119, 255))
screen.textCh(str("风力等级:")+str(weather.nightpower()),5,85,1,(0, 119, 255))
screen.refresh()
sleep(1)
实物效果图