We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Saving Data Cumulatively
Page Index Toggle Pages: 1
Saving Data Cumulatively (Read 382 times)
Saving Data Cumulatively
Mar 23rd, 2006, 4:01am
 
Hello --

I am trying to write a program that will enable me to create a file that logs instances of a certain kind of object appearing for auction on eBay (for simplicity's sake, I'll call it a "pen") over an extended period of time.

I have my program built to the point where I can get it to look at eBay at the present time and log each pen that is currently up for auction -- creating a string array of each pen auction's 10-digit ebay id number, and saving the array of numbers to a text file in the sketch folder.

But what I can't figure out is how I can add to this file (rather than re-writing it and losing old data) over repeated runs of the program.

Put another way:
1) Say today I run the program, and two "pens" are found on eBay, and their IDs are 34 and 37.  So I save a file in the sketch folder called "auctions.txt" that contains those IDs ("34 37")

2) In two days, I run the program again.  Again, two pens are found on eBay, and their IDs are 37 and 52 -- the auction for pen 34 has ended since I last ran the program, so it is no longer on eBay.  The fact that 37 is a duplicate is not important, but I would like to add 52 to "auctions.txt" without losing the original entry of "34 37".  So I would like it to now read "34 37 52" (or "34 37 37 52"... all that matters is that I have all the numbers).

Any suggestions would be appreciated!  Thanks very much.
Re: Saving Data Cumulatively
Reply #1 - Mar 23rd, 2006, 11:02am
 
It shoudl be farily easy to read the file, then add to it...

Code:

//assuming you have the ID numbers in an array called newPens

String lines[] = loadStrings("auctions.txt");
for(int i=0;i<newPens.length;i++)
{
lines=append(lines,newPens[i]);
}
saveStrings("auctions.txt",lines);


Untested, you may have to save to a different name, since I'm not sure if processing keeps the file open after a loadStrings.
Page Index Toggle Pages: 1