Author Topic: What's the weather for tomorrow in Orlando? or vice versa!  (Read 5730 times)

0 Members and 1 Guest are viewing this topic.

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
What's the weather for tomorrow in Orlando? or vice versa!
« on: July 12, 2015, 08:13:22 PM »
What's the weather for tomorrow in Orlando?
What's the weather in Las Vegas on Thursday?
What's the weather?
What's the weather for tomorrow?
What's the weather in Orlando?
What's the weather for today in Santos?

The phrases and payloads were originally written in portuguese. But I have quickly translated them to post here. And in this newer and significantly better version I'm not going to translate the displaying text since you can easily find the strings to be translated in the python script and then use Google translator to translate them.
The advantage of this xml against the other posted xmls (that I could find at least), is that this one can have both the location and the day as optional payload xml's.
So I can say any of the above phrases with a single command and it will work perfectly.

You must add your locations to the file weather_locations.xml so you can use it. This file contains a the actual weather station respective to the place you are asking the weather for. Please pay attention to weather stations that you will have to use a format like pws:ISANTOS10 or others that don't have the pws: like this KORL. Look in the respective payload xml (weather_locations.xml) for examples.
Visit this URL for getting your respective weather station:
http://www.wunderground.com

In the latest version I've transferred all the logic to python because it is easier to me and probably more flexible that being limited only to VC native macros.

The latest version will not change your default location (as set in the script, variable defaultlocation on line 24) if you don't request it. Once you change a location, all the further requests for the forecast will be made for this same location, unless you change the location again by saying another specific location in your phrase. The other condition for the code to execute a change action is if there is no data available from the plugin, hence a new download of information would be required anyway.

When you don't say a location at all, the script will get the location name from the plugin variables using the variable C.observation_location. So you never miss what location is actually being displayed.
The script will always tell the actual weather station where the weather data came from so you can always make sure the weather being displayed is the one that you really wanted to know.

The day is also now show in both weekday and day of the month so you never misunderstand what day is actually being displayed.

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.5.2-->
<commandGroup open="True" name="Previsão do tempo-EN" enabled="True" prefix="" priority="0" requiredProcess="" description="">
  <command id="753" name="Qual a previsão do tempo para &lt;dia&gt; em &lt;local&gt; (python)" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>TTS.Speak</cmdType>
      <params>
        <param>I'm getting the weather for ya.|Ok, let me get it|I'll get it quickly for you.</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>PY.ExecString</cmdType>
      <params>
        <param>weather_forecast("{1}","{PF.1}","{2}","{PF.2}")</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>what's the weather,how is the weather</phrase>
    <phrase optional="true">in,on,for,at</phrase>
    <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="True">payloads\weather_locations.xml</payloadFromXML>
    <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="True">payloads\weather_day.xml</payloadFromXML>
    <phrase optional="true">in,on,for,at</phrase>
    <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="True">payloads\weather_day.xml</payloadFromXML>
    <payloadFromXML phraseOnly="False" use2partPhrase="False" phraseConnector="by" Phrase2wildcard="anyone" optional="True">payloads\weather_locations.xml</payloadFromXML>
  </command>
  <command id="352" name="Query current Wunder Settings" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>WUnder.GetCustom</cmdType>
      <params>
        <param>{C.observation_location.full}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.ShowText</cmdType>
      <params>
        <param>{LastResult}</param>
        <param>10000</param>
        <param>1</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>RegExTool.Open</cmdType>
      <params>
        <param>True</param>
      </params>
      <cmdRepeat>0</cmdRepeat>
    </action>
    <action>
      <cmdType>Results.RegEx</cmdType>
      <params>
        <param>"full":\s"(.*?)",</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.AddText</cmdType>
      <params>
        <param>{Match.1}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>WUnder.GetCustom</cmdType>
      <params>
        <param>{C.station_id}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <action>
      <cmdType>OSD.AddText</cmdType>
      <params>
        <param>{LastResult}</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <phrase>Query current weather settings</phrase>
  </command>
  <command id="301" name="load python script" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
    <action>
      <cmdType>PY.ExecFile</cmdType>
      <params>
        <param>PY\weather_forecast_Marcus.py</param>
      </params>
      <cmdRepeat>1</cmdRepeat>
    </action>
    <event>VC.Loaded</event>
  </command>
</commandGroup>

This is the final version of the script. Please report any bugs so I can fix them.
« Last Edit: July 19, 2015, 08:20:33 PM by marcusvdt »

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Re: What's the weather for tomorrow in Orlando? or vice versa!
« Reply #1 on: July 12, 2015, 08:22:04 PM »
Does anybody know how I can get the name of the location that is currently setup on WUnder plugin?
Mine is set to autoip right now and I would like to enhance the above command by letting it read what's the current location (as per doing a query of the current value that has been set by autoip setting).

