tes5884 Posted December 5, 2012 Posted December 5, 2012 (edited) Hi Guys, I'm trying to write a script to check a rss feed if there is an update to Adobe or Firezilla. Trouble is, I cant wrap my brain around StringRegExp, how do I get only the version number so I can compare to my current version and see if it is up to date? Thanks! #include <IE.au3> #include <Array.au3> #include <CSV.au3> $lst = "sources.csv" $csv = _ParseCSV($lst, "", "", 1) For $i = 0 To UBound($csv, 1) - 1 InetGet($csv[$i][0], "temp.xml") $1 = FileRead("temp.xml") $2 = StringRegExp($1, '', 3) If FileExists($csv[$i][1] & ".txt") Then If $2[2] > FileReadLine($csv[$i][1] & ".txt", -1) Then $rslt = MsgBox(4, "", "Updates available! Do you want to be reminded again?") If $rslt = 7 Then FileWriteLine($csv[$i][1] & ".txt", $2[2]) EndIf EndIf Else FileWrite($csv[$i][1] & ".txt", $2[2]) EndIf FileDelete("temp.xml") Next Exit Edited December 5, 2012 by tes5884 www.tspitz.com
jchd Posted December 5, 2012 Posted December 5, 2012 What exact input syntax do you have and what do you want to extract? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
tes5884 Posted December 5, 2012 Author Posted December 5, 2012 What exact input syntax do you have and what do you want to extract?example RSS source would be: http://www.filehippo.com/download_adobe_reader/rss I want to retrieve the new version number, compare to the list of current versions, if it doesnt exist here notify me about new version, otherwise exit. www.tspitz.com
PhoenixXL Posted December 5, 2012 Posted December 5, 2012 (edited) try with _StringBetween or Edited December 5, 2012 by PhoenixXL My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.
tes5884 Posted December 5, 2012 Author Posted December 5, 2012 try with _StringBetween or Thanks man! but I'm trying to learn how to use StringRegExp properly... Also, I'm trying to just get back the digits, no alpha.Thanks www.tspitz.com
jdelaney Posted December 5, 2012 Posted December 5, 2012 use XML DOM, or HTML DOM objects:http://www.w3schools.com/dom/default.aspsome UDF's are out there too IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
jchd Posted December 5, 2012 Posted December 5, 2012 I'd use: $sVersion = StringRegExp($sXMLcontent, "(?i)<item>.*?<title>.*?(d+(?:.d+)*).*?</title>), 1) then use StringSplit then Number to compare each component of both versions. A raw string compare won't work: '10.2.1' < '9.0.1' This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
tes5884 Posted December 5, 2012 Author Posted December 5, 2012 I'd use:$sVersion = StringRegExp($sXMLcontent, "(?i)<item>.*?<title>.*?(d+(?:.d+)*).*?</title>), 1)then use StringSplit then Number to compare each component of both versions. A raw string compare won't work: '10.2.1' < '9.0.1'Scite doesnt like your StringRexExp... www.tspitz.com
jchd Posted December 5, 2012 Posted December 5, 2012 $sVersion = StringRegExp($sXMLcontent, "(?i)<item>.*?<title>.*?(d+(?:.d+)*).*?</title>", 1) Sorry for typo. I can't test right now but I hope it's fine. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
jdelaney Posted December 5, 2012 Posted December 5, 2012 (edited) I'm inferring the XPATH...feel free to update it as needed $oXML=ObjCreate("Microsoft.XMLDOM") $oXML.loadxml($string) ; load document...the string you read from the file...or use.xml(file) $oItem = $oXML.selectSingleNode( '//item' ) $oTitle = $oXML.selectSingleNode( '//title' ) ConsoleWrite ($oItem.text & " " & $oTitle.text & @crlf ) update: weakness of regexp...what if there are 2 item's, and only the second includes a title? your regexp would match the first item, but the second title. dom objects are always consistent (when well formatted xpath included) Edited December 5, 2012 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
jchd Posted December 5, 2012 Posted December 5, 2012 That's why I asked for the exact input syntax! Anyway you're right in that XMLDOM is more reliable in the general case, but the poster insisted on a regexp. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
jdelaney Posted December 5, 2012 Posted December 5, 2012 I always see similar posts, and always try to open posters to DOM objects. Maybe they are unfamiliar, or don't know about them. It answers the question, just with a better answer (opinion) then actually asked for. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
tes5884 Posted December 5, 2012 Author Posted December 5, 2012 (edited) I always see similar posts, and always try to open posters to DOM objects. Maybe they are unfamiliar, or don't know about them. It answers the question, just with a better answer (opinion) then actually asked for.That's why I asked for the exact input syntax!Anyway you're right in that XMLDOM is more reliable in the general case, but the poster insisted on a regexp.I don't know what DOM objects are, hence my confusion.My apologies.. Edited December 5, 2012 by tes5884 www.tspitz.com
jdelaney Posted December 5, 2012 Posted December 5, 2012 I provided a link with the basics of DOM objects. I suggest reading through it, if you are going to work with lots of xml files. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
PhoenixXL Posted December 6, 2012 Posted December 6, 2012 Example#include <Array.au3> $RSS = InetRead('http://www.filehippo.com/download_adobe_reader/rss') $RSS = BinaryToString($RSS) ;Get the Text Between the Tag $sTitle = TagBetween($RSS, 'title') For $i = 0 To UBound($sTitle) - 1 $sVersion = Version($sTitle[$i]) ConsoleWrite('Index:' & $i & ' Version:' & $sVersion & @CR) Next _ArrayDisplay($sTitle) Func TagBetween($sString, $sTag) $aRet = StringRegExp($sString, "(?i)(?s)<" & $sTag & ">(.*?)</" & $sTag & ">", 3) If @error Then Return SetError(@error, @extended, -1) Return $aRet EndFunc ;==>TagBetween Func Version($sString) ;Remove the Alphabets $aRet = StringRegExpReplace($sString, "([^0-9.])*", '') If @error Then Return SetError(@error, @extended, -1) If $aRet = '' Then Return 0 Return $aRet EndFunc ;==>Version My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.
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