Jump to content
UBot Underground

Table Comparison And Scraping Problem


Recommended Posts

Hi,

 

Wondering if anyone could help me with a problem I am having.

 

I am wanting to loop through a table and only scrape Cities if their latitude number (Column 5) is +2.00 more than the row (City) my app is currently on.

 

So in the table below my original position (#row) is 0 (Adak with has a latitude of 51.88), and I want to scrape the next cities that have a latitude number up to 53.88 which in this case would be:

Adak, Atka, Attu Station, Nikolski, Unalaska

<img src="https://imgur.com/a/PUrFojF">

I can't figure out what I need to qualify (comparison, eval etc) and extract the cities needed.

 

    set(#tableloop,0,"Global")
    clear list(%NearbyCities)
    loop($table total rows(&data)) {
        set(#Plus2,$table cell(&data,#row,5),"Global")
        if($comparison($table cell(&data,#tableloop,5),"> Greater than",#Plus2)) {
            then {
                add item to list(%NearbyCities,$table cell(&data,#tableloop,0),"Don\'t Delete","Global")
            }
            else {
            }
        }
        increment(#tableloop)
    }
 
Any ideas?
 
 
Link to post
Share on other sites

create table from file("C:\\ubot sample scripts\\sampletable.txt",&cityElevation)
clear list(%nearby_cities)
set(#max_elevation,$add($table cell(&cityElevation,0,5),2),"Global")
set(#current_row,0,"Global")
loop($table total rows(&cityElevation)) {
    if($comparison($table cell(&cityElevation,#current_row,5),"<= Less than or equal to",#max_elevation)) {
        then {
            add item to list(%nearby_cities,$table cell(&cityElevation,#current_row,0),"Don\'t Delete","Global")
            increment(#current_row)
        }
        else {
        }
    }
}

 

 

this was the table I used -

 

adak,alaska,ak,adak,ak,51.88
atka,alaska,ak,atka,ak,52.19611
attu station,alaska,ak,attu staion,ak,52.880
nikolski,alaska,ak,nikolski,ak,52.938
unlaska,alaska,ak,aualaska,ak,53.87
akutan,alaska,ak,akutan,ak,54.13
false pass,alaska,ak,false pass,ak,54.85
King cove,alaska,ak,King cove,ak,55.85
 
----------------------------------------------------------------
I am assuming you want to scrape the city name only?
 
the logic is as follows - 
---------------------------------------
We set a variable to = 51.88 + 2
 
set(#max_elevation,$add($table cell(&cityElevation,0,5),2),"Global")
 
 
Then we look at the 'column 5' value of each row - and assert - that it's value should be less than 53.88 or equal to 53.88
 
 if($comparison($table cell(&cityElevation,#current_row,5),"<= Less than or equal to",#max_elevation))
 
 
if yes - add city name - 'column 0'  in this case of the  current row to list.
 
add item to list(%nearby_cities,$table cell(&cityElevation,#current_row,0),"Don\'t Delete","Global")
  • Like 1
Link to post
Share on other sites

if $list total is => #max results:

    stop script

 

something like that

This almost got me there but the Stop Script of course stops the primary loop. I need it to exit this 2nd loop if the condition (#maxresults) is met.

Any ideas?

Link to post
Share on other sites

not sure if this is what you are looking for - 

 

create table from file("C:\\Users\\ubot sample scripts\\sampletable.txt",&cityElevation)
set(#list total,0,"Global")
set(#max_results,3,"Global")
clear list(%nearby_cities)
set(#max_elevation,$add($table cell(&cityElevation,0,5),2),"Global")
set(#current_row,0,"Global")
loop($table total rows(&cityElevation)) {
    if($both($comparison(#list total,"< Less than",#max_results),$comparison($table cell(&cityElevation,#current_row,5),"<= Less than or equal to",#max_elevation))) {
        then {
            add item to list(%nearby_cities,$table cell(&cityElevation,#current_row,0),"Don\'t Delete","Global")
            increment(#list total)
            increment(#current_row)
        }
        else {
            increment(#current_row)
        }
    }
}

Link to post
Share on other sites

This almost got me there but the Stop Script of course stops the primary loop. I need it to exit this 2nd loop if the condition (#maxresults) is met.

Any ideas?

 

Throw it in a command and use the return command to exit that custom command.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...