Thanks!

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: What's the weather for tomorrow in Orlando? or vice versa!
« Reply #2 on: July 12, 2015, 09:25:18 PM »
Since your command is setting the location, you can store it in a variable and then read that.  There is no way to read the value of this variable as far as I know.  There are thousands of variables throughout the program and plugins.  Most of them cannot be read.

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Re: What's the weather for tomorrow in Orlando? or vice versa!
« Reply #3 on: July 12, 2015, 11:02:03 PM »
since this is based on this http://voxcommando.com/forum/index.php?topic=1755.0

wouldn't it be logical to post it in the same thread?, otherwise the XML exchange will become very messy with time ... just wondering?
When Voice command gets tough, use hand gestures

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Re: What's the weather for tomorrow in Orlando? or vice versa!
« Reply #4 on: July 12, 2015, 11:40:47 PM »
no problem at all. If James wants to merge with the other thread, I've no issues.

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Re: What's the weather for tomorrow in Orlando? or vice versa!
« Reply #5 on: July 13, 2015, 10:58:33 AM »
Hey guys!
I've found a way of querying the data from the current location that is set in Wunder plugin. There is an undocumented variable called {C.display_location}. At least I did not find documentation for it, except the documentation from the API for Weather Underground itself.
The documentation of the API tells that display_location.full would return what I want without the need for a regex, but then this variable does not work on VC. I'm not concerned about this anyway, because {C.display_location} already contains the information that I want.

