Jump to content
UBot Underground

Help with table comparison


Recommended Posts

Good morning guys,

 

sorry to bother you but I'm facing quite a few problems trying to compare table cells from 2 different csv database.

this is the situation: the first database contains all the products for an ecommerce website. because a single product  can be found in different sub-categories and the subcategories are missing from the main database, I had to create a new database which contains only the subcategories (in the first column) and the product number (in the second column).

what the bot should do is:

 

1) check 2 cells value (the products numbers);

2) if the value is the same, add the value from the subcategories table to a new row, else, check the next product id, and so on.

 

This is the code:

 

clear table(&datafeed)
clear table(&categories)
create table from file("C:\\Users\\luciano\\Desktop\\datafeed ubot\\datafeed.csv", &datafeed)
create table from file("C:\\Users\\luciano\\Desktop\\datafeed ubot\\categories db.csv", &categories)

set(#row position product id datafeed, 1, "Global")
set(#row position category, 1, "Global")
set(#row position product id, 1, "Global")
set(#product id datafeed position, 1, "Global")
set(#current category position, 1, "Global")
set(#product id category position, 1, "Global")
set(#product id datafeed position value, $table cell(&datafeed, #row position product id datafeed, 0), "Global")
set(#current category position value, $table cell(&categories, #row position category, 0), "Global")
set(#product id category position value, $table cell(&categories, #row position product id, 1), "Global")
loop($table total rows(&datafeed)) {
     if($comparison(#current category position value, "=", #product id datafeed position value)) {
        then {
            set table cell(&datafeed, #row position, 19, #current category position value)
        }
        else {
        }
    }
    increment(#product id datafeed position)
    increment(#row position)
    if($comparison(#current category position value, "=", #product id datafeed position value)) {
        then {
            set table cell(&datafeed, #row position, 19, #current category position value)
        }
        else {
            increment(#current category position)
            increment(#product id category position)
        }
    }
}
save to file("C:\\Users\\luciano\\Desktop\\db.csv", &datafeed)

Do you have any suggestions?

 

Thanks in advance,

 

Lucio

Link to post
Share on other sites

I tried with this code too, but same results:

clear table(&datafeed)
clear table(&categories)
create table from file("C:\\Users\\luciano\\Desktop\\datafeed ubot\\datafeed.csv", &datafeed)
create table from file("C:\\Users\\luciano\\Desktop\\datafeed ubot\\categories db.csv", &categories)
add list to list($plugin function("TableCommands.dll", "$list from table", &datafeed, "Column", 0), %product id datafeed, "Don\'t Delete", "Global")
add list to list($plugin function("TableCommands.dll", "$list from table", &categories, "Column", 1), %product id category, "Don\'t Delete", "Global")
add list to list($plugin function("TableCommands.dll", "$list from table", &categories, "Column", 0), %categories, "Don\'t Delete", "Global")
set(#row position, 1, "Global")
set(#product id datafeed position, 1, "Global")
set(#current category position, 1, "Global")
set(#product id category position, 1, "Global")
set(#product id datafeed position value, $next list item(%product id datafeed), "Global")
set(#current category position value, $next list item(%categories), "Global")
set(#product id category position value, $next list item(%product id category), "Global")
loop($list total(%product id datafeed)) {
    if($comparison(#current category position value, "=", #product id datafeed position value)) {
        then {
            set table cell(&datafeed, #row position, 19, #current category position value)
        }
        else {
        }
    }
    increment(#product id datafeed position)
    increment(#row position)
    if($comparison(#current category position value, "=", #product id datafeed position value)) {
        then {
            set table cell(&datafeed, #row position, 19, #current category position value)
        }
        else {
            increment(#current category position)
            increment(#product id category position)
        }
    }
}
save to file("C:\\Users\\luciano\\Desktop\\db.csv", &datafeed)
Link to post
Share on other sites

I tried with this code too, but same results:

clear table(&datafeed)
clear table(&categories)
create table from file("C:\\Users\\luciano\\Desktop\\datafeed ubot\\datafeed.csv", &datafeed)
create table from file("C:\\Users\\luciano\\Desktop\\datafeed ubot\\categories db.csv", &categories)
add list to list($plugin function("TableCommands.dll", "$list from table", &datafeed, "Column", 0), %product id datafeed, "Don\'t Delete", "Global")
add list to list($plugin function("TableCommands.dll", "$list from table", &categories, "Column", 1), %product id category, "Don\'t Delete", "Global")
add list to list($plugin function("TableCommands.dll", "$list from table", &categories, "Column", 0), %categories, "Don\'t Delete", "Global")
set(#row position, 1, "Global")
set(#product id datafeed position, 1, "Global")
set(#current category position, 1, "Global")
set(#product id category position, 1, "Global")
set(#product id datafeed position value, $next list item(%product id datafeed), "Global")
set(#current category position value, $next list item(%categories), "Global")
set(#product id category position value, $next list item(%product id category), "Global")
loop($list total(%product id datafeed)) {
    if($comparison(#current category position value, "=", #product id datafeed position value)) {
        then {
            set table cell(&datafeed, #row position, 19, #current category position value)
        }
        else {
        }
    }
    increment(#product id datafeed position)
    increment(#row position)
    if($comparison(#current category position value, "=", #product id datafeed position value)) {
        then {
            set table cell(&datafeed, #row position, 19, #current category position value)
        }
        else {
            increment(#current category position)
            increment(#product id category position)
        }
    }
}
save to file("C:\\Users\\luciano\\Desktop\\db.csv", &datafeed)

By quickly throwing an eye on your code I see that you are using the lists the wrong way. 1st list parameter is list name, and 2nd list parameter is the data you want to load from a list (not the other way around).

Link to post
Share on other sites

Lucio,

 

Can you give examples of your 2 DB's and then what it should look like at the end?

 

Like:

 

Product numbers DB

6540654

63406546

3654654

460

746546

440

 

Categories DB

 

Phones

Cell Phones

Cell phone accesseries

Iphones

Blackberry's

 

 

New DB

 

?

 

Maybe you upload them.

next to post button is "more reply options" button to attach files.

 

Or id you are editing a post you made it would be "use full editor"

Link to post
Share on other sites

Lucio,

 

Here's a couple examples. The second one is probably closer to what you want. Without knowing what your categories DB looks like I'm just guessing. You can check these out and hopefully work off of these examples.

 

Example 1

 

set(#prod IDs"15
58
122
555""Global")
set(#category list"15
44
800
555
9000
186
69""Global")
clear list(%exist in category)
clear list(%category list)
clear list(%prod IDs)
add list to list(%prod IDs$list from text(#prod IDs$new line), "Delete""Global")
add list to list(%category list$list from text(#category list$new line), "Delete""Global")
loop($list total(%prod IDs)) {
    set(#prod next item$next list item(%prod IDs), "Global")
    set(#prod exist in category$plugin function("File Management.dll""$exists in list"%category list#prod next item), "Global")
    if(#prod exist in category) {
        then {
            add item to list(%exist in category#prod next item"Delete""Global")
        }
        else {
        }
    }
}

 

 

Example 2

 

set(#prod IDs"15
58
122
555""Global")
set(#category list"Phones,Iphones,Blackberry\'s,Windows Phone
15,800,33,44,69
44,9000,15,9000,555
800,122,15,555,186
555,444,555,888,999
9000,58,69,122,111
186,400,300,600,58
69,58,900,992,449""Global")
if($file exists("{$special folder("Desktop")}\\demo table.csv")) {
    then {
    }
    else {
        save to file("{$special folder("Desktop")}\\demo table.csv"#category list)
    }
}
clear list(%exist in category)
clear list(%category list)
clear list(%prod IDs)
add list to list(%prod IDs$list from text(#prod IDs$new line), "Delete""Global")
add list to list(%category list$list from text(#category list$new line), "Delete""Global")
clear table(&categories)
create table from file("{$special folder("Desktop")}\\demo table.csv"&categories)
loop($list total(%prod IDs)) {
    set(#prod next item$next list item(%prod IDs), "Global")
    set(#category index"-1""Global")
    loop($table total columns(&categories)) {
        increment(#category index)
        set(#category$table cell(&categories, 0, #category index), "Global")
        clear list(%column)
        add list to list(%column$plugin function("TableCommands.dll""$list from table"&categories"Column"#category index), "Delete""Global")
        set(#prod exist in category$plugin function("File Management.dll""$exists in list"%column#prod next item), "Global")
        if(#prod exist in category) {
            then {
                add item to list(%exist in category"{#prod next item},{#category}""Delete""Global")
            }
            else {
            }
        }
    }
}

 

make sure you have plugins installed and activated.

 

Your table delimiter may be different too. US is a coma and Europe is semicolon.

 

TC

luciono examples.ubot

Link to post
Share on other sites

Traffik Cop,

 

first of all thanks for your help and i apologize if i couldn't reply sooner. i'm attaching the first 50 rows of both databases. I'm going to test your examples asap.

 

thanks in advance for your time,

 

Lucio

datafeed test.csv

categories db test.csv

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...