Created
November 7, 2014 05:42
-
-
Save abhibeckert/b109dcf806001959244b to your computer and use it in GitHub Desktop.
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
#!/usr/bin/swift | |
import Foundation | |
print("Content-type: text/html\n\n") | |
// load all data files | |
let dataDir = "/Users/abhi/www/data.json-files" | |
let dataFiles = NSFileManager.defaultManager().contentsOfDirectoryAtPath(dataDir, error: nil) as Array! | |
// pick which one to show | |
let timeinterval = NSDate().timeIntervalSince1970 | |
let fileIndex = Int(timeinterval * 60) % dataFiles.count | |
let filePath = dataDir.stringByAppendingPathComponent(dataFiles[fileIndex] as String) | |
// print it out | |
let data = NSData(contentsOfFile: filePath) | |
if data == nil { | |
print("cannot read file") | |
exit(0) | |
} | |
let string = NSString(data: data!, encoding: NSUTF8StringEncoding) | |
print(string!) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment