本教程教你在Script中如何获取天气信息

1:新建一个Script Node 双击进入脚本编辑器
a.添加Inputs变量

b.添加Outputs变量

c.代码覆盖
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Ventuz.Kernel;using System.IO;
using System.IO.Compression;
using System.Text.RegularExpressions;
using System.Net;
using System.Text;/// <summary>
/// 会自动执行一次更新
/// 修改CityName或者调用ReGetData方法就可以更新数据
/// </summary>
public class Script : ScriptBase, System.IDisposable
{public class HTTPS{public delegate void AsyncRequestHandler(string data, string url, System.Action<string> callback);public static void AsyncRequest(string data, string url, System.Action<string> callback) {AsyncRequestHandler ar = AsyncRequestMethod;ar.BeginInvoke(data, url, callback, null, null);}private static void AsyncRequestMethod(string data, string url, System.Action<string> callback){string result = Request(data, url);if (callback != null){callback(result);}}public static string Request(string data, string url){return Request(Encoding.GetEncoding("UTF-8").GetBytes(data), url);}public static string Request(byte[] data, string url){string result = string.Empty;//创建一个客户端的Http请求实例HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;request.ContentType = "application/x-www-form-urlencoded";request.Method = "POST";request.ContentLength = data.Length;Stream requestStream = request.GetRequestStream();requestStream.Write(data, 0, data.Length);requestStream.Close();//获取当前Http请求的响应实例HttpWebResponse response = request.GetResponse() as HttpWebResponse;Stream responseStream = response.GetResponseStream();using (StreamReader reader = new StreamReader(responseStream, Encoding.GetEncoding("UTF-8"))){result = reader.ReadToEnd();}responseStream.Close();return result;}}private const string url = "https://www.tianqiapi.com/api/?version=v1&city=";private string latestCityName = "";private bool isNeedInitData = true;// This member is used by the Validate() method to indicate// whether the Generate() method should return true or false// during its next execution.private bool changed;// This Method is called if the component is loaded/created.public Script(){ // Note: Accessing input or output properties from this method// will have no effect as they have not been allocated yet.}// This Method is called if the component is unloaded/disposedpublic virtual void Dispose(){}// This Method is called if an input property has changed its valuepublic override void Validate(){// Remember: set changed to true if any of the output // properties has been changed, see Generate()if ((string.IsNullOrEmpty(this.CityName)==false && latestCityName.Equals(this.CityName) == false)){latestCityName = this.CityName;OnReGetData(-1);}    else if (isNeedInitData == true){OnReGetData(-1);}}// This Method is called every time before a frame is rendered.// Return value: if true, Ventuz will notify all nodes bound to this//               script node that one of the script's outputs has a//               new value and they therefore need to validate. For//               performance reasons, only return true if output//               values really have been changed.public override bool Generate(){if (changed){changed = false;return true;}return false;}//重新从服务器获取数据// This Method is called if the function/method ReGetData is invoked by the user or a bound event.// Return true, if this component has to be revalidated!public bool OnReGetData(int arg){if (string.IsNullOrEmpty(this.CityName)==true){return false;}isNeedInitData = false;HTTPS.AsyncRequest("", url+this.CityName, (reusult) => {this.httpResult = reusult;this.changed = true;});return false;}}
2:新建JsonParser Node 解析 获取到的天气数据


3:效果图

4:里面有其他数据字段可根据自己需求享用
5: 有问题可以找我:zyf151@qq.com
6:示例vza(v6.3):
 链~接:https://pan.baidu.com/s/1pMwneUpw5f_mopCn_mWdDg提~取~码:gl5g

Ventuz 获取实时天气信息相关推荐

  1. 【IoT最佳实践】设备获取实时天气信息

    [摘要] 物联网智能设备可以通过物联网平台统一获取实时天气信息,本文提供一个实现该功能的DEMO和其使用方法. 场景说明 随着技术的发展,物联网设备也越来越智能化,例如可以显示当地的实时天气. 在物联 ...

  2. 【IoT最佳实践】设备获取实时天气DEMO代码解读

    [摘要] 之前,我们曾为您介绍如何实现设备实时获取天气信息,本文将为您从代码逻辑层面解读该实时天气应用的DEMO. 本文承接[IoT最佳实践]设备获取实时天气信息,为您解读实时天气DEMO的代码逻辑, ...

  3. 微信小程序获取实时天气

    一.实验目标 1.掌握服务器域名配置和临时服务器部署:2.掌握 wx.request 接口的用法. 二.实验步骤 1.使用和风天气申请key 2.导航栏设计 3.页面设计 4.逻辑实现 更新地区信息 ...

  4. 腾讯云API与国家气象局API获取实时天气

    腾讯云API获取天气(收费) package com.vxdata.cases.common.utils;import com.alibaba.fastjson.JSONObject; import ...

  5. 通过Temboo实现从Arduino获取雅虎天气信息

    如果问我未来的科技行业发展有哪些亮点的话,我必须说物联网一定是其中之一.物联网技术发展迅速,现在我们已经看到非常多的设备通过互联网互相通信了.物联网技术的发展背后的推动因素之一是Arduino和Ras ...

  6. Android 获取实时天气数据

    先上效果图: 深圳实时天气数据 关于获取实时天气数据有很多种方法,像聚合数据.和风天气等平台都可以提供数据来源,本文主要使用和风天气SDK获取实时天气数据.以下是使用和风天气SDK来获取地方实时天气数 ...

  7. python 学习笔记 12 -- 写一个脚本获取城市天气信息

    近期在玩树莓派,前面写过一篇在树莓派上使用1602液晶显示屏,那么可以显示后最重要的就是显示什么的问题了. 最easy想到的就是显示时间啊,CPU利用率啊.IP地址之类的.那么我认为呢,假设可以显示当 ...

  8. 通过百度地图获取当地天气信息

    首先,通过之前用过的百度地图,实现定位功能:首先去百度开放云申请密钥,这里就不说明申请过程了,不懂得可以百度一下. 申请完密钥后,需要去声明Activity的地方添加上下面的语句: [html] vi ...

  9. Linux网络编程之获取网络天气信息

    需求分析:1.需要Linux c 网络编程基础,2.需要了解 http 协议3.需要天气信息相关api(可以从阿里云上购买,很便宜的!)4.需要cJSON解析库(因为获取到的天气信息一般是用cJSON ...

最新文章

  1. DB天气app冲刺二阶段第十一天(完结)
  2. Java 8 开发的 4 大顶级技巧,你都知道吗 ?
  3. 2014-12-27 迎接15年前夕,原来时间是这样过的
  4. 无法加载 DLL“SQLite.Interop.DLL”: 找不到指定的模块。 (异常来自 HRESULT:0x8007007E)。...
  5. 定时器实现方式之TimerTask、Timer
  6. 混合云下割裂的Web安全管理挑战如何破?
  7. input file 选择文件后自动上传文件
  8. 名片识别信息分类python_python文字识别
  9. js进阶正则表达式10-分组-多行匹配-正则对象的属性(小括号作用:分组,将小括号里面的东西看成一个整体,因为量词只对前一个字符有效)(多行匹配:m)(属性使用:reg.global)...
  10. Android权限管理原理
  11. 基于html5的旅游网站的设计与实现,基于HTML5的旅游网站的设计与实现(静态网页)(含录像)...
  12. 分享一个轻量级免费UML绘图工具JUDE
  13. 计算机组装训练知识总结,组装知识总结
  14. 电脑壁纸软件(Bing Wallpaper)
  15. 基于Django框架的视频播放器设计
  16. 一个请求式分页存储管理系统中计算机应用,操作系统概论自考2012年7月真题
  17. [异常类] 空指针 Calendar.setTime(a) 源码剖析
  18. Android11 Launcher添加网格布局设置(3x3,4x4,5x5)
  19. PC实现Win10/原生安卓双系统
  20. 能够语义化的编写html文档,HTML语义化 - 写给未来的自己 - OSCHINA - 中文开源技术交流社区...

热门文章

  1. 微信小程序支付详解:
  2. Scala 的 Tuple 元组
  3. 固本强基 筑梦人生——读《人生基本功:建筑师潘冀的砌砖哲学》有感
  4. 使用Scrapy爬取我主良缘所有图片
  5. 从头开始学语法 1:名词的分类
  6. 使用定义判断函数的奇偶性
  7. 品优购项目实战第一天打卡
  8. 【信息学】【2018.02】噪声环境下基于时频域信号模型的语音去混响
  9. Exhaustive search 和 Beam search 详解(图文并茂)
  10. win10环境下的spark2.4源码环境搭建