It is currently June 26th, 2019, 4:53 pm

Random weather pictures

Help with creating, editing & fixing problems with skins
mrkrupik
Posts: 2
Joined: April 21st, 2019, 8:35 am

Random weather pictures

mrkrupik » April 21st, 2019, 8:49 am

I am modifying a Weather Program that returns a Icon of 0-47 or blank currently you can have 1 image set for each number so 1.png, 2.png . I want random pictures to show up. Currenlty the folder structure is

Code: Select all

Backgrounds
 -1.png
 -2.png
 -3.png
 - etc...

i want to change it to 

Backgrounds
  1 <- this is a folder
     Background-A
     Background-B
  2 <- this is a folder
     Background-A
     Background-B
     Background-C
     Background-D
  3 <- this is a folder
     Background-A
So what you would have is a folder for each number that is returned, for example 0 means tornado so you would put a bunch of tornado pictures in that folder. When the weather status turns to 0 then the program will query the folder for a list of pictures and randomly select a picture form it.

The question is how to do it.

my code below is what I would like to change:

Code: Select all

; ----------------------------------
; MEASURES.
; ----------------------------------

[MeasureCurrent]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=#CurrentTodayUpdate#
Url=http://xml.weather.com/weather/local/#Location#?cc=*&unit=#Unit#&dayf=1
RegExp="(?siU).*<locale>(.*)</locale>.*<ut>(.*)</ut>.*<ud>(.*)</ud>.*<us>(.*)</us>.*<up>(.*)</up>.*<ur>(.*)</ur>.*<loc id="(.*)">.*<dnam>(.*)</dnam>.*<tm>(.*)</tm>.*<lat>(.*)</lat>.*<lon>(.*)</lon>.*<sunr>(.*)</sunr>.*<suns>(.*)</suns>.*<zone>(.*)</zone>.*<cc>.*<lsup>(.*)</lsup>.*<obst>(.*)</obst>.*<tmp>(.*)</tmp>.*<flik>(.*)</flik>.*<t>(.*)</t>.*<icon>(.*)</icon>.*<bar>.*<r>(.*)</r>.*<d>(.*)</d>.*<wind>.*<s>(.*)</s>.*<gust>(.*)</gust>.*<d>(.*)</d>.*<t>(.*)</t>.*<hmid>(.*)</hmid>.*<vis>(.*)</vis>.*<uv>.*<i>(.*)</i>.*<t>(.*)</t>.*<dewp>(.*)</dewp>.*<moon>.*<icon>(.*)</icon>.*<t>(.*)</t>.*<ppcp>(.*)</ppcp>.*"
StringIndex=21
IfEqualValue=0
IfEqualAction=[!ShowMeterGroup Loading]
IfAboveValue=1
IfAboveAction=[!HideMeterGroup Loading]

[Today]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=#CurrentTodayUpdate#
Url=http://xml.weather.com/weather/local/#Location#?cc=*&unit=#Unit#&dayf=1
RegExp="(?siU)<dayf>.*<lsup>(.*)</lsup>.*<day d="0" t="(.*)" dt="(.*)".*<hi>(.*)</hi>.*<low>(.*)</low>.*<sunr>(.*)</sunr>.*<suns>(.*)</suns>.*<part p="d">.*<icon>(.*)</icon>.*<t>(.*)</t>.*<wind>.*<s>(.*)</s>.*<gust>(.*)</gust>.*<d>(.*)</d>.*<t>(.*)</t>.*<bt>(.*)</bt>.*<ppcp>(.*)</ppcp>.*<hmid>(.*)</hmid>.*<part p="n">.*<icon>(.*)</icon>.*<t>(.*)</t>.*<wind>.*<s>(.*)</s>.*<gust>(.*)</gust>.*<d>(.*)</d>.*<t>(.*)</t>.*<bt>(.*)</bt>.*<ppcp>(.*)</ppcp>.*<hmid>(.*)</hmid>.*"
Disabled=#Today#

