Jump to content



Photo

Table Comparison And Scraping Problem


  • Please log in to reply
7 replies to this topic

#1 cjacobs

cjacobs

    Member

  • Fellow UBotter
  • PipPip
  • 21 posts
  • OS:Windows 8
  • Total Memory:More Than 9Gb
  • Framework:v3.5
  • License:Developer Edition

Posted 04 September 2018 - 08:57 AM

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?
 
 


#2 HelloInsomnia

HelloInsomnia

    Advanced Member

  • Moderators
  • 3128 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v4.5+, unsure
  • License:Developer Edition

Posted 04 September 2018 - 09:07 AM

Can't you just add 2 like so
 

set(#Plus2,$add($table cell(&data,#row,5),2),"Global")


#3 Sanjeev

Sanjeev

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 361 posts
  • LocationIndia, Mumbai
  • OS:Windows 10
  • Total Memory:8Gb
  • Framework:v4.5+, unsure
  • License:Developer Edition

Posted 04 September 2018 - 09:33 AM

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")

upad%20ninja%20banner2.png


#4 cjacobs

cjacobs

    Member

  • Fellow UBotter
  • PipPip
  • 21 posts
  • OS:Windows 8
  • Total Memory:More Than 9Gb
  • Framework:v3.5
  • License:Developer Edition

Posted 04 September 2018 - 09:52 PM

Thanks for your input guys! Got it working using Sanjeev's code.

 

Is there a way to set a maximum number of results it will return?



#5 Code Docta (Nick C.)

Code Docta (Nick C.)

    Member for Hire

  • Fellow UBotter
  • PipPipPip
  • 1489 posts
  • LocationIn a Python or UBot IDE or ubotdocta.com
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v4.5+, unsure
  • License:Developer Edition

Posted 05 September 2018 - 08:12 PM

if $list total is => #max results:

    stop script

 

something like that


UBot Expert Tutorials Store

 

ubot-docta-header-ubot-expert-store.png

 

Python and UBot expert tutorials and documentation


#6 cjacobs

cjacobs

    Member

  • Fellow UBotter
  • PipPip
  • 21 posts
  • OS:Windows 8
  • Total Memory:More Than 9Gb
  • Framework:v3.5
  • License:Developer Edition

Posted 05 September 2018 - 09:04 PM

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?



#7 Sanjeev

Sanjeev

    Advanced Member

  • Fellow UBotter
  • PipPipPip
  • 361 posts
  • LocationIndia, Mumbai
  • OS:Windows 10
  • Total Memory:8Gb
  • Framework:v4.5+, unsure
  • License:Developer Edition

Posted 06 September 2018 - 02:09 AM

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)
        }
    }
}


upad%20ninja%20banner2.png


#8 HelloInsomnia

HelloInsomnia

    Advanced Member

  • Moderators
  • 3128 posts
  • OS:Windows 10
  • Total Memory:More Than 9Gb
  • Framework:v4.5+, unsure
  • License:Developer Edition

Posted 06 September 2018 - 07:12 AM

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.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users