mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Feb 2015
Posts: 138
kap Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Feb 2015
Posts: 138
I've been trying to get this rss newsticker working using native msl and com. Half the trouble was finding the documentation, but Ouims was a great help.

This is what I have working so far:

Code
; URLGET RSS FEED -> BINVAR            [x]
; BINVAR          -> COM XML (MSXML)   [x]
; COM XML         -> PARSE DATA        [ΒΌ]
; PARSE DATA      -> NEWSTICKER WINDOW [ ]

; IXMLDOMElement Members
; https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms757048(v=vs.85)

alias _rssfin {
  if (($1 isnum) && ($urlget($1).state == ok)) {
    if ($com(a)) .comclose a
    .comopen a MSXML2.DOMDocument.6.0
    if ($comerr) goto :error
    echo -ag Load into XML (slurp): $com(a,LoadXML,3,&bstr, &slurp) - $com(a).result
    if ($com(b)) .comclose b
    echo -ag selectNodes: $com(a,selectNodes,3,bstr,//item,dispatch* b)
    if ($comerr) goto :error
    var %n $comval(b,0,selectNodes), %i 1
    while (%i <= %n) {
      echo -ag $comval(b,%i,xml)
      ;parse data
      inc %i
    }
    :error
    if ($com(a)) .comclose a
    if ($com(b)) .comclose b
  }
}
; https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url
alias _rssget {
  var %pattern https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)
  if (!$regex($1,%pattern)) echo 4 Invalid URL
  else noop $urlget($1-,gb,&slurp,_rssfin)
}


If I type...
Code
/_rssget https://www.volkskrant.nl/voorpagina/rss.xml


...then I get the raw xml echo-ed in my window as per the line: echo -ag $comval(b,%i,xml)

However I wish to keep parsing the xml using the MSXML2.DOMDocument.6.0 COM object and return the title, the link and the pubDate data. I've tried a variety of things using the visual studio object browser and the documentation online to look for ideas, but can't get anything working. I was wondering if someone out there can give me a hint...