[MeasureForcastToday+1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=2700
Url=http://xml.weather.com/weather/local/#Location#?cc=*&unit=#Unit#&dayf=2
RegExp="(?siU)<day d="1" t="(.*)" dt="(.*)".*<hi>(.*)</hi>.*<low>(.*)</low>.*<sunr>(.*)</sunr>.*<suns>(.*)</suns>.*<part p="d">.*<icon>(.*)</icon>.*<t>(.*)</t>.*<wind>.*<s>(.*)</s>.*<gust>(.*)</gust>.*<d>(.*)</d>.*<t>(.*)</t>.*<bt>(.*)</bt>.*<ppcp>(.*)</ppcp>.*<hmid>(.*)</hmid>.*<part p="n">.*<icon>(.*)</icon>.*<t>(.*)</t>.*<wind>.*<s>(.*)</s>.*<gust>(.*)</gust>.*<d>(.*)</d>.*<t>(.*)</t>.*<bt>(.*)</bt>.*<ppcp>(.*)</ppcp>.*<hmid>(.*)</hmid>.*"

[MeasureForcastToday+2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=2700
Url=http://xml.weather.com/weather/local/#Location#?cc=*&unit=#Unit#&dayf=3
RegExp="(?siU)<day d="2" t="(.*)" dt="(.*)".*<hi>(.*)</hi>.*<low>(.*)</low>.*<sunr>(.*)</sunr>.*<suns>(.*)</suns>.*<part p="d">.*<icon>(.*)</icon>.*<t>(.*)</t>.*<wind>.*<s>(.*)</s>.*<gust>(.*)</gust>.*<d>(.*)</d>.*<t>(.*)</t>.*<bt>(.*)</bt>.*<ppcp>(.*)</ppcp>.*<hmid>(.*)</hmid>.*<part p="n">.*<icon>(.*)</icon>.*<t>(.*)</t>.*<wind>.*<s>(.*)</s>.*<gust>(.*)</gust>.*<d>(.*)</d>.*<t>(.*)</t>.*<bt>(.*)</bt>.*<ppcp>(.*)</ppcp>.*<hmid>(.*)</hmid>.*"

[MeasureForcastToday+3]
Measure=Plugin
Plugin=Plugins\WebParser.dll
UpdateRate=2700
Url=http://xml.weather.com/weather/local/#Location#?cc=*&unit=#Unit#&dayf=4
RegExp="(?siU)<day d="3" t="(.*)" dt="(.*)".*<hi>(.*)</hi>.*<low>(.*)</low>.*<sunr>(.*)</sunr>.*<suns>(.*)</suns>.*<part p="d">.*<icon>(.*)</icon>.*<t>(.*)</t>.*<wind>.*<s>(.*)</s>.*<gust>(.*)</gust>.*<d>(.*)</d>.*<t>(.*)</t>.*<bt>(.*)</bt>.*<ppcp>(.*)</ppcp>.*<hmid>(.*)</hmid>.*<part p="n">.*<icon>(.*)</icon>.*<t>(.*)</t>.*<wind>.*<s>(.*)</s>.*<gust>(.*)</gust>.*<d>(.*)</d>.*<t>(.*)</t>.*<bt>(.*)</bt>.*<ppcp>(.*)</ppcp>.*<hmid>(.*)</hmid>.*"

[MeasureIconCurrent]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureCurrent]
StringIndex=20

[MeasureTempCurrent]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureCurrent]
StringIndex=17

[MeasureTempUnitCurrent]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureCurrent]
StringIndex=2

[MeasureLocationCurrent]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureCurrent]
StringIndex=8

[MeasureConditionsCurrent]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureCurrent]
StringIndex=19

[MeasureUnitsCurrent]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureCurrent]
StringIndex=3

[MeasureLowToday]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[Today]
StringIndex=5
Disabled=0
Substitute="":"?"

[MeasurePrecipCurrent]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureCurrent]
StringIndex=34
Disabled=0

[MeasureWindCurrent]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureCurrent]
StringIndex=23
Disabled=0
Substitute="calm":"0"

[MeasureIcon+1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureForcastToday+1]
StringIndex=7

[MeasureDay+1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureForcastToday+1]
StringIndex=1
Substitute="Monday":"MON","Tuesday":"TUE","Wednesday":"WED","Thursday":"THU","Friday":"FRI","Saturday":"SAT","Sunday":"SUN"

[MeasureDayConditionsDesc+1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureForcastToday+1]
StringIndex=8

[MeasureTemp+1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureForcastToday+1]
StringIndex=3

[MeasureLow+1]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureForcastToday+1]
StringIndex=4

[MeasureIcon+2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureForcastToday+2]
StringIndex=7

[MeasureDay+2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureForcastToday+2]
StringIndex=1
Substitute="Monday":"MON","Tuesday":"TUE","Wednesday":"WED","Thursday":"THU","Friday":"FRI","Saturday":"SAT","Sunday":"SUN"

