Jump to content
Sign in to follow this  
shaggy89

If $a Not in $b

Recommended Posts

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

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.

 


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

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Jamestay97
      Hello! Thanks you for looking at my post
      **No source code I'm sorry work related can't copy information**
      I've been using autoit for about 1 year. 
      I'm having trouble automating a click on an internet explorer web page and I've tried a lot of examples from help pages and forums already. The object I'm trying to click on isnt always in the same spot so I can't use mouse click or control click, I have tried to use the different get collection options and clickbyname, or index or get object. I'm just struggling. 
      Description of object I'm trying to click -- 
      HTML Code looks like <a ng-click.. "Click Here" it appears it's just a click able object named "click here" that opens a hidden window by running a script inside the web page. I'm not able to grab the information from the window unless it's open so I have to automate this click somehow. 
       
      I understand it's difficult to assist without having something to look at, I apologize for that sincerely and appreciate and assistance and suggestions. 
    • By kingjacob90
      Hi
      So I am trying to click the green button, this button is not always in the same place. So fare I am trying to click it by finding the color but there is also something else with the same color on the screen (circled in yellow) that is causing issues. Is there a way to use the Title and Class of the window (can't be just the window as there are more than one with the same name).
      How does AutoIt Info get this information?

    • By adjist
      Hello all! 
       
      Getting this error :
      (22) : ==> Variable used without being declared.: if $vNumber = 0 Then if ^ ERROR  
      But I'm sure I have defined the variable, as in the top of my script has 
      Global $vNumber = 0  
      How would I go about fixing this?
       
    • By MarkIT
      Hi AutoIT masters,
      Good day! Sorry to have bothered this forum but we really need help. We are working on an automation project that is running on VDI server. The BOTS are in .exe are running fine until AV detected them and deleted the files. The files were re-compiled and AV kept on deleting them. The copy of the .exe BOT deleted were sent to Symantec for whitelisting. After whitelisting, it is no longer deleted but no longer working as designed (showing Line script error). We checked the scripts and there were no issues since we run it using SciTE editor and it performed the desired task. Good thing we found on this thread the solution using .a3x and the BOTS worked fine and no longer deleted. Now, the problem is they are asking why the BOTS won't run in .EXE and what is the reason behind Symantec AV deleting them. We raised a case with Symantec but they cannot provide further information as they are always seeing the file as "False Positive". We even tested with Symantec turned off and those .EXE files are working fine, however, after re-enabling, it got deleted.
      Just seeking help on how to better convince them that it is really Symantec causing the issue and the .a3x file.
    • By AutoitMike
      Scite 3.4.4
      Win 10
      I click "Help" or press F1, there is no response
      If I use the file explorer and double click Autoit.chm or Autoit3.chm help opens.
      There is no dialog to check or uncheck "Always ask before opening this file" when clicking on these files.
       
      If you are curious as to why I dont have the latest version, I am creating a back up laptop that has a VERY extensive automation application that I have written over the past 15 years.
       
      An extremely potent, powerful, needed function has been deleted in the upgrade of Autoit in recent years that I can not do without. If my main laptop dies, which it almost did, I am in a very bad position. So I bought the exact same laptop and I am "cofiguring" it to work exactly the same as my main laptop. However, this one has been "Upgraded" to Win 10 which I hope is not the problem. 
      Thanks for any help
×
×
  • Create New...