BSSAXTweetParserDemo / BSSAXTweetParserDemo.m

#import <Foundation/Foundation.h>
#import "BSSAXTweetParser.h"
#import "BSTweet.h"

/* Public domain code. Brent Simmons 3 June 2010. */

int main (int argc, const char * argv[]) {

	NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
	NSLog(@"Downloading public timeline... wait a sec...");
	NSURLResponse *response = nil;
	NSError *error = nil;
	NSURL *publicTimelineURL = [NSURL URLWithString:@""];
	NSData *xmlData = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:publicTimelineURL] returningResponse:&response error:&error];
	/*I don't need to remind you about error checking, I'm sure.*/
	int reps = 1000;
	NSLog(@"Got it, parsing it %d times...", reps);
	BSSAXTweetParser *parser = nil;
	NSDate *start = [NSDate date];
	int i;
	for (i = 0; i < reps; i++) {
		parser = [[BSSAXTweetParser alloc] init];
		[parser parseData:xmlData];
		[parser release];
	NSTimeInterval t = [[NSDate date] timeIntervalSinceDate:start];
	NSLog(@"Total time: %f", t);
	NSLog(@"Avg. time: %f", t / reps);
	parser = [[BSSAXTweetParser alloc] init];
	[parser parseData:xmlData];
	NSMutableArray *tweetsAsDictionaries = [[NSMutableArray alloc] init];
	for (BSTweet *oneTweet in parser.tweets)
		[tweetsAsDictionaries addObject:[oneTweet dictionaryRepresentationForDebuggingOnly]];
	[parser release];
	NSLog(@"Here's the public timeline...\n%@", tweetsAsDictionaries);

	//	/*Write it to disk so you can look at it in Property List Editor*/	
//	[tweetsAsDictionaries writeToFile:[@"~/Desktop/BSSAXTwitterPublicTimelineArray.plist" stringByExpandingTildeInPath] atomically:YES];
//	/*Write data to disk so we can look at it.*/
//	[xmlData writeToFile:[@"~/Desktop/BSSAXTwitterData.xml" stringByExpandingTildeInPath] options:NSAtomicWrite error:&error];
	[tweetsAsDictionaries release];
	[pool drain];
 return 0;