[MeasureTemp+2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureForcastToday+2]
StringIndex=3

[MeasureLow+2]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureForcastToday+2]
StringIndex=4

[MeasureIcon+3]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureForcastToday+3]
StringIndex=7

[MeasureDay+3]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureForcastToday+3]
StringIndex=1
Substitute="Monday":"MON","Tuesday":"TUE","Wednesday":"WED","Thursday":"THU","Friday":"FRI","Saturday":"SAT","Sunday":"SUN"

[MeasureTemp+3]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureForcastToday+3]
StringIndex=3

[MeasureLow+3]
Measure=Plugin
Plugin=Plugins\WebParser.dll
Url=[MeasureForcastToday+3]
StringIndex=4

; ----------------------------------
; METERS.
; ----------------------------------

[CurrentBack]
Path=#@#Weather\Backgrounds
MeasureName=MeasureIconCurrent
Meter=Image
PreserveAspectRatio=1
AntiAlias=1
X=0
Y=0

[3dayBack]
Meter=Image
ImageName=#@#Weather\Background.png
X=0
Y=151

[SettingsButton]
Meter=Button
ButtonImage=#@#Weather\settingsbttn.png
SolidColor=0,0,0,1
H=13
W=15
X=191
Y=10
LeftMouseUpAction=!execute [ notepad "#CurrentPath#Variables.inc"][!Redraw]

[City]
Meter=String
MeterStyle=LocationStyle
StringAlign=Left
FontFace=Roboto Light
AntiAlias=1
StringCase=Upper
FontColor=ffffff
MeasureName=MeasureLocationCurrent
H=18
W=180
X=14
Y=20
SolidColor=0,0,0,1
AntiAlias=1
ClipString=1

[MeterTempCurrent]
MeasureName=MeasureTempCurrent
Meter=String
MeterStyle=TempStyle
StringAlign=Left
FontSize=45
FontFace=Roboto Light
FontColor=ffffff
AntiAlias=1
X=0
Y=30
AntiAlias=1
Text="%1°"

[MeterCurrentIcon]
Path=#@#Weather\Icons
MeasureName=MeasureIconCurrent
Meter=Image
PreserveAspectRatio=1
AntiAlias=1
X=142
Y=48
H=48
W=48
SolidColor=0,0,0,1

[WindSpeedIcon]
Meter=Image
ImageName=#@#Weather\wind.png
X=16
Y=104

[MeterWindSpeed]
Meter=String
MeasureName=MeasureWindCurrent
MeterStyle=LocationStyle
StringAlign=Left
FontFace=Roboto Light
FontColor=ffffff
AntiAlias=1
FontSize=8
X=48
Y=104
Text=%1 MPH

[RainIcon]
Meter=Image
ImageName=#@#Weather\rain.png
X=110
Y=106

[MeterPercip]
Meter=String
MeasureName=MeasurePrecipCurrent
MeterStyle=LocationStyle
StringAlign=Left
FontFace=Roboto Light
FontColor=ffffff
AntiAlias=1
FontSize=8
X=134
Y=104
Text=%1%

[MeterIcon+1]
Path=#@#Weather\Icons-2
MeasureName=MeasureIcon+1
Meter=Image
X=13
Y=194
H=48
W=48
PreserveAspectRatio=1
AntiAlias=1

[MeterDay+1]
Meter=String
MeterStyle=ForecastStyle
MeasureName=MeasureDay+1
FontColor=434343
FontFace=Roboto Light
FontSize=10
AntiAlias=1
FontSize=8
StringAlign=Center
X=24r
Y=170
Text="%1"

[MeterTemp+1]
Meter=String
MeterStyle=ForecastStyle
MeasureName=MeasureTemp+1
MeasureName2=MeasureLow+1
FontColor=434343
FontFace=Roboto Light
FontSize=10
AntiAlias=1
StringAlign=Center
X=38
Y=248
Text="%1°-%2°"

[MeterIcon+2]
Path=#@#Weather\Icons-2
MeasureName=MeasureIcon+2
Meter=Image
X=86
Y=194
H=48
W=48
PreserveAspectRatio=1
AntiAlias=1

[MeterDay+2]
Meter=String
MeterStyle=ForecastStyle
MeasureName=MeasureDay+2
FontColor=434343
FontFace=Roboto Light
FontSize=10
AntiAlias=1
StringAlign=Center
X=24r
Y=170
Text="%1"

