home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 1
MediaPortal 1 Talk
UK weather images - I use the BBC's
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="cheezey" data-source="post: 72133" data-attributes="member: 10350"><p><strong>BBC weather images</strong></p><p></p><p>As a subject (not a guest) of Her Majesty I am:</p><p></p><ol> <li data-xf-list-type="ol"> Obsessed with the weather forecast</li> <li data-xf-list-type="ol"> Genetically programmed to understand the BBC weather maps</li> </ol><p></p><p>That said, when I came to program up the MP Weather plugin with the images from the BBC website I found that they don't have static names, they change with the time of day, this isn't very MP friendly. I mailed the BBC about this (and a couple of other things <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite11" alt=":rolleyes:" title="Roll Eyes :rolleyes:" loading="lazy" data-shortname=":rolleyes:" /> ) and got a reply saying . . . . mmmmm . . . . . we're looking at a few things.</p><p></p><p>So while they look at a few things, I scripted up the retrieval of the BBC weather images for my own personal use. </p><p></p><p>This script can take two parameters, that of the region you want the maps for, if you don't use a parameter you'll get the UK country maps (you can find the available regions in the comments of the code below), the second parameter is the path to where you want to save your images . You just need to then configure the MP weather plugin to load the images from your selected path.</p><p></p><p>I have this script running as a scheduled task every 30mins to keep the images updated.</p><p></p><p>If you want to use it:</p><ol> <li data-xf-list-type="ol">Save this code as C:\GetBBCWeatherImages.vbs</li> <li data-xf-list-type="ol">Schedule wscript.exe C:\GetBBCWeatherImages.vbs <REGION> <PATH> - optional</li> </ol> <p style="margin-left: 20px">e.g. For the North East of England images and to save to C:\Temp you schedule </p> <p style="margin-left: 20px">wscript.exe C:\GetBBCWeatherImages.vbs NE C:\Temp</p> <p style="margin-left: 20px"></p> <p style="margin-left: 20px">e.g. For Northern Europe and to save to the root of C:\ you schedule </p> <p style="margin-left: 20px">wscript.exe C:\GetBBCWeatherImages.vbs NEUR</p><p></p><p></p><p><em>I have pasted this code into a PHP box as the CODE box didn't like my CrLf and formatted it as one big block of text and the QUOTE box removed my Tabs.</em></p><p>[php]</p><p>'==========================================================================</p><p>'</p><p>' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.0</p><p>'</p><p>' NAME: GetBBCWeatherImages.vbs</p><p>'</p><p>' AUTHOR: Cheezey</p><p>' DATE : 20/08/2006</p><p>'</p><p>' COMMENT: Grabs BBC weather images, gets the nearest image to the current</p><p>' time, saves the images in the root of C:\ if not otherwise</p><p>' specified</p><p>'</p><p>' USAGE: cscript //nologo GetBBCWeatherImages.vbs <REGION> <PATH></p><p>'</p><p>' <REGION> is optional but can accept the following</p><p>' uk = United Kingdom (Default)</p><p>' ci = Channel Islands</p><p>' e = England East</p><p>' m = England Midlands</p><p>' ne = England North East</p><p>' nw = England North West</p><p>' ni = Northern Ireland</p><p>' ss = Scotland South</p><p>' sn = Scotland North</p><p>' s = England South</p><p>' se = England South East</p><p>' sw = England South West</p><p>' wl = Wales</p><p>' neur = Europe - North</p><p>' eeur = Europe - Mediterranean and East</p><p>' weur = Europe - West and Canary Islands</p><p>' mide = Middle East</p><p>' ausa = Australasia</p><p>' cam = America - Central</p><p>' nam = America - North</p><p>' sam = America - South</p><p>' easia = Asia - East</p><p>' sasia = Asia - South</p><p>' seasia = Asia - South East</p><p>'</p><p>' <PATH> is optional, it's where you want to save the files To</p><p>' including, it defaults to C:\</p><p>'</p><p>' DATE ACTION</p><p>' 20/08/06 Created</p><p>' 28/08/06 Updated to work with world regions</p><p>' 28/08/06 Fixed bug where images before 10am (double figures) weren't</p><p>' saved - DOH!!</p><p>' 28/08/06 Added the debug & error handling</p><p>'</p><p>'==========================================================================</p><p>Option Explicit</p><p>On Error Resume Next</p><p></p><p>'==========================================================================</p><p>' Initialise debug</p><p>'==========================================================================</p><p>Dim Debug : Debug = False</p><p></p><p>'==========================================================================</p><p>' Initialise objects</p><p>'==========================================================================</p><p>Dim oXML</p><p>Set oXML = CreateObject("Microsoft.XMLHTTP")</p><p>Dim oArgs</p><p>Set oArgs = WScript.Arguments</p><p>Dim oFS</p><p>Set oFS = CreateObject("Scripting.FileSystemObject")</p><p></p><p>'==========================================================================</p><p>' Initialise variables</p><p>'==========================================================================</p><p>Dim sRegion : sRegion = "uk"</p><p>Dim sURLp : sURLp = "http://www.bbc.co.uk/weather/charts/"</p><p>Dim sArea : sArea = "uk"</p><p>Dim sPath : sPath = "c:\"</p><p></p><p>'==========================================================================</p><p>' Set the region & area using the parameter passed in, default to uk / uk</p><p>'==========================================================================</p><p>If oArgs.Count = 1 Or oArgs.Count = 2 Then</p><p> sRegion = LCase(oArgs(0))</p><p> Select Case sRegion</p><p> Case "uk", "ci", "e", "m", "ne", "nw", "ni", "ss", "ns", "s", "se", "sw", "wl"</p><p> sArea = "uk"</p><p> Case "neur", "eeur", "weur", "mide", "ausa", "cam", "sam", "easia", "sasia", "seasia"</p><p> sArea = "world"</p><p> Case Else</p><p> sArea = "uk"</p><p> sRegion = "uk"</p><p> End Select</p><p>End If</p><p>sURLp = sURLp & sArea & "/"</p><p></p><p>'==========================================================================</p><p>' See if the path has been passed in, otherwise default to c:\</p><p>'==========================================================================</p><p>If oArgs.Count = 2 Then</p><p> sPath = LCase(oArgs(1))</p><p> If Not Right(sPath,1) = "\" Then sPath = sPath & "\"</p><p> If Not oFS.FolderExists(sPath) Then sPath = "c:\"</p><p>End If</p><p></p><p>'==========================================================================</p><p>' Initialise yet more variables</p><p>'==========================================================================</p><p>Dim sURL</p><p>Dim sRain : sRain = sRegion & "_rain_"</p><p>Dim sCloud : sCloud = sRegion & "_cloud_"</p><p>Dim sTemp : sTemp = sRegion & "_temperature_"</p><p>Dim sWind : sWind = sRegion & "_wind_"</p><p>Dim sPressure : sPressure = sRegion & "_pressure_"</p><p>Dim sSummary : sSummary = sRegion & "_summary_"</p><p>Dim sVisSat : sVisSat = "uk_visiblesatellite_"</p><p></p><p>'==========================================================================</p><p>' The BBC uses yymmddhh as their format for the weather image filenames</p><p>' so get these in the correct format i.e. 2 char strings</p><p>'==========================================================================</p><p>Dim yy, mm, dd, td, yd, hh, mn</p><p> yy = Padnum(2,CInt(Right(CStr(Year(Now())),2)))</p><p> mm = Padnum(2,CInt(Month(Now())))</p><p> dd = Padnum(2,CInt(Day(Now())))</p><p> td = Padnum(2,CInt(Day(Now())+1))</p><p> yd = Padnum(2,CInt(Day(Now())-1))</p><p> hh = Padnum(2,CInt(Hour(Now())))</p><p> mn = Padnum(2,CInt(Minute(Now())))</p><p> </p><p>'==========================================================================</p><p>' Try and get all the images</p><p>'==========================================================================</p><p>GetImage sRain & ".jpg", sRain</p><p>CheckForError("Error getting rain image.")</p><p>GetImage sCloud & ".jpg", sCloud</p><p>CheckForError("Error getting cloud image.")</p><p>GetImage sTemp & ".jpg", sTemp</p><p>CheckForError("Error getting temperature image.")</p><p>GetImage sWind & ".jpg", sWind</p><p>CheckForError("Error getting wind image.")</p><p>GetImage sPressure & ".jpg", sPressure</p><p>CheckForError("Error getting pressure image.")</p><p>GetImage sSummary & ".jpg", sSummary</p><p>CheckForError("Error getting summary image.")</p><p></p><p>'==========================================================================</p><p>' Only get the visible satellite image if the region is in the uk, 'Cos</p><p>' that's all they do</p><p>'==========================================================================</p><p>If sArea = "uk" Then </p><p> GetImage sVisSat & ".jpg", sVisSat</p><p> CheckForError("Error getting satellite image.")</p><p>End If</p><p></p><p>'==========================================================================</p><p>' Tidy up</p><p>'==========================================================================</p><p>Set oXML = Nothing</p><p>Set oArgs = Nothing</p><p>Set oFS = Nothing</p><p></p><p>'==========================================================================</p><p>' Subs & Functions</p><p>'==========================================================================</p><p></p><p></p><p>Sub GetImage(strFilename, strType)</p><p></p><p> Dim i, j, k, l</p><p> '==========================================================================</p><p> ' If minutes are greater than 30 (i.e. nearer the next hour) then add one</p><p> ' to start at the next hour</p><p> '==========================================================================</p><p> If CInt(mn) < 31 Then</p><p> i = CInt(hh)</p><p> Else</p><p> i = CInt(hh) + 1</p><p> End If</p><p></p><p> '==========================================================================</p><p> ' Nothing was found in the previous loop so check the whole day (24 - 0)</p><p> ' If no image is found, the next loops will check tomorrow or yesterday</p><p> '==========================================================================</p><p> k = 25</p><p> l = 99</p><p> For j = 0 To 24</p><p> sURL = sURLp & strType & Cstr(yy) & Cstr(mm) & CStr(dd) & Padnum(2, j) & ".jpg"</p><p> oXML.open "GET", sURL, False</p><p> oXML.send</p><p> If oXML.status = "200" Then</p><p> '==========================================================================</p><p> ' Do a bit of jiggery pokery to get the image with the time nearest to the</p><p> ' current time</p><p> '==========================================================================</p><p> If Abs(i - j) < k Then </p><p> k = Abs(i - j)</p><p> l = j</p><p> End If</p><p> End If</p><p> Next</p><p> sURL = sURLp & strType & Cstr(yy) & Cstr(mm) & Cstr(dd) & Padnum(2, l) & ".jpg"</p><p> oXML.open "GET", sURL, False</p><p> oXML.send</p><p> If oXML.status = "200" Then</p><p> '==========================================================================</p><p> ' We've found a good image so save it</p><p> '==========================================================================</p><p> SaveBinaryData sPath & strFilename, oXML.responseBody</p><p> Exit Sub</p><p> End If</p><p></p><p>End Sub</p><p></p><p>Function SaveBinaryData(FileName, ByteArray)</p><p></p><p> Const adTypeBinary = 1</p><p> Const adSaveCreateOverWrite = 2</p><p> '==========================================================================</p><p> ' Create Stream object</p><p> '==========================================================================</p><p> Dim BinaryStream</p><p> Set BinaryStream = CreateObject("ADODB.Stream")</p><p> '==========================================================================</p><p> 'Specify stream type - we want to save binary data.</p><p> '==========================================================================</p><p> BinaryStream.Type = adTypeBinary</p><p> </p><p> '==========================================================================</p><p> ' Open the stream and write binary data to the object</p><p> '==========================================================================</p><p> BinaryStream.Open</p><p> BinaryStream.Write ByteArray</p><p></p><p> '==========================================================================</p><p> ' Save binary data to disk</p><p> '==========================================================================</p><p> BinaryStream.SaveToFile FileName, adSaveCreateOverWrite</p><p> </p><p>End Function</p><p></p><p>Function Padnum(intLength, intNumber)</p><p></p><p> Dim iLen : iLen = Len(CStr(intNumber))</p><p></p><p> If iLen < intLength Then </p><p> Padnum = String(intLength - iLen, "0") & CStr(intNumber)</p><p> Else</p><p> Padnum = CStr(intNumber) </p><p> End If</p><p> </p><p>End Function </p><p> </p><p>Sub CheckForError(strMsg)</p><p></p><p> If Err.Number <> 0 Then</p><p> If Debug = True Then</p><p> Dim fDebug</p><p> Set fDebug = oFS.CreateTextFile("c:\GetBBCWeatherImages.vbs.ERRORS.txt", True)</p><p> fDebug.WriteLine(String(78,"*"))</p><p> fDebug.WriteLine(Now() & " : " & strMsg)</p><p> fDebug.WriteLine(String(78,"*"))</p><p> fDebug.WriteLine("Error number : " & CStr(Err.Number))</p><p> fDebug.WriteLine("Error source : " & Err.Source)</p><p> fDebug.WriteLine("Error text : " & Err.Description)</p><p> fDebug.Close</p><p> End If</p><p> WScript.Quit(1)</p><p> End If</p><p>End Sub</p><p>[/php]</p></blockquote><p></p>
[QUOTE="cheezey, post: 72133, member: 10350"] [b]BBC weather images[/b] As a subject (not a guest) of Her Majesty I am: [list=1] [*] Obsessed with the weather forecast [*] Genetically programmed to understand the BBC weather maps [/list] That said, when I came to program up the MP Weather plugin with the images from the BBC website I found that they don't have static names, they change with the time of day, this isn't very MP friendly. I mailed the BBC about this (and a couple of other things :rolleyes: ) and got a reply saying . . . . mmmmm . . . . . we're looking at a few things. So while they look at a few things, I scripted up the retrieval of the BBC weather images for my own personal use. This script can take two parameters, that of the region you want the maps for, if you don't use a parameter you'll get the UK country maps (you can find the available regions in the comments of the code below), the second parameter is the path to where you want to save your images . You just need to then configure the MP weather plugin to load the images from your selected path. I have this script running as a scheduled task every 30mins to keep the images updated. If you want to use it: [list=1] [*]Save this code as C:\GetBBCWeatherImages.vbs [*]Schedule wscript.exe C:\GetBBCWeatherImages.vbs <REGION> <PATH> - optional [/list] [indent]e.g. For the North East of England images and to save to C:\Temp you schedule wscript.exe C:\GetBBCWeatherImages.vbs NE C:\Temp e.g. For Northern Europe and to save to the root of C:\ you schedule wscript.exe C:\GetBBCWeatherImages.vbs NEUR[/indent] [I]I have pasted this code into a PHP box as the CODE box didn't like my CrLf and formatted it as one big block of text and the QUOTE box removed my Tabs.[/I] [php] '========================================================================== ' ' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.0 ' ' NAME: GetBBCWeatherImages.vbs ' ' AUTHOR: Cheezey ' DATE : 20/08/2006 ' ' COMMENT: Grabs BBC weather images, gets the nearest image to the current ' time, saves the images in the root of C:\ if not otherwise ' specified ' ' USAGE: cscript //nologo GetBBCWeatherImages.vbs <REGION> <PATH> ' ' <REGION> is optional but can accept the following ' uk = United Kingdom (Default) ' ci = Channel Islands ' e = England East ' m = England Midlands ' ne = England North East ' nw = England North West ' ni = Northern Ireland ' ss = Scotland South ' sn = Scotland North ' s = England South ' se = England South East ' sw = England South West ' wl = Wales ' neur = Europe - North ' eeur = Europe - Mediterranean and East ' weur = Europe - West and Canary Islands ' mide = Middle East ' ausa = Australasia ' cam = America - Central ' nam = America - North ' sam = America - South ' easia = Asia - East ' sasia = Asia - South ' seasia = Asia - South East ' ' <PATH> is optional, it's where you want to save the files To ' including, it defaults to C:\ ' ' DATE ACTION ' 20/08/06 Created ' 28/08/06 Updated to work with world regions ' 28/08/06 Fixed bug where images before 10am (double figures) weren't ' saved - DOH!! ' 28/08/06 Added the debug & error handling ' '========================================================================== Option Explicit On Error Resume Next '========================================================================== ' Initialise debug '========================================================================== Dim Debug : Debug = False '========================================================================== ' Initialise objects '========================================================================== Dim oXML Set oXML = CreateObject("Microsoft.XMLHTTP") Dim oArgs Set oArgs = WScript.Arguments Dim oFS Set oFS = CreateObject("Scripting.FileSystemObject") '========================================================================== ' Initialise variables '========================================================================== Dim sRegion : sRegion = "uk" Dim sURLp : sURLp = "http://www.bbc.co.uk/weather/charts/" Dim sArea : sArea = "uk" Dim sPath : sPath = "c:\" '========================================================================== ' Set the region & area using the parameter passed in, default to uk / uk '========================================================================== If oArgs.Count = 1 Or oArgs.Count = 2 Then sRegion = LCase(oArgs(0)) Select Case sRegion Case "uk", "ci", "e", "m", "ne", "nw", "ni", "ss", "ns", "s", "se", "sw", "wl" sArea = "uk" Case "neur", "eeur", "weur", "mide", "ausa", "cam", "sam", "easia", "sasia", "seasia" sArea = "world" Case Else sArea = "uk" sRegion = "uk" End Select End If sURLp = sURLp & sArea & "/" '========================================================================== ' See if the path has been passed in, otherwise default to c:\ '========================================================================== If oArgs.Count = 2 Then sPath = LCase(oArgs(1)) If Not Right(sPath,1) = "\" Then sPath = sPath & "\" If Not oFS.FolderExists(sPath) Then sPath = "c:\" End If '========================================================================== ' Initialise yet more variables '========================================================================== Dim sURL Dim sRain : sRain = sRegion & "_rain_" Dim sCloud : sCloud = sRegion & "_cloud_" Dim sTemp : sTemp = sRegion & "_temperature_" Dim sWind : sWind = sRegion & "_wind_" Dim sPressure : sPressure = sRegion & "_pressure_" Dim sSummary : sSummary = sRegion & "_summary_" Dim sVisSat : sVisSat = "uk_visiblesatellite_" '========================================================================== ' The BBC uses yymmddhh as their format for the weather image filenames ' so get these in the correct format i.e. 2 char strings '========================================================================== Dim yy, mm, dd, td, yd, hh, mn yy = Padnum(2,CInt(Right(CStr(Year(Now())),2))) mm = Padnum(2,CInt(Month(Now()))) dd = Padnum(2,CInt(Day(Now()))) td = Padnum(2,CInt(Day(Now())+1)) yd = Padnum(2,CInt(Day(Now())-1)) hh = Padnum(2,CInt(Hour(Now()))) mn = Padnum(2,CInt(Minute(Now()))) '========================================================================== ' Try and get all the images '========================================================================== GetImage sRain & ".jpg", sRain CheckForError("Error getting rain image.") GetImage sCloud & ".jpg", sCloud CheckForError("Error getting cloud image.") GetImage sTemp & ".jpg", sTemp CheckForError("Error getting temperature image.") GetImage sWind & ".jpg", sWind CheckForError("Error getting wind image.") GetImage sPressure & ".jpg", sPressure CheckForError("Error getting pressure image.") GetImage sSummary & ".jpg", sSummary CheckForError("Error getting summary image.") '========================================================================== ' Only get the visible satellite image if the region is in the uk, 'Cos ' that's all they do '========================================================================== If sArea = "uk" Then GetImage sVisSat & ".jpg", sVisSat CheckForError("Error getting satellite image.") End If '========================================================================== ' Tidy up '========================================================================== Set oXML = Nothing Set oArgs = Nothing Set oFS = Nothing '========================================================================== ' Subs & Functions '========================================================================== Sub GetImage(strFilename, strType) Dim i, j, k, l '========================================================================== ' If minutes are greater than 30 (i.e. nearer the next hour) then add one ' to start at the next hour '========================================================================== If CInt(mn) < 31 Then i = CInt(hh) Else i = CInt(hh) + 1 End If '========================================================================== ' Nothing was found in the previous loop so check the whole day (24 - 0) ' If no image is found, the next loops will check tomorrow or yesterday '========================================================================== k = 25 l = 99 For j = 0 To 24 sURL = sURLp & strType & Cstr(yy) & Cstr(mm) & CStr(dd) & Padnum(2, j) & ".jpg" oXML.open "GET", sURL, False oXML.send If oXML.status = "200" Then '========================================================================== ' Do a bit of jiggery pokery to get the image with the time nearest to the ' current time '========================================================================== If Abs(i - j) < k Then k = Abs(i - j) l = j End If End If Next sURL = sURLp & strType & Cstr(yy) & Cstr(mm) & Cstr(dd) & Padnum(2, l) & ".jpg" oXML.open "GET", sURL, False oXML.send If oXML.status = "200" Then '========================================================================== ' We've found a good image so save it '========================================================================== SaveBinaryData sPath & strFilename, oXML.responseBody Exit Sub End If End Sub Function SaveBinaryData(FileName, ByteArray) Const adTypeBinary = 1 Const adSaveCreateOverWrite = 2 '========================================================================== ' Create Stream object '========================================================================== Dim BinaryStream Set BinaryStream = CreateObject("ADODB.Stream") '========================================================================== 'Specify stream type - we want to save binary data. '========================================================================== BinaryStream.Type = adTypeBinary '========================================================================== ' Open the stream and write binary data to the object '========================================================================== BinaryStream.Open BinaryStream.Write ByteArray '========================================================================== ' Save binary data to disk '========================================================================== BinaryStream.SaveToFile FileName, adSaveCreateOverWrite End Function Function Padnum(intLength, intNumber) Dim iLen : iLen = Len(CStr(intNumber)) If iLen < intLength Then Padnum = String(intLength - iLen, "0") & CStr(intNumber) Else Padnum = CStr(intNumber) End If End Function Sub CheckForError(strMsg) If Err.Number <> 0 Then If Debug = True Then Dim fDebug Set fDebug = oFS.CreateTextFile("c:\GetBBCWeatherImages.vbs.ERRORS.txt", True) fDebug.WriteLine(String(78,"*")) fDebug.WriteLine(Now() & " : " & strMsg) fDebug.WriteLine(String(78,"*")) fDebug.WriteLine("Error number : " & CStr(Err.Number)) fDebug.WriteLine("Error source : " & Err.Source) fDebug.WriteLine("Error text : " & Err.Description) fDebug.Close End If WScript.Quit(1) End If End Sub [/php] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 1
MediaPortal 1 Talk
UK weather images - I use the BBC's
Contact us
RSS
Top
Bottom