With this testing command, you can get whatever are the settings now from your Wunder plugin.
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.1.5.2-->
<command id="320" name="Query current Wunder Settings" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>WUnder.GetCustom</cmdType>
    <params>
      <param>{C.display_location}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegExReplace</cmdType>
    <params>
      <param>(^.*\"full\":\s\")(.*?)(\"\,*\n.*$)</param>
      <param>$2</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{LastResult}</param>
      <param>3000</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>WUnder.GetCustom</cmdType>
    <params>
      <param>{C.station_id}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.AddText</cmdType>
    <params>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Query current weather settings</phrase>
</command>


This is what the variable itself returns in my case. This is what is currently set from autoip setting on the plugin. I know this is from autoip because it's a different weather station from those that I have in my payload xml:
Code: [Select]
  "full": "Santos, Brasil",

  "city": "Santos",

  "state": "",

  "state_name": "Brasil",

  "country": "BZ",

  "country_iso3166": "BR",

  "zip": "00000",

  "magic": "1",

  "wmo": "83782",

  "latitude": "-23.93000031",

  "longitude": "-46.31999969",

  "elevation": "14.00000000"

As you can see from the testing command, my regex as set in the command is doing nothing because I'm probably doing something wrong. I've been able to build that particular regular expression on this web site (I'm really bad with regex), but I don't seem to get it to work on VC. The purpose is to remove everything from the string, except whatever comes after
Code: [Select]
"full": "and before
Code: [Select]
",
So, in this specific case, it should return:
Code: [Select]
Santos, Brasil
Could someone please help me to get the correct regex compatible with VC for my purpose?

Thanks so much!

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: What's the weather for tomorrow in Orlando? or vice versa!
« Reply #6 on: July 13, 2015, 11:16:51 AM »
Anyone use this command, please be careful not to overdo it when testing.  Every time you switch locations VC must download full information from the weather underground and this affect our quota.  Since we are using a free package our quota is somewhat limited.

Our maximum total number of request per day for ALL VoxCommando users is 150 per day, with a maximum of only 10 calls per minute.

So please be careful not to go crazy switching locations, or it will break the plugin for us all.

Under normal operation, when you don't change locations, VoxCommando caches results and only updates the data at most once every 15 minutes.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: What's the weather for tomorrow in Orlando? or vice versa!
« Reply #7 on: July 13, 2015, 11:37:44 AM »
Instead of using a RegEx tester from some other site, you should be using the RegEx Tool provided by VoxCommando.  ::club

Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<!--VoxCommando 2.2.0.1-->
<command id="338" name="Query current Wunder Settings" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>WUnder.GetCustom</cmdType>
    <params>
      <param>{C.display_location}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>RegExTool.Open</cmdType>
    <params>
      <param>True</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegEx</cmdType>
    <params>
      <param>"full":\s"(.*?)",</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.ShowText</cmdType>
    <params>
      <param>{Match.1}</param>
      <param>3000</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>WUnder.GetCustom</cmdType>
    <params>
      <param>{C.station_id}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>OSD.AddText</cmdType>
    <params>
      <param>{LastResult}</param>
    </params>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <phrase>Query current weather settings</phrase>
</command>

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Re: What's the weather for tomorrow in Orlando? or vice versa!
« Reply #8 on: July 13, 2015, 11:48:10 AM »
Anyone use this command, please be careful not to overdo it when testing.  Every time you switch locations VC must download full information from the weather underground and this affect our quota.  Since we are using a free package our quota is somewhat limited.

Our maximum total number of request per day for ALL VoxCommando users is 150 per day, with a maximum of only 10 calls per minute.

So please be careful not to go crazy switching locations, or it will break the plugin for us all.

Under normal operation, when you don't change locations, VoxCommando caches results and only updates the data at most once every 15 minutes.
James, oops!  :o I'm sorry.
I did not know of the limit.

Please let me know if there is a way to query the time for another location without changing the location (meaning that I wouldn't need to use WUnder.Change)?
The reason for having more than one location is that I sometimes I work in another cities and on the morning I want to know how is the weather forecast for a particular city so I can prepare the clothes and/or the umbrella.
This is something that could happen once a day in my case, so I don't want to be responsible for using a significant amount of the queries that should be available to your entire customer base  :bonk


Maybe I should remove this command?


Instead of using a RegEx tester from some other site, you should be using the RegEx Tool provided by VoxCommando.  ::club
Haha! I always have to forget something important! Actually I opened this regex tool once, but I forgot it exists!
Thanks!

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: What's the weather for tomorrow in Orlando? or vice versa!
« Reply #9 on: July 13, 2015, 01:30:52 PM »
A couple of times a day is not a problem.  The only issue that comes up is usually when we are testing commands and we execute them over and over when trying to get them set up correctly.  I am just asking people to be careful when doing this.

I don't really know what you mean by
Quote
query the time for another location

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Re: What's the weather for tomorrow in Orlando? or vice versa!
« Reply #10 on: July 13, 2015, 02:25:10 PM »
I don't really know what you mean by
I mean I have necessarily to fix a location under wunder plugin settings. So I've chosen the weather station that is nearest to where I live. But then, as I have explained, I have the need to request the weather forecast for other cities that I may need to travel to in the next days.
As far as I know, the only way to be able to request the forecast to a different location as I explained above is to use the action WUnder.Change to actually change the location permanently until you restart VC. This action WUnder.Change will be consuming the quota for total number of requests allowed for all VC users and I would prefer I could have an alternative way of getting the forecast for another city, without consuming that quota.
Is there such alternative way for getting the forecast for another place (different from what is set under wunder plugin) without using the WUnder.Change action?

Btw, to make sure that a location change made with WUnder.Change is permanent only until VC is restarted, I've tested:
1-Changed the location by issuing the respective phrasing to trigger my command for getting the forecast for another city. It worked preety fine.
2-Then I issued the phrase "Query current weather settings" so that triggers the command that you fixed for me, the one that queries the current settings for wunder plugin. The location returned is just the same that I changed in step 1. Repeated this some times, and the result is still the same changed location.
3-After that, I've performed a full restart of VC and then used the command "Query current weather settings" again. The returned location got back to the one that was set under wunder plugin settings.

The above test shows that an additional change may occur whatever VC is restarted, and consequently consuming one more request from the total quota reserved for all VC users.

Hey, I don't want to be picky, just trying to get the forecast command useful for me, and simultaneously not pushing this quota to the limits.

And yes, I've done those tests many times yesterday!  :-\ Sorry for that!

Thanks for all the help!

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: What's the weather for tomorrow in Orlando? or vice versa!
« Reply #11 on: July 13, 2015, 02:56:31 PM »
Your assumptions are correct. 

Data will need to be refreshed under all of the following circumstances.

- you make a request for information after VC has been started or restarted (even if you don't change the location)
- you make a request for information and it has been at least 15 minutes since your last request.
- you change the location

That is how it is.  There is no way around it.  If you need to make 10-15 requests per day it is fine.  Just be careful not to make 50 or more requests when you are doing testing on a new command.  If someone else is doing the same thing it could be a problem.

Weather Underground tolerates the occasional over-quota within reason.
« Last Edit: July 13, 2015, 03:09:53 PM by jitterjames »

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Re: What's the weather for tomorrow in Orlando? or vice versa!
« Reply #12 on: July 13, 2015, 03:10:43 PM »
Ok, thanks.

I've updated the first post with the latest enhanced version. This latest version will not perform the action WUnder.Change if the previous location setting is equal to the one you are requesting the weather for. I hope this helps to minimize the impact on consuming the quota from Weather Underground (not sure if the action WUnder.Change already does this check internally).

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: What's the weather for tomorrow in Orlando? or vice versa!
« Reply #13 on: July 13, 2015, 03:11:30 PM »
If it ever becomes a big problem I can add an option to use your own API KEY from WUnderground.  So instead of sharing the VC quota, you can use your own.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7713
  • Karma: 116
    • View Profile
    • VoxCommando
Re: What's the weather for tomorrow in Orlando? or vice versa!
« Reply #14 on: July 13, 2015, 03:12:18 PM »
(not sure if the action WUnder.Change already does this check internally).

Neither am I.  :biglaugh

I am too lazy to check right now. :)