全部mpy增加心知天气、网络请求、ds18x20

This commit is contained in:
Irene-Maxine
2024-09-28 00:08:39 +08:00
parent 1d2957442b
commit 93cb1f887e
66 changed files with 2992 additions and 1194 deletions

View File

@@ -1463,7 +1463,7 @@ export const draw_pointer = {
.appendField(Blockly.Msg.DRAW_POINTER_ANGLE);
this.appendValueInput('angle');
this.appendDummyInput()
.appendField('°');
.appendField(Blockly.Msg.MIXLY_DRAW_POINTER_DU);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setInputsInline(true);

View File

@@ -297,11 +297,11 @@ export const sensor_sht = {
}
};
export const sensor_ds18x20 = {
export const sensor_DS18X20 = {
init: function () {
this.setColour(SENSOR_EXTERN_HUE);
this.appendValueInput("PIN", Number)
.appendField("DS18x20 " + Blockly.Msg.MIXLY_PIN)
.appendField("DS18X20 " + Blockly.Msg.MIXLY_PIN)
.setCheck(Number);
this.appendDummyInput("")
.appendField(Blockly.Msg.MIXLY_GETTEMPERATUE);
@@ -311,8 +311,6 @@ export const sensor_ds18x20 = {
}
};
export const sensor_lm35 = {
init: function () {
this.setColour(SENSOR_EXTERN_HUE);

View File

@@ -61,4 +61,307 @@ export const WEATHER_HOUR = {
this.setInputsInline(true);
this.setOutput(true);
}
}
export const Weather_now ={
init: function() {
this.setColour(WEATHER_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MSG.catweather)
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_WEATHER_NOW, "Weather_now"],
[Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_WEATHER_ALARM, "weather_alarm"],
[Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_AIR_NOW, "air_now"],
[Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_TIDE_DAILY, "tide_daily"],
[Blockly.Msg.MIXLY_WEB_PLACE+Blockly.Msg.HTML_SEARCH, "location_search"],
[Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_LIFE_SUGGESTION,"Life_suggestion"]
]), "mode");
this.appendValueInput('key')
.appendField(Blockly.Msg.MIXLY_API_PRIVATE_KEY);
this.appendValueInput('addr')
.appendField(Blockly.Msg.MIXLY_GEOGRAPHIC_LOCATION);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
}
};
export const Weather_now_content={
init: function() {
this.setColour(WEATHER_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_WEATHER_NOW+Blockly.Msg.MIXLY_BELONG);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_PARAMETER_FREE,"none"],
[Blockly.Msg.MIXLY_WEATHER_PHENOMENON, "text"],
[Blockly.Msg.MIXLY_WEATHER_PHENOMENON_CODE, "code"],
[Blockly.Msg.MIXLY_TEMPERATURE+Blockly.Msg.MIXLY_TEMPERATURE_UNIT_, "temperature"],
[Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_WEATHER_NOW_FEEL, "feels_like"],
[Blockly.Msg.MIXLY_Altitude+Blockly.Msg.MIXLY_PRESSURE_UNIT, "pressure"],
[Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_WEATHER_NOW_HUMIDITY, "humidity"],
[Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_WEATHER_NOW_VISIBILITY, "visibility"],
[Blockly.Msg.ForecastFx, "wind_direction"],
[Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_WEATHER_NOW_WIND_DIRECT_DEGREE, "wind_direction_degree"],
[Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_WEATHER_NOW_WIND_SPEED, "wind_speed"],
[Blockly.Msg.MIXLY_WIND_RATING, "wind_scale"],
[Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_WEATHER_NOW_CLOUDS, "clouds"]
]), "content");
this.setInputsInline(true);
this.setOutput(true);
}
};
export const Air_now_content ={
init: function() {
this.setColour(WEATHER_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_AIR_NOW+Blockly.Msg.MIXLY_BELONG);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_PARAMETER_FREE,"none"],
[Blockly.Msg.MIXLY_AIR_NOW_AIRQUAILTY, "api"],
[Blockly.Msg.MIXLY_AIR_NOW_PM25, "pm25"],
[Blockly.Msg.MIXLY_AIR_NOW_PM10, "pm10"],
[Blockly.Msg.MIXLY_AIR_NOW_so2, "so2"],
[Blockly.Msg.MIXLY_AIR_NOW_no2, "no2"],
[Blockly.Msg.MIXLY_AIR_NOW_co, "co"],
[Blockly.Msg.MIXLY_AIR_NOW_o3, "o3"],
[Blockly.Msg.MIXLY_AIR_NOW_pp, "primary_pollutant"],
[Blockly.Msg.MIXLY_AIR_NOW_quailty, "quality"],
[Blockly.Msg.MIXLY_AIR_NOW_last_update, "last_update"]
]), "content");
this.setInputsInline(true);
this.setOutput(true);
}
};
export const Weather_alarm_content ={
init: function() {
this.setColour(WEATHER_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_WEATHER_ALARM+Blockly.Msg.MIXLY_BELONG);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_PARAMETER_FREE,"none"],
[Blockly.Msg.MIXLY_WEATHER_ALARM_TITLE, "title"],
[Blockly.Msg.MIXLY_WEATHER_ALARM_TYPE, "type"],
[Blockly.Msg.MIXLY_WEATHER_ALARM_LEVEL, "level"],
[Blockly.Msg.MIXLY_WEATHER_ALARM_DESCRIPTION, "description"],
[Blockly.Msg.MIXLY_WEATHER_ALARM_PUB_DATE, "pub_date"]
]), "content");
this.setInputsInline(true);
this.setOutput(true);
}
};
export const Life_suggestion_content ={
init: function() {
this.setColour(WEATHER_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_LIFE_SUGGESTION+Blockly.Msg.MIXLY_BELONG);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_PARAMETER_FREE,"none"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_AC, "ac"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_AP, "air_pollution"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_AIRING, "airing"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_ALLERGY, "allergy"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_BEER, "beer"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_BOATING, "boating"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_CAR_WS, "car_washing"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_CHILL, "chill"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_COMFORT, "comfort"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_DATING, "dating"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_DRESSING, "dressing"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_FISHING, "fishing"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_FLU, "flu"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_HAIR_DRESS, "hair_dressing"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_KITEFLYING, "kiteflying"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_MAKEUP, "makeup"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_MOOD, "mood"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_MORNINIG_SPORT, "morning_sport"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_NIGHT_LIFE, "night_life"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_ROAD_CONDI, "road_condition"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_SHOPPING, "shopping"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_SPORT, "sport"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_SUNSCREEN, "sunscreen"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_TRAFFIC, "traffic"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_TRAVEL, "travel"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_UMBRELLA, "umbrella"],
[Blockly.Msg.MIXLY_LIFE_SUGGESTION_UV, "uv"]
]), "content");
this.setInputsInline(true);
this.setOutput(true);
}
};
export const Tide_daily_content ={
init: function() {
this.setColour(WEATHER_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_TIDE_DAILY+Blockly.Msg.MIXLY_BELONG);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_PARAMETER_FREE,"none"],
[Blockly.Msg.MIXLY_GPS_DATE, "date"],
[Blockly.Msg.MIXLY_TIDE_DAILY_HEIGHT, "tide"],
[Blockly.Msg.MIXLY_TIDE_DAILY_0_TIME, "0,time"],
[Blockly.Msg.MIXLY_TIDE_DAILY_0_HEIGHT, "0,height"],
[Blockly.Msg.MIXLY_TIDE_DAILY_1_TIME, "1,time"],
[Blockly.Msg.MIXLY_TIDE_DAILY_1_HEIGHT, "1,height"],
[Blockly.Msg.MIXLY_TIDE_DAILY_2_TIME, "2,time"],
[Blockly.Msg.MIXLY_TIDE_DAILY_2_HEIGHT, "2,height"],
[Blockly.Msg.MIXLY_TIDE_DAILY_3_TIME, "3,time"],
[Blockly.Msg.MIXLY_TIDE_DAILY_3_HEIGHT, "3,height"]
]), "content");
this.setInputsInline(true);
this.setOutput(true);
}
};
export const Location_search_content ={
init: function() {
this.setColour(WEATHER_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_WEB_PLACE+Blockly.Msg.HTML_SEARCH+Blockly.Msg.MIXLY_BELONG);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_PARAMETER_FREE,"none"],
[Blockly.Msg.MIXLY_LOCATION_SEARCH_ID, "id"],
[Blockly.Msg.MIXLY_LOCATION_SEARCH_NAME, "name"],
[Blockly.Msg.MIXLY_LOCATION_SEARCH_COUNTRY, "country"],
[Blockly.Msg.MIXLY_LOCATION_SEARCH_PATH, "path"],
[Blockly.Msg.MIXLY_LOCATION_SEARCH_TIMEZONE, "timezone"],
[Blockly.Msg.MIXLY_LOCATION_SEARCH_TIMEZONE_O, "timezone_offset"]
]), "content");
this.setInputsInline(true);
this.setOutput(true);
}
};
export const Weather_daily ={
init: function() {
this.setColour(WEATHER_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MSG.catweather)
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_WEATHER_DAILY, "Weather_daily"],
[Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_AIR_DAILY, "Air_daily"],
[Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_GEO_SUN, "Geo_sun"],
[Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_GEO_MOON, "Geo_moon"]
]), "mode");
this.appendValueInput('key')
.appendField(Blockly.Msg.MIXLY_API_PRIVATE_KEY);
this.appendValueInput('addr')
.appendField(Blockly.Msg.MIXLY_GEOGRAPHIC_LOCATION);
this.appendValueInput('day')
.appendField(Blockly.Msg.MIXLY_WEB_DAILY);
this.setInputsInline(true);
this.setPreviousStatement(true);
this.setNextStatement(true);
}
};
export const Weather_daily_content ={
init: function() {
this.setColour(WEATHER_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_WEATHER_DAILY);
this.appendValueInput('day')
.appendField(Blockly.Msg.LISTS_GET_INDEX_FROM_START);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_WEATHER_DAILY_DAY+Blockly.Msg.MIXLY_BELONG);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_PARAMETER_FREE,"none"],
[Blockly.Msg.MIXLY_GPS_DATE, "date"],
[Blockly.Msg.MIXLY_DAYTIME_WEATHER_PHENOMENON, "text_day"],
[Blockly.Msg.MIXLY_DAYTIME_WEATHER_PHENOMENON_CODE, "code_day"],
[Blockly.Msg.MIXLY_EVENING_WEATHER_PHENOMENON, "text_night"],
[Blockly.Msg.MIXLY_EVENING_WEATHER_PHENOMENON_CODE, "code_night"],
[Blockly.Msg.ForecastHigh+Blockly.Msg.MIXLY_TEMPERATURE_UNIT_ , "high"],
[Blockly.Msg.ForecastLow+Blockly.Msg.MIXLY_TEMPERATURE_UNIT_, "low"],
[Blockly.Msg.MIXLY_PROBABILITY_OF_PRECIPITATION, "precip"],
[Blockly.Msg.ForecastFx, "wind_direction"],
[Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_WEATHER_NOW_WIND_DIRECT_DEGREE, "wind_direction_degree"],
[Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_WEATHER_NOW_WIND_SPEED, "wind_speed"],
[Blockly.Msg.MIXLY_WIND_RATING, "wind_scale"],
[Blockly.Msg.MIXLY_RAINFALL,"rainfall"],
[Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_WEATHER_NOW_HUMIDITY, "humidity"]
]), "content");
this.setInputsInline(true);
this.setOutput(true);
}
};
export const Air_daily_content ={
init: function() {
this.setColour(WEATHER_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_AIR_DAILY);
this.appendValueInput('day')
.appendField(Blockly.Msg.LISTS_GET_INDEX_FROM_START);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_WEATHER_DAILY_DAY+Blockly.Msg.MIXLY_BELONG);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_PARAMETER_FREE,"none"],
[Blockly.Msg.MIXLY_AIR_NOW_AIRQUAILTY, "api"],
[Blockly.Msg.MIXLY_AIR_NOW_PM25, "pm25"],
[Blockly.Msg.MIXLY_AIR_NOW_PM10, "pm10"],
[Blockly.Msg.MIXLY_AIR_NOW_so2, "so2"],
[Blockly.Msg.MIXLY_AIR_NOW_no2, "no2"],
[Blockly.Msg.MIXLY_AIR_NOW_co, "co"],
[Blockly.Msg.MIXLY_AIR_NOW_o3, "o3"],
[Blockly.Msg.MIXLY_AIR_NOW_quailty, "quality"],
[Blockly.Msg.MIXLY_GPS_DATE, "date"]
]), "content");
this.setInputsInline(true);
this.setOutput(true);
}
};
export const Geo_sun_content ={
init: function() {
this.setColour(WEATHER_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_GEO_SUN);
this.appendValueInput('day')
.appendField(Blockly.Msg.LISTS_GET_INDEX_FROM_START);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_WEATHER_DAILY_DAY+Blockly.Msg.MIXLY_BELONG);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_PARAMETER_FREE,"none"],
[Blockly.Msg.MIXLY_GPS_DATE, "date"],
[Blockly.Msg.MIXLY_SUNRISE_T, "sunrise"],
[Blockly.Msg.MIXLY_SUNSET_T, "sunset"]
]), "content");
this.setInputsInline(true);
this.setOutput(true);
}
};
export const Geo_moon_content ={
init: function() {
this.setColour(WEATHER_HUE);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_GEO_MOON);
this.appendValueInput('day')
.appendField(Blockly.Msg.LISTS_GET_INDEX_FROM_START);
this.appendDummyInput()
.appendField(Blockly.Msg.MIXLY_WEB_DATA_SENIVERSE_GET_WEATHER_DAILY_DAY+Blockly.Msg.MIXLY_BELONG);
this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([
[Blockly.Msg.MIXLY_PARAMETER_FREE,"none"],
[Blockly.Msg.MIXLY_GPS_DATE, "date"],
[Blockly.Msg.MIXLT_MOONRISE_T, "rise"],
[Blockly.Msg.MIXLY_MOONSET_T, "set"],
[Blockly.Msg.MIXLY_MOON_FRACTION, "fraction"],
[Blockly.Msg.MIXLY_MOON_PHASE, "phase"],
[Blockly.Msg.MIXLY_MOON_PHASE_NAME , "phase_name"]
]), "content");
this.setInputsInline(true);
this.setOutput(true);
}
};

