Bodman Posted July 14, 2010 Share Posted July 14, 2010 (edited) Hi All, I am trying to auto create the HTML for my personal website and I need to auto generate the HTML code. The only parts I need to change is the word "date", the words picture1.jpg and th_picture1.jpg need to count up to a predefined number. The HTML Code looks like below <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td width="100" height="75"> <a href="http://www.mywebsite.com/date/picture1.jpg" rel="lightbox[photo]"><img src="http://www.mywebsite.com/date/th_picture1.jpg" width="100" height="76" /></a> </td> <td> </td> <td width="100" height="75"> <a href="http://www.mywebsite.com/date/picture2.jpg" rel="lightbox[photo]"><img src="http://www.mywebsite.com/date/th_picture2.jpg" width="100" height="76" /></a> </a></td> <td> </td> <td width="100" height="75"> <a href="http://www.mywebsite.com/date/picture3.jpg" rel="lightbox[photo]"><img src="http://www.mywebsite.com/date/th_picture3.jpg" width="100" height="76" /></a> </td> <td> </td> <td width="100" height="75"> <a href="http://www.mywebsite.com/date/picture4.jpg" rel="lightbox[photo]"><img src="http://www.mywebsite.com/date/th_picture4.jpg" width="100" height="76" /></a> </td> <td> </td> <td width="100" height="75"> <a href="http://www.mywebsite.com/date/picture5.jpg" rel="lightbox[photo]"><img src="http://www.mywebsite.com/date/th_picture5.jpg" width="100" height="76" /></a> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> <td> </td> </tr> <tr> <td width="100" height="75"> <a href="http://www.mywebsite.com/date/picture6.jpg" rel="lightbox[photo]"><img src="http://www.mywebsite.com/date/th_picture6.jpg" width="100" height="76" /></a> </td> <td> </td> <td width="100" height="75"> <a href="http://www.mywebsite.com/date/picture7.jpg" rel="lightbox[photo]"><img src="http://www.mywebsite.com/date/th_picture7.jpg" width="100" height="76" /></a> </a></td> <td> </td> <td width="100" height="75"> <a href="http://www.mywebsite.com/date/picture8.jpg" rel="lightbox[photo]"><img src="http://www.mywebsite.com/date/th_picture8.jpg" width="100" height="76" /></a> </td> <td> </td> <td width="100" height="75"> <a href="http://www.mywebsite.com/date/picture9.jpg" rel="lightbox[photo]"><img src="http://www.mywebsite.com/date/th_picture9.jpg" width="100" height="76" /></a> </td> <td> </td> <td width="100" height="75"> <a href="http://www.mywebsite.com/date/picture10.jpg" rel="lightbox[photo]"><img src="http://www.mywebsite.com/date/th_picture10.jpg" width="100" height="76" /></a> </td> <td> </td> </tr> I have got quite close with the code below but this was reading the HTML from a txt file called "pics1.txt" expandcollapse popup$count = 0 ;Read Pics.txt $pics = FileOpen("pics1.txt", 0) ; Check if file opened for reading OK If $pics = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $pics1 = FileRead($pics) If @error = -1 Then ExitLoop counter () ;MsgBox(0, "Char read:", $pics1); outputs header.txt data Wend FileClose($pics) ;Finished Reading pics.txt ;Counter Function func counter() While $count < 5 $count = $count + 1 ;MsgBox(0, "Char read:", $count ) $pics2 = StringReplace($pics1, "picture" & $count, "image" & $count) MsgBox(0, "Char read:", $pics2); outputs header.txt data Sleep(100) Wend EndFunc So my end result I want is, if $count = 25 I would get <a href="http://www.mywebsite.com/date/image1.jpg" rel="lightbox[photo]"><img src="http://www.mywebsite.com/date/th_image1.jpg" width="100" height="76" /></a> up to image25.jpg (seperated every 5 by <td> </td>) I would really appreciate any help / pointers Bod Edited July 14, 2010 by Bodman Link to comment Share on other sites More sharing options...
enaiman Posted July 14, 2010 Share Posted July 14, 2010 (edited) Here you go: $htmlSTRING = "" $MyDate = "12/12/1212" $stringSEP = _AddSeparator() $htmlSTRING &= $stringSEP For $i=1 To 25 $htmlSTRING &= "<tr>"&@CRLF $htmlSTRING &= '<td width="100" height="75">'&@CRLF $htmlSTRING &= '<a href="http://www.mywebsite.com/'&$MyDate&'/picture'&$i&'.jpg" rel="lightbox[photo]"><img src="http://www.mywebsite.com/'&$MyDate&'/th_picture'&$i&'.jpg" width="100" height="76" /></a>'&@CRLF $htmlSTRING &= '</td>'&@CRLF $htmlSTRING &= '<td> </td>'&@CRLF $htmlSTRING &= "</tr>"&@CRLF If Mod($i, 5) = 0 Then $htmlSTRING &= $stringSEP Next FileClose(FileOpen(@ScriptDir&"\myHTML.html", 2)) FileWrite(@ScriptDir&"\myHTML.html", $htmlSTRING) MsgBox(0, "", "Done") Func _AddSeparator() Local $strSEP = "<tr>"&@CRLF For $i=1 To 10 $strSEP &= "<td> </td>"&@CRLF Next $strSEP &= "</tr>"&@CRLF Return $strSEP EndFunc Nothing difficult, late beginner level - you could have made this script by yourself. Don't be lazy next time Edited July 14, 2010 by enaiman SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
Mat Posted July 14, 2010 Share Posted July 14, 2010 Don't be lazy next time Don't be so helpful next time. AutoIt Project Listing Link to comment Share on other sites More sharing options...
enaiman Posted July 14, 2010 Share Posted July 14, 2010 Sometimes I feel generous SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
Bodman Posted July 15, 2010 Author Share Posted July 15, 2010 Thank you so much, I had tried and tried to get this to work, but I was obviously barking up the wrong tree, I had even split the HTML file into several txt files then read them in 1 at a time..... . Thank you again Bod Link to comment Share on other sites More sharing options...
Bodman Posted July 15, 2010 Author Share Posted July 15, 2010 I also need to add approx 250lines of HTML before this and 48lines after, What is the best way, should I assign a variable to each line (like the $htmlSTRING )and write it to the myHTML.html or would it be better to hold this in 2 external txt files and read them in, then write to myHTMLhtml thanks Bod Link to comment Share on other sites More sharing options...
enaiman Posted July 15, 2010 Share Posted July 15, 2010 Keep them in separate files.When you need them, just read the file and add the content to $htmlSTRINGIt is easier to do it this way; you will end finally with a very long string to write to a file in one go.However, pay attention to AutoIt limits when dealing with strings. just read this from the documentation:Maximum string length: 2,147,483,647 charactersI guess you won't come near that SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
Bodman Posted July 21, 2010 Author Share Posted July 21, 2010 Brilliant thank you. It works like a dream now Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now