GNU Terry Pratchett - Looking for a mIRC help channel -> Check #mircscripting @ irc.swiftirc.net
Joined: Feb 2015
Posts: 138
kap Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Feb 2015
Posts: 138
The following seems to work, but is not elegant:
Code
alias _rssfin {
  if (($1 isnum) && ($urlget($1).state == ok)) {
    if ($com(a)) .comclose a
    .comopen a MSXML2.DOMDocument.6.0
    if ($comerr) goto error
    echo -ag Load into XML (slurp): $com(a,LoadXML,3,&bstr, &slurp) - $com(a).result
    if ($com(b)) .comclose b
    echo -ag selectNodes: $com(a,selectNodes,3,bstr,//item,dispatch* b)
    if ($comerr) goto error
    var %n $comval(b,0,selectNodes), %i 1
    while (%i <= %n) {
      ;echo -ag $comval(b,%i,xml)
      if ($com(c)) .comclose c
      .comopen c MSXML2.DOMDocument.6.0
      if ($comerr) goto error
      echo -ag Load into XML ($!com): $com(c,LoadXML,3,bstr, $comval(b,%i,xml)) - $com(a).result
      if ($com(d)) .comclose d
      echo -ag Title: $com(c,selectNodes,3,bstr,//title,dispatch* d)
      if ($comerr) goto error
      echo -ag $comval(d,1,text)
      if ($com(d)) .comclose d
      echo -ag Link: $com(c,selectNodes,3,bstr,//link,dispatch* d)
      if ($comerr) goto error
      echo -ag $comval(d,1,text)
      if ($com(d)) .comclose d
      echo -ag pubDate: $com(c,selectNodes,3,bstr,//pubDate,dispatch* d)
      echo -ag $comval(d,1,text)       
      if ($com(d)) .comclose d
      inc %i
    }
    :error
    if ($com(a)) .comclose a
    if ($com(b)) .comclose b
    if ($com(c)) .comclose c
    if ($com(d)) .comclose d
  }
}
; https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url
alias _rssget {
  var %pattern https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)
  if (!$regex($1,%pattern)) echo 4 Invalid URL
  else noop $urlget($1-,gb,&slurp,_rssfin)
}



Code
/_rssget https://www.volkskrant.nl/voorpagina/rss.xml

Last edited by kap; 07/04/20 05:09 PM.

GNU Terry Pratchett - Looking for a mIRC help channel -> Check #mircscripting @ irc.swiftirc.net
Joined: Feb 2015
Posts: 138
kap Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Feb 2015
Posts: 138
I dug up an old post from FibreOptics (https://forums.mirc.com/ubbthreads.php/topics/134803/re-cnn-headline-grabber#Post134803) and re-created my script. It's not finished, but the following works a little better:
Code
alias rss {
  var %error, %pattern https?:\/\/(?:www\.)?([-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6})\b([-a-zA-Z0-9()@:%_\+.~#?&\/\/=]*)
  if (!$regex($1,%pattern)) %error = Invalid URL!
  else {
    var %t $ticks, %itemcol itemcol. $+ %t, %com rss. $+ %t, %com2 rss2. $+ %t, %com3 rss3. $+ %t, %url $1
    .comopen %com MSXML2.DOMDocument.6.0
    if ((!$com(%com)) || ($comerr)) %error = Unable to create an instance of MSXML2.DOMDocument.6.0
    elseif ((!$com(%com, async, 4, bool, false)) || ($comerr)) %error = Unable to set async property
    elseif ((!$com(%com, load, 1, bstr*, %url)) || ($comerr)) %error = Unable to load XML from: %url
    elseif ((!$com(%com, selectnodes, 1, bstr*, /rss/channel/item, dispatch* %itemcol)) || ($comerr)) %error = Unable to select nodes /rss/channel/item
    else {
      var %items $comval(%itemcol,0), %item 1
      if (%items) {
        while (%item <= %items) {
          if ((!$com(%itemcol, item, 1, uint, %item, dispatch* %com2)) || ($comerr)) %error = Cannot dispatch XML for individual item to new object
          if ($com(%com2)) {
            .comclose %com2 $com(%com2, childnodes, 3, dispatch* %com3) 
            if ($com(%com3)) {
              var %children $comval(%com3,0), %child 1
              while (%child <= %children) {
                if ($comval(%com3,%child,tagName) == title) echo -ag $v1 : $comval(%com3,%child,text)
                if ($comval(%com3,%child,tagName) == link) echo -ag $v1 : $comval(%com3,%child,text)                
                if ($comval(%com3,%child,tagName) == description) echo -ag $v1 : $comval(%com3,%child,text)
                if ($comval(%com3,%child,tagName) == pubDate) echo -ag $v1 : $comval(%com3,%child,text)
                inc %child
              }
              .comclose %com3
            }
          }
          inc %item
        }
      }
      else %error = No news items found.
    }
  }
  ; Handle errors
  :error
  if ($error) var %error $v1 | reseterror

  ; Close coms
  if ($com(%com)) .comclose %com
  if ($com(%com2)) .comclose %com2
  if ($com(%com3)) .comclose %com3
  if ($com(%itemcol)) .comclose %itemcol

  ; Show error
  if (%error) echo -ag Error: $v1
}

Last edited by kap; 10/04/20 08:38 AM. Reason: removed $_rss.shorten alias

GNU Terry Pratchett - Looking for a mIRC help channel -> Check #mircscripting @ irc.swiftirc.net
Joined: Feb 2015
Posts: 138
kap Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Feb 2015
Posts: 138
I used the smarts I gained learning about COM and XML to create a RSS manager/viewer for PnP. Can be had here: https://github.com/peace-and-protection/PnPAddons422 (Naturally doesn't work without script Peace and Protection)


GNU Terry Pratchett - Looking for a mIRC help channel -> Check #mircscripting @ irc.swiftirc.net

Link Copied to Clipboard