View File

@@ -845,4 +845,12 @@ export const sensor_weather_solo_rain = function (_, generator) {
var key = this.getFieldValue('key');
var code = sub + '.rain_count(' + time + ')' + key + '';
return [code, generator.ORDER_ATOMIC];
}
}
export const sensor_DS18X20 = function(_, generator){
generator.definitions_['import_DS18X20'] = 'from ds18b20 import DS18X20';
var dropdown_pin = generator.valueToCode(this, 'PIN', generator.ORDER_ATOMIC);
var code ='DS18X20('+dropdown_pin+').temperature()';
return [code, generator.ORDER_ATOMIC];
};

View File

@@ -24,4 +24,151 @@ export const WEATHER_HOUR = function (_, generator) {
var hour = generator.valueToCode(this, 'hour', generator.ORDER_ATOMIC);
var code = 'seniverse_api.weather_hourly(' + key + ',' + addr + ',' + hour + ')';
return [code, generator.ORDER_ATOMIC];
}
}
export const Weather_now = function(_, generator) {
generator.definitions_['import_seniverse_api*'] = "from seniverse_api import *";
var dropdown_mode = this.getFieldValue('mode');
var key = generator.valueToCode(this, 'key', generator.ORDER_ATOMIC) ;
var addr = generator.valueToCode(this, 'addr', generator.ORDER_ATOMIC) ;
var code =dropdown_mode+'.request(' + key + ',' + addr + ')\n';
return code;
};
export const Weather_now_content = function(_, generator) {
generator.definitions_['import_seniverse_api*'] = "from seniverse_api import *";
var content= this.getFieldValue('content');
if (content == 'none'){
var code = 'Weather_now.analysis()';
}
else{
var code ='Weather_now.analysis(\"' + content + '\")';
}
return [code, generator.ORDER_ATOMIC];
};
export const Air_now_content = function(blo_, generatorck) {
generator.definitions_['import_seniverse_api*'] = "from seniverse_api import *";
var content= this.getFieldValue('content');
if (content == 'none'){
var code = 'Air_now.analysis()';
}
else{
var code ='Air_now.analysis(\"' + content + '\")';
}
return [code, generator.ORDER_ATOMIC];
};
export const Weather_alarm_content = function(_, generator) {
generator.definitions_['import_seniverse_api*'] = "from seniverse_api import *";
var content= this.getFieldValue('content');
if (content == 'none'){
var code = 'Weather_alarm.analysis()';
}
else{
var code ='Weather_alarm.analysis(\"' + content + '\")';
}
return [code, generator.ORDER_ATOMIC];
};
export const Life_suggestion_content = function(_, generator) {
generator.definitions_['import_seniverse_api*'] = "from seniverse_api import *";
var content= this.getFieldValue('content');
if (content == 'none'){
var code = 'Life_suggestion.analysis()';
}
else{
var code ='Life_suggestion.analysis(\"' + content + '\")';
}
return [code, generator.ORDER_ATOMIC];
};
export const Tide_daily_content = function(_, generator) {
generator.definitions_['import_seniverse_api*'] = "from seniverse_api import *";
var content= this.getFieldValue('content');
if (content == 'none'){
var code = 'Tide_daily.analysis()';
}
else{
var code ='Tide_daily.analysis(\"' + content + '\")';
}
return [code, generator.ORDER_ATOMIC];
};
export const Location_search_content = function(_, generator) {
generator.definitions_['import_seniverse_api*'] = "from seniverse_api import *";
var content= this.getFieldValue('content');
if (content == 'none'){
var code = 'Location_search.analysis()';
}
else{
var code ='Location_search.analysis(\"' + content + '\")';
}
return [code, generator.ORDER_ATOMIC];
};
export const Weather_daily = function(_, generator) {
generator.definitions_['import_seniverse_api*'] = "from seniverse_api import *";
var dropdown_mode = this.getFieldValue('mode');
var key = generator.valueToCode(this, 'key', generator.ORDER_ATOMIC) ;
var addr = generator.valueToCode(this, 'addr', generator.ORDER_ATOMIC) ;
var day = generator.valueToCode(this, 'day', generator.ORDER_ATOMIC) ;
var code =dropdown_mode+'.request(' + key + ',' + addr + ',' + day + ')\n';
return code;
};
export const Weather_daily_content = function(_, generator) {
generator.definitions_['import_seniverse_api*'] = "from seniverse_api import *";
var content= this.getFieldValue('content');
var day = generator.valueToCode(this, 'day', generator.ORDER_ATOMIC);
var index = day-1;
if (content == 'none'){
var code = 'Weather_daily.analysis()';
}
else{
var code ='Weather_daily.analysis('+ index +',\"' + content + '\")';
}
return [code, generator.ORDER_ATOMIC];
};
export const Air_daily_content = function(_, generator) {
generator.definitions_['import_seniverse_api*'] = "from seniverse_api import *";
var content= this.getFieldValue('content');
var day = generator.valueToCode(this, 'day', generator.ORDER_ATOMIC);
var index = day-1;
if (content == 'none'){
var code = 'Air_daily.analysis()';
}
else{
var code ='Air_daily.analysis('+ index +',\"' + content + '\")';
}
return [code, generator.ORDER_ATOMIC];
};
export const Geo_sun_content = function(_, generator) {
generator.definitions_['import_seniverse_api*'] = "from seniverse_api import *";
var content= this.getFieldValue('content');
var day = generator.valueToCode(this, 'day', generator.ORDER_ATOMIC);
var index = day-1;
if (content == 'none'){
var code = 'Geo_sun.analysis()';
}
else{
var code ='Geo_sun.analysis('+ index +',\"' + content + '\")';
}
return [code, generator.ORDER_ATOMIC];
};
export const Geo_moon_content = function(_, generator) {
generator.definitions_['import_seniverse_api*'] = "from seniverse_api import *";
var content= this.getFieldValue('content');
var day = generator.valueToCode(this, 'day', generator.ORDER_ATOMIC);
var index = day-1;
if (content == 'none'){
var code = 'Geo_moon.analysis()';
}
else{
var code ='Geo_moon.analysis('+ index +',\"' + content + '\")';
}
return [code, generator.ORDER_ATOMIC];
};