[MeterTemp+2]
Meter=String
MeterStyle=ForecastStyle
MeasureName=MeasureTemp+2
MeasureName2=MeasureLow+2
FontColor=434343
FontFace=Roboto Light
FontSize=10
AntiAlias=1
StringAlign=Center
X=r
Y=248
Text="%1°-%2°"

[MeterIcon+3]
Path=#@#Weather\Icons-2
MeasureName=MeasureIcon+3
Meter=Image
X=159
Y=194
H=48
W=48
PreserveAspectRatio=1
AntiAlias=1

[MeterDay+3]
Meter=String
MeterStyle=ForecastStyle
MeasureName=MeasureDay+3
FontColor=434343
FontFace=Roboto Light
FontSize=10
AntiAlias=1
StringAlign=Center
X=24r
Y=170
Text="%1"

[MeterTemp+3]
Meter=String
MeterStyle=ForecastStyle
MeasureName=MeasureTemp+3
MeasureName2=MeasureLow+3
FontColor=434343
FontFace=Roboto Light
StringAlign=Center
FontSize=10
AntiAlias=1
X=r
Y=248
Text="%1°-%2°"
User avatar
balala
Rainmeter Sage
Posts: 8319
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Random weather pictures

balala » April 21st, 2019, 10:13 am

mrkrupik wrote:
April 21st, 2019, 8:49 am
So what you would have is a folder for each number that is returned, for example 0 means tornado so you would put a bunch of tornado pictures in that folder. When the weather status turns to 0 then the program will query the folder for a list of pictures and randomly select a picture form it.

The question is how to do it.
First let's create the desired feature for the [CurrentBack] meter. Later in same way you can create for the others, too.
First of all you need a Calc measure, which returns a random value. Ideal would be to have the same number of images into each of those folders. Would be much more easier. Do you have them so?
If you do, add the following measure to your code:

Code: Select all

[MeasureRandomCurrent]
Measure=Calc
Formula=Random
LowBound=1
HighBound=5
UpdateRandom=1
UpdateDivider=-1
Note the UpdateDivider=-1 option, which makes not to get the measure updated in each update cycle of the skin. We'll have to update this measure only when the icon changes. Also in the HighBound option you have to use the number of images existing into each of those folders. I put here 5, but obviously you can modify depending on how many images do you have.
Now modify the [CurrentBack] meter, to get it to choose randomly an image from the appropriate folder, according to the value returned by the above measure:

Code: Select all

[CurrentBack]
Path=#@#Weather\Backgrounds\[MeasureIconCurrent]
MeasureName=MeasureRandomCurrent
Meter=Image
PreserveAspectRatio=1
AntiAlias=1
X=0
Y=0
DynamicVariables=1
See that I added a [MeasureIconCurrent] folder name into the Path option and modified the MeasureName option to MeasureName=MeasureRandomCurrent. This way the image will be selected from the [MeasureIconCurrent] folder (this is a number, which corresponds to the icon number returned by weather.com). The icon is chosen randomly, according to the (random) value returned by the [MeasureRandomCurrent] measure (through the MeasureName=MeasureRandomCurrent option). Note an extremely important option also added to the above [CurrentBack] meter: DynamicVariables=1. It is needed, because section variable is used into this meter.
Now you have to do one more thing: to modify the above random value whenever the number of the icon changes, because an icon once shown, must be kept while the condition doesn't change. For this you have to add an OnchangeAction option to the [MeasureIconCurrent] measure. Add the following one: OnChangeAction=[!UpdateMeasure "MeasureRandomCurrent"].
That's it. But as I said this will make what you want ONLY with the current icon. You have to add similar measures and options to the other needed meters / measure as well, to get the skin working as you want.
Please try to make these changes and if you don't succeed, let me know.
mrkrupik
Posts: 2
Joined: April 21st, 2019, 8:35 am

Re: Random weather pictures

mrkrupik » April 21st, 2019, 1:39 pm

balala wrote:
April 21st, 2019, 10:13 am
Please try to make these changes and if you don't succeed, let me know.
Oh thank you so much!
User avatar
eclectic-tech
Rainmeter Sage
Posts: 3375
Joined: April 12th, 2012, 9:40 pm
Location: Cedar Point, Ohio, USA

Re: Random weather pictures

eclectic-tech » April 21st, 2019, 2:02 pm

mrkrupik wrote:
April 21st, 2019, 1:39 pm
Oh thank you so much!
You can look at a skin I created last year to see how I did a similar thing... WeatherWall

Feel free to use any portions of the code to help you with your creation :welcome: