Jump to content
shaggy89

If $a Not in $b

Recommended Posts

shaggy89

Hi all,

        I'm looking for some help to finish my last bit of code. So far my code scrapes an XML from a webpage and then sends and email on a trigger but what i need to do is find a way to see if a string is in the XML.

example

Global $Site = IniRead("settings.ini", "Site", "web", "")
;============================================================

while 1
    if @HOUR >= 05 and @HOUR <= 18 then
        $sXML = BinaryToString(InetRead($Site))
        $Day = StringRegExpReplace($sXML, '(?is).*<availability.*?day="([^"]+).*</availability.*', '$1')
        $4WD = StringRegExpReplace($sXML, '(?is).*?<members.*? name="4WD Operations".*?day="([^"]+).*</members.*', '$1')
        $ARS = StringRegExpReplace($sXML, '(?is).*?<members.*? name="Advance Rescue Shorting".*?day="([^"]+).*</members.*', '$1')
        $ART = StringRegExpReplace($sXML, '(?is).*?<members.*? name="Advanced Rescue Tools Equipment".*?day="([^"]+).*</members.*', '$1')
        $ASO = StringRegExpReplace($sXML, '(?is).*?<members.*? name="Air Search Observer".*?day="([^"]+).*</members.*', '$1')
        check("Day Crew", $day)
        check("4WD Operations",$4WD)
        check("Advance Rescue Shorting",$ARS)
        check("Advanced Rescue Tools Equipment",$ART)
        check("Air Search Observer",$ASO)
        sleep(3000000) ; Sleep for 50 mins cause the extra 10 mins is outside of the if
    EndIf
WEnd
func check($Class, $ScrapeValue)
    $Num = IniRead("settings.ini", "Numbers", $class, "")
    if $Num == 0 Then
    EndIf
    if $ScrapeValue < $Num then box($class, $ScrapeValue, $Num)
     EndFunc
func box ($class, $ScrapeValue, $Num)
    MsgBox(6,"test", $class & $ScrapeValue &$Num )
 EndFunc

So right now if I open the settings.ini and made day = 2 and the XML site has day as 1 the message box shows message. (great)

But if <members.*? name="4WD Operations".*?day="([^"]+).*</members is not in the XML is shows the whole XML.

 

So i need a way to do a

if $class not in $sXML skip else keep running script

Global $Site = IniRead("settings.ini", "Site", "web", "")
;============================================================

while 1
    if @HOUR >= 05 and @HOUR <= 18 then
        $sXML = BinaryToString(InetRead($Site))
        $Day = StringRegExpReplace($sXML, '(?is).*<availability.*?day="([^"]+).*</availability.*', '$1')
        $4WD = StringRegExpReplace($sXML, '(?is).*?<members.*? name="4WD Operations".*?day="([^"]+).*</members.*', '$1')
        $ARS = StringRegExpReplace($sXML, '(?is).*?<members.*? name="Advance Rescue Shorting".*?day="([^"]+).*</members.*', '$1')
        $ART = StringRegExpReplace($sXML, '(?is).*?<members.*? name="Advanced Rescue Tools Equipment".*?day="([^"]+).*</members.*', '$1')
        $ASO = StringRegExpReplace($sXML, '(?is).*?<members.*? name="Air Search Observer".*?day="([^"]+).*</members.*', '$1')
        check("Day Crew", $day)
        check("4WD Operations",$4WD)
        check("Advance Rescue Shorting",$ARS)
        check("Advanced Rescue Tools Equipment",$ART)
        check("Air Search Observer",$ASO)
        sleep(3000000) ; Sleep for 50 mins cause the extra 10 mins is outside of the if
    EndIf
WEnd
func check($Class, $ScrapeValue)
    $Num = IniRead("settings.ini", "Numbers", $class, "")
    if $Num == 0 Then
    EndIf
    if $Class Not In $sXML ; At this point I need to see if the Class is in the XML if its not skip
    EndIf
     ElseIf $ScrapeValue < $Num then box($class, $ScrapeValue, $Num)
     EndFunc
func box ($class, $ScrapeValue, $Num)
    MsgBox(6,"test", $class & $ScrapeValue &$Num )
 EndFunc

any ideas ?

Share this post


Link to post
Share on other sites
TheSaint

You could just use one of the XML UDF's here and do things directly or you could just check for each element first with the StringInStr command ... provided there is a unique element that can be relied upon.

Another way, is to use StringSplit a few times, having divided up your XML read into lines, and weeding out what is not wanted, reducing the XML as you go.

 


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
shaggy89

So I have tried using StringInStr and have made a bit of progress. If I change code to this

Global $Site = IniRead("settings.ini", "Site", "web", "")
;============================================================