View File

@@ -0,0 +1,65 @@
# DS18x20 temperature sensor driver for MicroPython.
# MIT license; Copyright (c) 2016 Damien P. George
import onewire
from machine import Pin
from micropython import const
_CONVERT = const(0x44)
_RD_SCRATCH = const(0xBE)
_WR_SCRATCH = const(0x4E)
class DS18X20:
__species = {}
__first_init = True
def __new__(cls, pin, *args, **kwargs):
if pin not in cls.__species.keys():
cls.__first_init = True
cls.__species[pin] = object.__new__(cls)
return cls.__species[pin]
def __init__(self, pin):
if self.__first_init:
self.__first_init = False
self._ow = onewire.OneWire(Pin(pin, pull=Pin.PULL_UP))
self._buf = bytearray(9)
self._roms = self.scan()
def scan(self):
return [rom for rom in self._ow.scan() if rom[0] in (0x10, 0x22, 0x28)]
def convert_temp(self):
self._ow.reset(True)
self._ow.writebyte(self._ow.SKIP_ROM)
self._ow.writebyte(_CONVERT)
def read_scratch(self, rom):
self._ow.reset(True)
self._ow.select_rom(rom)
self._ow.writebyte(_RD_SCRATCH)
self._ow.readinto(self._buf)
if self._ow.crc8(self._buf):
raise Exception("CRC error")
return self._buf
def read_temp(self, rom):
buf = self.read_scratch(rom)
if rom[0] == 0x10:
if buf[1]:
t = buf[0] >> 1 | 0x80
t = -((~t + 1) & 0xFF)
else:
t = buf[0] >> 1
return t - 0.25 + (buf[7] - buf[6]) / buf[7]
else:
t = buf[1] << 8 | buf[0]
if t & 0x8000: # sign bit set
t = -((t ^ 0xFFFF) + 1)
return t / 16
def temperature(self):
temp = []
self.convert_temp()
for rom in self._roms:
temp.append(round(self.read_temp(rom), 2))
return temp [0] if len(temp) == 1 else tuple(temp)

