NEO12 Posted February 23, 2010 Posted February 23, 2010 I'm trying to make a program that show the latest notification of facebook. I have a difficult part: how to pick up the text of the RSS (see url in script) In the script i have put a url between "" and for the moment there is nothing on it. I know that its something with stringregexp and IE.au3, but for the rest i'm turning around without finding something. I would also like to have a configuration GUI, but that i'll do it on myself. Please help me I already have a part of the script. Here is it: expandcollapse popup;#NoTrayIcon #include <IE.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <Array.au3> $width = 300 $height = 90 $xa = @DesktopWidth - $width - 5 $ya = @DesktopHeight - $height - 50 $GUi = GUICreate("Facebook Notification", $width, $height, $xa, $ya, $WS_POPUPWINDOW, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) $label = GUICtrlCreateLabel("Facebook Notification", 5, 5, 130, 20) $label2 = GUICtrlCreateLabel("", 5, 30, 130, 20) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd Func Notification() $baseurl = "http://www.facebook.com/feeds/notifications.php?id=100000295219880&viewer=100000295219880&key=683ac29a17&format=rss20" $Source = _IEBodyReadHTML( $baseurl) $array = StringRegExp($Source," <channel> <channel>", "<title> </title>") GUICtrlSetData($label2,$array) EndFunc Thanks to all in advance! Greets
dani Posted February 23, 2010 Posted February 23, 2010 (edited) This seems to work -- using Inet.au3 instead of IE.au3. It grabs the contents of the <title> tag, both of them. #include <Array.au3> #include <Inet.au3> $baseurl = "http://www.facebook.com/feeds/notifications.php?id=100000295219880&viewer=100000295219880&key=683ac29a17&format=rss20" $source = _InetGetSource($baseurl) $array = StringRegExp($source, "(?s).*<title>(.*)</title>.*", 3) _ArrayDisplay($array) Too bad there are no XML parsing functions to my knowledge, that's what you actually need. Edited February 23, 2010 by d4ni
NEO12 Posted February 23, 2010 Author Posted February 23, 2010 It's a good way but it's not the result i would have. It should look as this:
GEOSoft Posted February 23, 2010 Posted February 23, 2010 This seems to work -- using Inet.au3 instead of IE.au3. It grabs the contents of the <title> tag, both of them. #include <Array.au3> #include <Inet.au3> $baseurl = "http://www.facebook.com/feeds/notifications.php?id=100000295219880&viewer=100000295219880&key=683ac29a17&format=rss20" $source = _InetGetSource($baseurl) $array = StringRegExp($source, "(?s).*<title>(.*)</title>.*", 3) _ArrayDisplay($array) Too bad there are no XML parsing functions to my knowledge, that's what you actually need. You can do it without the array too. Instead of $array = StringRegExp($source, "(?s).*<title>(.*)</title>.*", 3) you can use this to get either Channel or Title $sRtn = StringRegExpReplace($source, "(?i)(?s)<(title|channel)>(.+?)</(title|channel)>", "$2") To get just title then $sRtn = StringRegExpReplace($source, "(?i)(?s)<title>(.+?)</title>", "$1") To get just channel, replace title in the one above with channel You can follow any of them with If @Extended Then Return $sRtn George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
NEO12 Posted February 23, 2010 Author Posted February 23, 2010 Ok But i'm looking for something that looks like my second post. With the function GUICtrlSetData($label2,$array) even if it's with or without array. http://www.autoitscript.com/forum/index.php?app=core&module=attach§ion=attach&attach_rel_module=post&attach_id=29754
dani Posted February 23, 2010 Posted February 23, 2010 (edited) @GEOSoft Please first actually test your code It doesn't work. I know why the Regular Expressions won't work -- you forgot .* or .+ before and after the <title>(.+?)</title>, right now it doesn't match anything. Anyway, the most important thing is you can't get both the <title> tags with that, as it only returns the contents of one of the <title> tags. I obviously did test StringRegExp replace but didn't use it as it wasn't quite what I wanted. Also, the RegEx "(?i)(?s)<(title|channel)>(.+?)</(title|channel)>" can match something like <channel> <title>Title of Post</title> It starts matching at <channel> and stops at </title>, this is undesirable as well. @NEO12 I think you have enough information do implement it yourself now, right? Come on show some effort yourself, you can do it It's a good way but it's not the result i would have. It should look as this: So that's the contents of the second <title>, right (in French @ your URL)? So that's the contents of $array[1] ... #include <Array.au3> #include <Inet.au3> $baseurl = "http://www.facebook.com/feeds/notifications.php?id=100000295219880&viewer=100000295219880&key=683ac29a17&format=rss20" $source = _InetGetSource($baseurl) $array = StringRegExp($source, "(?i)(?s)<title>(.+?)</title>", 3) MsgBox(0, "", $array[1]) It outputs: Sebastien Bauval a publié quelque chose sur votre mur. While my French isn't awesome I can only assume that's the translation of "... wrote something on your wall". Actually, "published something on your wall", I believe. Anyway, I think my or Facebook's encoding is messed up so it becomes publié instead of whatever it's supposed to be. Edited February 23, 2010 by d4ni
NEO12 Posted February 23, 2010 Author Posted February 23, 2010 (edited) That's right: Sébastien a publiAc quelque chose sur votre mur. That should appear in the place of "... wrote something on your wall" that acually should be "... published something on your wall". I've searched for "rss help" but i didn't find something that interested me. I'm not a great coder and before i posted i searched also on google but again found nothing. I'm just beginning here with autoit again, because i was occuped with something other (Private) I think i must look around this: code of gui... $baseurl = "http://www.facebook.com/feeds/notifications.php?id=100000295219880&viewer=100000295219880&key=683ac29a17&format=rss20" $source = _InetGetSource($baseurl) $array = StringRegExp($source, "(?i)(?s)<title>(.+?)</title>", 3) GUICtrlCreateLabel($array, 5, 30, 200, 20) while... Ok i found it : expandcollapse popup;#NoTrayIcon #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <Array.au3> #include <Inet.au3> $width = 300 $height = 90 $xa = @DesktopWidth - $width - 5 $ya = @DesktopHeight - $height - 50 $GUi = GUICreate("Facebook Notification", $width, $height, $xa, $ya, $WS_POPUPWINDOW, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST) $label = GUICtrlCreateLabel("Facebook Notification", 5, 5, 130, 20) $baseurl = "http://www.facebook.com/feeds/notifications.php?id=100000295219880&viewer=100000295219880&key=683ac29a17&format=rss20" $source = _InetGetSource($baseurl) $array = StringRegExp($source, "(?i)(?s)<title>(.+?)</title>", 3) GUICtrlCreateLabel($array[1], 5, 30, 200, 20) GUISetState(@SW_SHOW) While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd I must only improve it a little bit Thank you very much. Edited February 23, 2010 by NEO12
GEOSoft Posted February 23, 2010 Posted February 23, 2010 @GEOSoft Please first actually test your code It doesn't work. I know why the Regular Expressions won't work -- you forgot .* or .+ before and after the <title>(.+?)</title>, right now it doesn't match anything. Anyway, the most important thing is you can't get both the <title> tags with that, as it only returns the contents of one of the <title> tags. I obviously did test StringRegExp replace but didn't use it as it wasn't quite what I wanted. Also, the RegEx "(?i)(?s)<(title|channel)>(.+?)</(title|channel)>" can match something like <channel> <title>Title of Post</title> It starts matching at <channel> and stops at </title>, this is undesirable as well. I'll look at it when I get on a system with AutoIt actually installed. I should have noted that I was writing it on the fly and from memory. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!"
dani Posted February 24, 2010 Posted February 24, 2010 Ah ok, then it makes sense I'd always put that disclaimer @ your code if it's untested though
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