Splitting output into multiple files.
Hi all,
First I would like to say thanks to the creators of this software, I love it so far, and once I have gotten it to do what I want I'm definetly going to buy it!
Would someone be so kind to tell me how to add some text to the beginning and the end of the file created? And also how do I split up the file with each file having a 100 records? So it would be Info1, Info2, Info3 each containing 100 records pr. file?
Here's my current code:
try
{
session.log( "Writing AIM data to a file." );
// Open up the file to be appended to.
out = new FileWriter( "Info.txt", true );
// Write out the data to the file.
out.write( "\"" );
out.write( dataRecord.get( "USERNAME" ));
out.write( "\"" );
out.write( "\n" );
// Close up the file.
out.close();
}
catch( Exception e )
{
session.log( "An error occurred while writing the data to a file: " + e.getMessage() );
}
Thank you so much!
Splitting output into multiple files.
Nautilus2910,
Thank you for your kind words about screen-scraper.
To add data to the beginning and ending of your output you would simply add a line above and below where you're currently writing out.
For example:
out.write( "Your data to prepend here" );
out.write( dataRecord.get( "USERNAME" ));
out.write( "Your data to append here" );
out.write( "\"" );
There is a bit more to parsing out the extracted data into chunks like you describe. I'm assuming the data you want to parse will be coming from ONE extractor pattern. If so, you have an option to "Automatically save the data set generated by this extractor pattern in a session variable" under the Advanced tab for that extractor pattern.
The variable is stored as a dataSet. Please see explanations of dataSet on the following pages.
http://www.screen-scraper.com/support/docs/api_documentation.php
http://www.screen-scraper.com/support/docs/using_extractor_patterns.php
With the dataSet saved as a session variable you can then reference that variable in a script "after pattern is applied" and manually parse the data. Because your data will be stored in the form of a dataSet (you can think of it as an array or as results from a database query) you will then loop through the elements and write them.
You'll want to set an outside loop that keeps track of when to write a new file and when the entire data set is parsed and an inner loop that writes out the data in chunks of 100 at a time.. Performing the parsing and loop will require relatively basic knowledge of Java. Some starter examples can be found here.
http://www.screen-scraper.com/support/docs/api_documentation.php#getNumDataRecords
I hope this helps get you going. Please let us know if you run in to any issues.
Thanks,
Scott