'This script downloads the tv listings for a whole week from tv.yahoo.com 'it creates a folder and saves it to a file on your pc. 'This script must be run before the TvListing script will work. 'You need to find your local listings in your web browser. 'Then copy and paste the url from your browser to the line indicated. 'To use it Create a new Event in HomeSeer and set it to run this script once a week. 'It may take 10 minutes or so to download a weeks worth of listings. 'I set my event to download late sunday nights. 'This script provides the information used by the Tvlistings script. 'created 5-6-2000 by Tom Caldwell (ttom@intelos.net) ' Const OpenFileForReading = 1 Const OpenFileForWriting = 2 Const OpenFileForAppending = 8 'Copy and paste the url to your local listings here 'Make sure the preceding and following quotation marks are still there. Const TvUrl = "http://tv.yahoo.com/yahoo/listings/tv1.dpg?chanArea=ditv1&daypart=Now&genres=All+Categories&channel=All+Channels&x=37&y=14" Public FilePath Public area sub main() Dim FSO 'Return the path to the HomeSeer executable file FilePath = hs.GetAppPath & "\Script Downloads" ' Set up global data.This line sets up a variable to access the file system Set FSO = CreateObject("Scripting.FileSystemObject") 'This If Then statement checks to see if the filepath already exists. If FSO.FolderExists(FilePath) Then DeleteDirectory(FSO) UpDateFile(FSO) Else BuildDirectory(FSO) End if end sub Function GetArea Dim string Dim count Dim char Dim charposition 'This block of statements extracts the info needed from the Url. count = 0 charposition = instr( TvUrl, "chanArea=") charposition = charposition + 8 Do count = count + 1 char = mid( TvUrl, charposition + count, 1) If char = "&" Then Exit Do String = String & char GetArea = string hs.waitevents Loop End Function 'This sub if called will delete the folder listed. Sub DeleteDirectory(FSO) ' to delete a folder: FSO.DeleteFolder(FilePath & "\Tv Listing") End Sub 'If this script has never been run before 'This function is called to create the folder directory Function BuildDirectory(FSO) Dim Folder Dim SubFolders Dim SubFolder Dim TextStream 'this line creates the folder listed in filepath Set Folder = FSO.CreateFolder(FilePath) Set TextStream = FSO.CreateTextFile(FilePath & "\ReadMe.txt") TextStream.WriteLine("This folder and file created by TvDownload script") TextStream.Close 'This line creates the tvlisting folder Set Folder = FSO.CreateFolder(FilePath & "\Tv Listing") Set SubFolders = Folder.SubFolders Set SubFolder = SubFolders.Add("Monday") CreateTvTxt SubFolder Set SubFolder = SubFolders.Add("Tuesday") CreateTvTxt SubFolder Set SubFolder = SubFolders.Add("Wednesday") CreateTvTxt SubFolder Set SubFolder = SubFolders.Add("Thursday") CreateTvTxt SubFolder Set SubFolder = SubFolders.Add("Friday") CreateTvTxt SubFolder Set SubFolder = SubFolders.Add("Saturday") CreateTvTxt SubFolder Set SubFolder = SubFolders.Add("Sunday") CreateTvTxt SubFolder BuildDirectory = True End Function 'If this script has been run before and this function is called 'It recreates the tvlisting folder with the new info. Function UpDateFile(FSO) Dim Folder Dim SubFolders Dim SubFolder 'This line creates the tv Listing folder Set Folder = FSO.CreateFolder(FilePath & "\Tv Listing") Set SubFolders = Folder.SubFolders Set SubFolder = SubFolders.Add("Monday") CreateTvTxt SubFolder Set SubFolder = SubFolders.Add("Tuesday") CreateTvTxt SubFolder Set SubFolder = SubFolders.Add("Wednesday") CreateTvTxt SubFolder Set SubFolder = SubFolders.Add("Thursday") CreateTvTxt SubFolder Set SubFolder = SubFolders.Add("Friday") CreateTvTxt SubFolder Set SubFolder = SubFolders.Add("Saturday") CreateTvTxt SubFolder Set SubFolder = SubFolders.Add("Sunday") CreateTvTxt SubFolder End Function 'This function creates the text files for the tv listings. 'Each days worth of listings is broken down into several files 'for faster loading and searching Sub CreateTvTxt(Folder) Dim TextStream Dim Info Dim WeekDay Dim Hour WeekDay = Folder.Name For Hour = 3 to 24 Set TextStream = Folder.CreateTextFile(Hour & ".txt") Info = TV(WeekDay,Hour) TextStream.Write(Info) ' Note that this does not add a line feed to the file. TextStream.Close Hour = Hour + 2 Next End Sub 'There are 2 variables passed to the function The day and time. 'Then GetUrl is used to get the info from the web. Function TV(dayname,TimeDay) dim host dim page dim strip_tags dim port dim Webpage dim counter dayname = Left(dayname, 2) dayname = LCase(dayname) host = "tv.yahoo.com" area = GetArea page = "/yahoo/listings/tv1.dpg?chanArea=" & area & "&day=" & dayname & "&daypart=" & TimeDay & "&genres=All+Categories&channel=All+Channels" strip_tags = false port = 80 'The following actually gets the page DO WHILE counter < 3 Webpage = hs.GetURL(host, page, strip_tags, port) TV = Webpage IF Webpage <> "" THEN Exit do counter = counter + 1 hs.waitevents LOOP End Function