View File

@@ -20,115 +20,198 @@ _weather_alarm="http://api.seniverse.com/v3/weather/alarm.json?" #气象灾害
_life_suggestion="http://api.seniverse.com/v3/life/suggestion.json?" #生活指数
_air_now="http://api.seniverse.com/v3/air/now.json?" #空气质量实况
_air_daily="http://api.seniverse.com/v3/air/daily.json?" #逐日空气质量预报
_tide_daily="http://api.seniverse.com/v3/tide/daily.json?" #逐小时潮汐预报
_air_hourly="http://api.seniverse.com/v3/air/hourly.json?" #逐时空气质量预报
_tide_daily="http://api.seniverse.com/v3/tide/daily.json?" #逐时潮汐预报
_geo_sun="http://api.seniverse.com/v3/geo/sun.json?" #日出日落
_geo_moon="http://api.seniverse.com/v3/geo/moon.json?" #月出月落和月相
_location_search="http://api.seniverse.com/v3/location/search.json?" #城市搜索
#数据请求
def _urequests_api(url):
try:
results=json.loads(urequests.post(url).text)
except Exception as e:
raise RuntimeError("API request failed or WiFi is not connected",e)
if "status" in results.keys():
raise ValueError(results["status"])
if "results" in results.keys():
return results["results"]
#天气实况 https://docs.seniverse.com/api/weather/now.html
def weather_now(key,location):
url="{}key={}&location={}".format(_weather_now,key,location)
results=_urequests_api(url)[0]
return results['now']
class API_BASE:
_results = None
def _urequests_api(self, url):
try:
results=json.loads(urequests.post(url).text)
except Exception as e:
raise RuntimeError("API request failed or WiFi is not connected",e)
if "status" in results.keys():
raise ValueError(results["status"])
if "results" in results.keys():
return results["results"]
#天气实况 https://docs.seniverse.com/api/weather/now.html
class Weather_now(API_BASE):
def request(self, key, location):
url = "{}key={}&location={}".format(_weather_now, key, location)
self._results = self._urequests_api(url)[0]['now']
def analysis(self, key=None):
if key is None:
return self._results
else:
return self._results[key]
Weather_now = Weather_now()
#逐日天气预报 https://docs.seniverse.com/api/weather/daily.html
def weather_daily(key,location,days=1):
url="{}key={}&location={}&days={}".format(_weather_daily,key,location,days)
results=_urequests_api(url)[0]
data=[]
for i in range(len(results['daily'])):
data.append(results['daily'][i])
return tuple(data)
class Weather_daily(API_BASE):
def request(self, key, location, days=1):
url = "{}key={}&location={}&days={}".format(_weather_daily, key, location, days)
self._results = self._urequests_api(url)[0]['daily']
def analysis(self, days=1, key=None):
if key is None:
return self._results[days]
else:
return self._results[days][key]
Weather_daily = Weather_daily()
#逐时天气预报 https://docs.seniverse.com/api/weather/hourly.html
def weather_hourly(key,location,hours=1):
url="{}key={}&location={}&hours={}".format(_weather_hourly,key,location,hours)
results=_urequests_api(url)[0]
data=[]
for i in range(len(results['hourly'])):
data.append(results['hourly'][i])
return tuple(data)
class Weather_hourly(API_BASE):
def request(self, key, location, hours=1):
url = "{}key={}&location={}&hours={}".format(_weather_hourly, key, location, hours)
self._results = self._urequests_api(url)[0]['hourly']
#气象灾害预警 https://docs.seniverse.com/api/weather/alarm.html
def weather_alarm(key,location):
url="{}key={}&location={}".format(_weather_alarm,key,location)
results=_urequests_api(url)[0]
data=[]
for i in range(len(results['alarms'])):
data.append(results['alarms'][i])
return tuple(data)
def analysis(self, hours=1, key=None):
if key is None:
return self._results[hours]
else:
return self._results[hours][key]
#生活指数 https://docs.seniverse.com/api/life/suggestion.html
def life_suggestion(key,location,days=1):
url="{}key={}&location={}&days={}".format(_life_suggestion,key,location,days)
results=_urequests_api(url)[0]
data=[]
for i in range(len(results['suggestion'])):
data.append(results['suggestion'][i])
return tuple(data)
#Weather_hourly = Weather_hourly() #暂不开启
#空气质量实况 https://docs.seniverse.com/api/air/now.html
def air_now(key,location):
url="{}key={}&location={}&scope=city".format(_air_now,key,location)
results=_urequests_api(url)[0]
return results['air']['city']
#逐日空气质量预报 https://docs.seniverse.com/api/air/daily5d.html
def air_daily(key,location,days=1):
url="{}key={}&location={}&days={}".format(_air_daily,key,location,days)
results=_urequests_api(url)[0]
data=[]
for i in range(len(results['daily'])):
data.append(results['daily'][i])
return tuple(data)
class Air_now(API_BASE):
def request(self, key, location):
url = "{}key={}&location={}&scope=city".format(_air_now, key, location)
self._results = self._urequests_api(url)[0]['air']['city']
#逐时潮汐预报 https://docs.seniverse.com/api/ocean/tide.html
def tide_daily(key,location):
url="{}key={}&location={}&days=1".format(_tide_daily,key,location)
results=_urequests_api(url)[0]
data=[]
for i in range(len(results['ports'])):
data.append({'port':results['ports'][i]['port'],
'tide':results['ports'][i]['data'][0]['tide'],
'range':results['ports'][i]['data'][0]['range']})
return tuple(data)
def analysis(self, key=None):
if key is None:
return self._results
else:
return self._results[key]
Air_now = Air_now()
#逐日空气质量预报 https://docs.seniverse.com/api/air/daily5d.html
class Air_daily(API_BASE):
def request(self, key, location, days=1):
url = "{}key={}&location={}&days={}".format(_air_daily, key, location, days)
self._results = self._urequests_api(url)[0]['daily']
def analysis(self, days=1, key=None):
if key is None:
return self._results[days]
else:
return self._results[days][key]
Air_daily= Air_daily()
#逐时空气质量预报 https://docs.seniverse.com/api/air/hourly5d.html
class Air_hourly(API_BASE):
def request(self, key, location, hours=1):
url = "{}key={}&location={}&hours={}&days=1".format(_air_hourly, key, location, hours)
self._results = self._urequests_api(url)[0]['hourly']
def analysis(self, hours=1, key=None):
if key is None:
return self._results[hours]
else:
return self._results[hours][key]
#Air_hourly = Air_hourly() #暂不开启
#气象灾害预警 https://docs.seniverse.com/api/weather/alarm.html
class Weather_alarm(API_BASE):
def request(self, key, location):
url = "{}key={}&location={}".format(_weather_alarm, key, location)
results = self._urequests_api(url)[0]['alarms']
self._results = results[0] if results else {}
def analysis(self, key=None):
if key is None:
return self._results
if key in self._results.keys():
return self._results[key]
Weather_alarm = Weather_alarm()
#生活指数 https://docs.seniverse.com/api/life/suggestion.html
class Life_suggestion(API_BASE):
def request(self, key, location):
url = "{}key={}&location={}".format(_life_suggestion, key, location)
self._results = self._urequests_api(url)[0]['suggestion']
def analysis(self, key=None, brief=False):
if key is None:
return self._results
else:
return self._results[key]['brief'] if brief else self._results[key]['details']
Life_suggestion = Life_suggestion()
#24时潮汐预报 https://docs.seniverse.com/api/ocean/tide.html
class Tide_daily(API_BASE):
def request(self, key, location):
url = "{}key={}&location={}&days=1".format(_tide_daily, key, location)
self._results = self._urequests_api(url)[0]['ports'][0]['data'][0]
def analysis(self, key=None):
if key is None:
return self._results
else:
key = key.split(',')
if len(key) == 1:
return self._results[key[0]]
if len(key) == 2:
return self._results['range'][int(key[0])][key[1]]
Tide_daily = Tide_daily()
#日出日落 https://docs.seniverse.com/api/geo/sun.html
def geo_sun(key,location,days=1):
url="{}key={}&location={}&days={}".format(_geo_sun,key,location,days)
results=_urequests_api(url)[0]
data=[]
for i in range(len(results['sun'])):
data.append(results['sun'][i])
return tuple(data)
class Geo_sun(API_BASE):
def request(self, key, location, days=1):
url = "{}key={}&location={}&days={}".format(_geo_sun, key, location, days)
self._results = self._urequests_api(url)[0]['sun']
def analysis(self, days=1, key=None):
if key is None:
return self._results[days]
else:
return self._results[days][key]
Geo_sun = Geo_sun()
#月出月落和月相 https://docs.seniverse.com/api/geo/moon.html
def geo_moon(key,location,days=1):
url="{}key={}&location={}&days={}".format(_geo_moon,key,location,days)
results=_urequests_api(url)[0]
data=[]
for i in range(len(results['moon'])):
data.append(results['moon'][i])
return tuple(data)
class Geo_moon(API_BASE):
def request(self, key, location, days=1):
url = "{}key={}&location={}&days={}".format(_geo_moon, key, location, days)
self._results = self._urequests_api(url)[0]['moon']
def analysis(self, days=1, key=None):
if key is None:
return self._results[days]
else:
return self._results[days][key]
Geo_moon = Geo_moon()
#城市搜索 https://docs.seniverse.com/api/fct/search.html
def location_search(key,location):
url="{}key={}&q={}&limit=50".format(_location_search,key,location)
results=_urequests_api(url)
data=[]
for i in range(len(results)):
data.append(results[i])
return tuple(data)
class Location_search(API_BASE):
def request(self, key, location):
url = "{}key={}&q={}&limit=50".format(_location_search, key, location)
results = self._urequests_api(url)
self._results = results[0] if results else {}
def analysis(self, key=None):
if key is None:
return self._results
else:
if key in self._results.keys():
return self._results[key]
Location_search = Location_search()