Last active
August 29, 2015 14:27
-
-
Save planetexpress69/8d4181ccd8c42d0d0f94 to your computer and use it in GitHub Desktop.
Leaks
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
func get(path: String) { | |
let url = NSURL(string: path) | |
let session = NSURLSession.sharedSession() | |
running = true | |
let task = session.dataTaskWithURL(url!, completionHandler: { | |
[unowned self] (data, response, error) -> Void in | |
println("Task completed") | |
if(error != nil) { | |
// If there is an error in the web request, print it to the console | |
println(error.localizedDescription) | |
} | |
var err: NSError? | |
var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as! NSDictionary | |
if(err != nil) { | |
// If there is an error parsing JSON, print it to the console | |
println("JSON Error \(err!.localizedDescription)") | |
} | |
var results: String = jsonResult["return"] as! String | |
var foo = self.splitLines(results) as [[String : AnyObject]] | |
//self.delegate.didReceiveResults(foo) | |
self.running = false | |
}) | |
task.resume() | |
} | |
/*********************************************************************************************************/ | |
// MARK: - Parse the fuck out of Eidberger's haystack | |
// --------------------------------------------------------------------------------------------- | |
func splitLines(string: String) -> [[String : AnyObject]] { | |
var newArray = [[String : AnyObject]]() | |
var linesArray = split(string) {$0 == "\n"} | |
for line in linesArray { | |
var splittedLine = split(line, allowEmptySlices: true) {$0 == ";"} | |
if splittedLine.count < 21 { | |
println("No result!") | |
return newArray | |
} | |
newArray.append( | |
[ | |
"positionReceived" : splittedLine[0], | |
"typeOfShipId" : splittedLine[1], | |
"dimensionA" : splittedLine[2], | |
"dimensionB" : splittedLine[3], | |
"dimensionC" : splittedLine[4], | |
"dimensionD" : splittedLine[5], | |
"dimensionL" : splittedLine[6], | |
"dimensionW" : splittedLine[7], | |
"name" : splittedLine[9], | |
"latitude" : splittedLine[14], | |
"longitude" : splittedLine[15], | |
"trueHeading" : splittedLine[10], | |
"courseOverGround" : splittedLine[11], | |
"speedOverGround" : splittedLine[12], | |
"orient" : splittedLine[13], | |
"typeOfShipIcon" : splittedLine[18], | |
"objectId" : splittedLine[19], | |
"age" : splittedLine[20] | |
] | |
) | |
} | |
return newArray | |
} | |
/*********************************************************************************************************/ | |
"1439974111;passenger;9;6;2;2;15;4;;WITTOW;;342.9;0.0;;54.092918;12.123948;DE;480124;5;3339616;365\n1439974427;yacht;9;13;3;3;22;6;;POOLSTER;;0.0;0.0;86.0;54.092930;12.143198;NL;872198,419746,637600,872194,637597,231364;4;2015859;49\n1439974108;yacht;8;3;3;1;11;4;;NEVER SAY NEVER;;;0.1;;54.093255;12.139640;DE;;4;9986916;368\n1439974366;yacht;6;6;6;2;12;8;;TONIA;;191.3;0.0;108.0;54.093323;12.139633;DE;;4;9924080;110\n1439974466;yacht;0;31;0;7;31;7;ROSTOCK;APHRODITE;;0.0;0.0;121.0;54.093333;12.126560;NL;9072,881377,775634,927913,1105779,951613,1071655,795827,1071667,9275,541777,610867,14430,610864,612085,659107,14431,16063,25916,86712,96077,101804,298444,486982,654043,659110,16176,58258,97266,177454,298447,610870,639940,659104,97263,97264,97265,285625,285628,486979,97267,17030;4;49471;10\n1439974469;tug;65;15;3;6;80;9;ROSTOCK;ZEEZAND EXPRESS;278;186.8;0.0;278.0;54.093572;12.124657;NL;955217,1002799,969047,1158747,750341,750332,82739,511183,673669,69412,82738,99140,100313,143626,143629,251656,511186;3;57067;7\n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment