Atmospheric pressure | Wind |
Cloud | Visibility |
Jolt | Freezing |
#!/usr/bin/env python3
#-*utf-8*-
import requests
def get_weather():
# use api from [url=https://github.com/jokermonn/-Api/blob/master/CenterWeather.md]https://github.com/jokermonn/-Api/blob/master/CenterWeather.md[/url]
weather = requests.get('http://tj.nineton.cn/Heart/index/all',params = 'city=CHJS070000')
return weather.json()
status = get_weather()['status']
cond = get_weather()['weather'][0]['now']
tomorrow = get_weather()['weather'][0]['future'][1]
if status == 'OK':
print("********当前天气********")
print("当前城市:{0}\n当前天气状况: {1}\n温度: {2} ℃\n风向: {3}\n风速: {4} m/s\n风力大小: {5}\n空气湿度: {6}\n能见度: {7} km\n气压: {8} hPa".format(get_weather()['weather'][0]['city_name'], cond['text'], cond['temperature'], cond['wind_direction'], cond['wind_speed'], cond['wind_scale'], cond['humidity'], cond['visibility'], cond['pressure']))
print("********明日天气********")
print("明日天气情况:{0}\n风力大小:{1}".format(tomorrow["text"], tomorrow['wind']))
if '雨' not in tomorrow['text']:
affordable_wind = ('风力0级', '风力1级', '风力2级', '风力3级', '风力4级')
if tomorrow['wind'] in affordable_wind:
# 后续加入字体颜色
print("明日适宜飞行!")
# 绿灯亮
else:
# 后续加入字体颜色
print('明日不宜飞行!')
# 红灯亮
else:
print('failed to fetch weather condition of XuZhou!')
from pyfirmata import Arduino, util
from time import sleep
# 初始化串口
board = Arduino('COM5')
print("********传感器数据********")
it = util.Iterator(board)
it.start()
board.analog[0].enable_reporting()
sleep(1) # 缓冲时间
# 待补充DHT11以及校准光敏传感器
print("环境亮度:{0}\n环境温度:{1}\n环境湿度:{2}\n".format(board.analog[0].read(), "N/A", "N/A"))
board.analog[0].disable_reporting()
# 绿灯亮
board.digital[9].write(1)
sleep(5)
board.digital[9].write(0)
# 红灯亮
board.digital[10].write(1)
sleep(5)
board.digital[10].write(0)