while 1
    if @HOUR >= 05 and @HOUR <= 18 then
        $sXML = BinaryToString(InetRead($Site))
        $Day = StringRegExpReplace($sXML, '(?is).*<availability.*?day="([^"]+).*</availability.*', '$1')
        $4WD = StringRegExpReplace($sXML, '(?is).*?<members.*? name="4WD Operations".*?day="([^"]+).*</members.*', '$1')
        $ARS = StringRegExpReplace($sXML, '(?is).*?<members.*? name="Advance Rescue Shorting".*?day="([^"]+).*</members.*', '$1')
        $ART = StringRegExpReplace($sXML, '(?is).*?<members.*? name="Advanced Rescue Tools Equipment".*?day="([^"]+).*</members.*', '$1')
        $ASO = StringRegExpReplace($sXML, '(?is).*?<members.*? name="Air Search Observer".*?day="([^"]+).*</members.*', '$1')
        $Day = StringInStr($sXML, $Day)
        check("Day Crew", $Day)
;=======REST OF CODE===========

nothing happens (knowing there is 3 "day" available and requirement set to 8) just skips to the next one instead of box being displayed. On the other hand it does skip if the $ is not in the XML.


UPDATE:

So i have used StringInString as suggested but now my next issue.

In my heck function I've added my StingInString right now I've got it to EXIT if $vay = 0 how can i do it that if $vay = 0 then skip and check the next $class  ?

 

func check($Class, $ScrapeValue)
    $vay = StringInStr($sXML, $Class)
    if $vay = 0 Then Exit ;Need to add some sort of skip
    $Num = IniRead("settings.ini", "Numbers", $class, "")
    if $ScrapeValue < $Num then box($class, $ScrapeValue, $Num, $vay)
     EndFunc
func box ($class, $ScrapeValue, $Num, $vay)
    MsgBox(1,"test", $class & $ScrapeValue &$Num )
 EndFunc

 

 

Edited by shaggy89
Update

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • chacoya121
      By chacoya121
      can someone plz explain how WinAPI work and some example script plz
    • watchoverme
      By watchoverme
      hi all, how can i move mouse to the place where pixel changes
       
      While Sleep (3000)
      $pix = PixelChecksum(0,0,55,55)
      If IsArray($pix) = True Then
      MouseMove($pix [0],$pix[1])
      EndIf
      WEnd
    • Ignacio
      By Ignacio
      Hello, and good day
      Im trying to make a sentence autocompleter so that when you type certain words (or commands) the scripts, and im in need of help/pointers
      That is what i have at the time and the issues i have currently is that:
      - I cant find an easy way to reset the counter to 0 in case a different letter from those are pressed ( tried NOT _ispressed but i think i got it wrong)
      -Is there another way to detect the key press that _ispressed? (i couldnt find it so far), since i feel like it is too clunky ( although maybe that is just me and my way to code)
      - for some reason the hex code (6F) for the / (divide nume pad) isnt working for me
       
      Im thinking of making a text file with some words to use them as variables/comparations  (so that at least removes the need of a variable for the words in the script) and make the script make a temporal text file to save the input and then compare it with the other one. But i dont know if that is a good approach.
      Thanks for your time and patience.
    • WiorDi37
      By WiorDi37
      Hello, Everyone!
      I want when clicking the exit button the window will close. If content changes upon exit the program will automatically choose not save.
      Look forward to the help, thanks.
      #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <AutoItConstants.au3> $GUI = GUICreate("Form1", 220, 119, 192, 124, $WS_SYSMENU) GUISetFont(10, 400, 0, "Tahoma") GUICtrlCreateGroup("Chuẩn bị trình chiếu", 16, 16, 185, 65) $ok_Button = GUICtrlCreateButton("Ok", 32, 48, 75, 25) $exit_Button = GUICtrlCreateButton("Exit", 112, 48, 75, 25) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $ok_Button ShellExecute(@MyDocumentsDir&'\Dich-thuat\Short-Document.pdf', "", "", Default, @SW_MAXIMIZE) WinWaitActive("Data and Computer Communications (Eighth Edition) - Google Chrome") ShellExecute(@MyDocumentsDir&'\Dich-thuat\Document.rtf', "", "", Default, @SW_MAXIMIZE) WinWaitActive("Document.rtf [Compatibility Mode] - Word") ShellExecute(@MyDocumentsDir&'\Dich-thuat\Presentation1.pptx', "", "", Default, @SW_MAXIMIZE) WinWaitActive("Presentation1.pptx - PowerPoint") MouseClick("left", 1381, 886, 1) Sleep(2000) MsgBox(64, "Thông báo", "Đã chuẩn bị xong") Case $exit_Button WinClose("Presentation1.pptx - PowerPoint") ;I need help handling this place Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  

    • badcoder123
      By badcoder123
      Hey everyone,
      I've been messing around with some new things and adlibs look extremely useful/interesting, however, I can't seem to get it to work.. Here's what I have
      HotKeySet("{F1}", "_Exit") $qCount = 1 Global $_Timer AdlibRegister($_Timer, 1000) AdlibUnRegister($_Timer) While 1 SoundPlay(@WindowsDir & "\media\tada.wav", 1) $qCount += 1 ToolTip('"Tada" has been played ' & $qCount & " times",200,200) WEnd Func _Timer() Local Static $iCount += 1 ConsoleWrite($iCount) If $iCount = 20 Then ConsoleWrite("iCount is at " & $iCount) EndFunc Func _Exit() Exit EndFunc Basically I want it to call the _Timer function but it doesn't seem to work :/ any ideas?
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.