Author Topic: Day-by-day weather forecasts -- without Python (new as of VC 2.2.1.6)  (Read 2385 times)

0 Members and 1 Guest are viewing this topic.

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
There is a new Tools action as of the recently released beta, VC 2.2.1.6: Tools.WeekdayToOffset.

i.e., if today is Tuesday, Weather Underground and Google Calendar consider today to be 0, tomorrow to be 1, Thursday to be 2, etc., which means that if we want to add something to our calendar on Saturday or tomorrow, we have to somehow translate these words into number values.

In another thread, I shared a Python script to help getting the weather forecast for specific days with the WUnder plugin: http://voxcommando.com/forum/index.php?topic=1755.0

Below is the exact same weather command I shared previously, but this time I'm using the new Tool.WeekdayToOffset action. No Python script is required.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.1.6-->
<command id="303" name="What's the forecast for {1}" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)==(B)</ifType>
    <ifParams>{1}&amp;&amp;today</ifParams>
    <then>
      <action>
        <cmdType>Results.SetVar</cmdType>
        <params>
          <param>day</param>
          <param>D0</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else />
  </if>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>(A)==(B)</ifType>
    <ifParams>{1}&amp;&amp;tomorrow</ifParams>
    <then>
      <action>
        <cmdType>Results.SetVar</cmdType>
        <params>
          <param>day</param>
          <param>D1</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else />
  </if>
  <if ifBlockDisabled="False" ifNot="True">
    <ifType>(A)Contains(B)</ifType>
    <ifParams>tomorrow today&amp;&amp;{1}</ifParams>
    <then>
      <action>
        <cmdType>Tools.WeekdayToOffset</cmdType>
        <params>
          <param>{1}</param>
          <param>True</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Results.SetVar</cmdType>
        <params>
          <param>day</param>
          <param>D{LastResult}</param>
        </params>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else />
  </if>
  <action>
    <cmdType>WUnder.GetCustom</cmdType>
    <params>
      <param>Weather for {1}: {{var.day}.conditions}, with high of {{var.day}.high} degrees Celsius and a low of {{var.day}.low} degrees. There's a {{var.day}.pop}% chance of precipitation, with winds averaging {{var.day}.avewind} km/h.</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{LastResult}</param>
      <param>10000</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>What's the forecast for</phrase>
  <payloadList>today, tomorrow, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday</payloadList>
</command>

I have chosen to use several logic blocks here so that I could use a payload list in my command, rather than needing to attach a payload XML file. The same command could be created using payload XML and fewer logic evaluations in the macro.

For this command, I have set the WeekdayToOffset action to always assume I mean future days, so if I ask for Sunday's forecast on a Monday, it will give me next Sunday's weather, not yesterday's weather.

See the action description in your installation or on the wiki for details.
« Last Edit: February 23, 2016, 09:49:28 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)