Last active
January 3, 2016 01:59
-
-
Save johnvoorhees/8392903 to your computer and use it in GitHub Desktop.
ComEd Electricity Price Tracker that can be tied to Panic's Status Board iPad app to track real versus actual electricity prices for ComEd, the Chicago-area electric utility.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.m | |
// Status Board Widget Predicted and Actual ComEd Prices | |
// | |
// Created by John Voorhees. | |
// Copyright (c) 2013 John Voorhees. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
int main(int argc, const char * argv[]) | |
{ | |
@autoreleasepool { | |
//create date string to append to URL string. | |
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; | |
[dateFormatter setDateFormat:@"yyyyMMdd"]; | |
NSDate *date = [NSDate date]; | |
NSString *formattedDateString = [dateFormatter stringFromDate:date]; | |
//NSLog(@"formattedDateString: %@", formattedDateString); | |
//today's prices string | |
NSString *fullURL = [NSString stringWithFormat:@"http://rrtp.comed.com/rrtp/ServletFeed?type=pricingtabledual&date=%@", formattedDateString]; | |
//NSLog(@"URL is %@", fullURL); | |
//Get contents of fullURL | |
NSURL *hourlyPriceURL = [NSURL URLWithString:fullURL]; | |
NSError *error = nil; | |
NSString *contents = [[NSString alloc] initWithContentsOfURL:hourlyPriceURL encoding:NSUTF8StringEncoding error:&error]; | |
//NSLog(@"data from web site: %@", contents); | |
//strip out html from contents of URL contents | |
contents = [contents stringByReplacingOccurrencesOfString:@"¢</td><td>" withString:@","]; | |
contents = [contents stringByReplacingOccurrencesOfString:@"¢</td></tr><tr>" withString:@"\n"]; | |
contents = [contents stringByReplacingOccurrencesOfString:@"<tr>" withString:@""]; | |
contents = [contents stringByReplacingOccurrencesOfString:@"<td>" withString:@""]; | |
contents = [contents stringByReplacingOccurrencesOfString:@"</tr>" withString:@"\n"]; | |
contents = [contents stringByReplacingOccurrencesOfString:@"</td>" withString:@""]; | |
contents = [contents stringByReplacingOccurrencesOfString:@"<small>" withString:@""]; | |
contents = [contents stringByReplacingOccurrencesOfString:@"</small>" withString:@""]; | |
contents = [contents stringByReplacingOccurrencesOfString:@";" withString:@""]; | |
contents = [contents stringByReplacingOccurrencesOfString:@"M" withString:@"M,"]; | |
//NSLog(@"New string: %@", contents); | |
//csv-ready string | |
NSString *csvContents = [NSString stringWithFormat:@"Electricity Prices,Predicted,Actual\n%@", contents]; | |
//NSLog(@"%@", csvContents); | |
[csvContents writeToFile:@"/Users/voorheesfamily/DropBox/dailyPrice.csv" atomically:NO encoding:NSUTF8StringEncoding error:&error]; | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment