Return multiple results from a single CSV File?
Return multiple results from a single CSV File?
Is there a way to return multiple results from the same CSV File, instead of just the first result?
for example, i have several csv file lists of specific movies, like: Mockumentaries, Direct To Video, Banned Films, Remakes, Based on True Stories, and several more.
And I want to check them if the movie name matches to add that additional info to the file name when applicable. but the only way I know how is to check each one separately.
But if I could add them all into 1 CSV File. and return each result when each one is found. (Surrounded by Brackets for each one) that would be great, and seems it'd be easier to maintain. I just don't know if it is possible.
Example:
I'd like it to return: [DTV] [Banned in US] [Remake] (When all 3 are in the same CSV File)
moviename;DTV
moviename;Banned in US
moviename;Remake
Thanks,
-Dev
for example, i have several csv file lists of specific movies, like: Mockumentaries, Direct To Video, Banned Films, Remakes, Based on True Stories, and several more.
And I want to check them if the movie name matches to add that additional info to the file name when applicable. but the only way I know how is to check each one separately.
But if I could add them all into 1 CSV File. and return each result when each one is found. (Surrounded by Brackets for each one) that would be great, and seems it'd be easier to maintain. I just don't know if it is possible.
Example:
I'd like it to return: [DTV] [Banned in US] [Remake] (When all 3 are in the same CSV File)
moviename;DTV
moviename;Banned in US
moviename;Remake
Thanks,
-Dev
Re: Return multiple results from a single CSV File?
Yes, the csv(...) function will give you a Map so you just grab the data you need from there.
@see http://groovy.codehaus.org/groovy-jdk/j ... g.Closure)
@see http://groovy.codehaus.org/groovy-jdk/j ... g.Closure)
Re: Return multiple results from a single CSV File?
I'm not so familiar with Groovy. But thanks for pointing me in the right direction, i'll see if I can get it working.
Re: Return multiple results from a single CSV File?
You know it took me over and hour to finally get the map to display with:
as i kept working on variations of the .get()
But when I finally did get the map to show, it only showed the first and the last record in the csv file. not the ones in the middle. (I tested with 3 and 4 rows in the csv file)
then I tried: it is only showing 2 results (not 4 that are in the csv file), and both show as the movie name, not the value they should be.
Though if i do this:
it shows the correct value, but only the last one.
if i do:
it shows the values, but still only the first one, and the last one. not the second or third one. and if i add a 5th, it'll show that one, and not the 4th one.
The link you posted says that findResults():
"Iterates through the map transforming items using the supplied closure and collecting any non-null results."
I dunno, am I doing something wrong?
Code: Select all
{csv('C:/FileBot Settings/Movies/ExtraFileInfo/Test.csv')}
But when I finally did get the map to show, it only showed the first and the last record in the csv file. not the ones in the middle. (I tested with 3 and 4 rows in the csv file)
then I tried:
Code: Select all
{csv('C:/FileBot Settings/Movies/ExtraFileInfo/Test.csv').findResults(n)}
Though if i do this:
Code: Select all
{csv('C:/FileBot Settings/Movies/ExtraFileInfo/Test.csv').findResults{ k, v -> k == n ? "$v" : null }}
if i do:
Code: Select all
{csv('C:/FileBot Settings/Movies/ExtraFileInfo/Test.csv').findResults{ k, v -> k =~ n ? "$v" : null }}
The link you posted says that findResults():
"Iterates through the map transforming items using the supplied closure and collecting any non-null results."
I dunno, am I doing something wrong?
Re: Return multiple results from a single CSV File?
The I assume the first and last entry match k =~ n and thus return v while the others return null and get ignored (since only non-null results are collected).
Maybe this little exercise will help:
Result: [0, 1]
Keep in mind that your k =~ n assumes that n is a regular expression, which it isn't. You probably want k.contains(n) if you want to check if k contains n.
Maybe this little exercise will help:
Code: Select all
{[0:'a',1:'b',2:'c'].findResults{ k, v -> v =~ /a|b/ ? k : null}}
Keep in mind that your k =~ n assumes that n is a regular expression, which it isn't. You probably want k.contains(n) if you want to check if k contains n.
Re: Return multiple results from a single CSV File?
I tried:
and it still came up with the first and last result:
here is the csv file for testing (on all of the examples)
... it's only returning: [Super Natural, True Story]
The problem, i would assume. appears to be: The csv(...) is creating the map of only the first and last result.
When I try this:
it only returns: {Mortal Kombat=Super Natural, Mortal Kombat=True Story}
now i can add/change as many lines i want. even by copy/paste and it'll still only show the first and last result.
Code: Select all
{csv('C:/FileBot Settings/Movies/ExtraFileInfo/Test.csv').findResults{ k, v -> k.contains(n) ? "$v" : null }}
here is the csv file for testing (on all of the examples)
Code: Select all
Mortal Kombat;Super Natural
Mortal Kombat;Based on Video Game
Mortal Kombat;New Line Studios
Mortal Kombat;True Story
The problem, i would assume. appears to be: The csv(...) is creating the map of only the first and last result.
When I try this:
Code: Select all
{csv('C:/FileBot Settings/Movies/ExtraFileInfo/Test.csv')}
now i can add/change as many lines i want. even by copy/paste and it'll still only show the first and last result.
Re: Return multiple results from a single CSV File?
Alright, the csv(...) function will give you a Map, and a Map cannot contain the same key more than once.
e.g.
I guess you could just swap key<->value in your csv file.
e.g.
Code: Select all
Key1;Value
Key2;Value
Key3;Value
Re: Return multiple results from a single CSV File?
that's odd, cause it still showed 2. but by swapping the key in the csv file. that worked. Thank you. I never would have thought of that.