Created
March 30, 2015 01:30
-
-
Save gmarceau/2f419ef3a8951971cd8f to your computer and use it in GitHub Desktop.
structure of the code follows structure of the data
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
// loadtweets.js: exports init function, which loads tweets from ./tweets folder into tweet_collection global variable. | |
var fs = require('fs'); | |
var _und = require('./underscore-min')._; | |
tweet_collection = []; | |
function Tweet(diskTweet, donor) { | |
// if encapsulated RT, act on retweeted_status value instead of entire tweet | |
if (tweet_json.retweeted_status) { | |
tweet_json = tweet_json.retweeted_status | |
}; | |
_und.extend(this, tweet_json); | |
this.created_at = new Date(this.created_at); | |
this.donors = []; | |
this.donors.push(donor); | |
// console.log(this.id_str + " donated by " + this.donors); | |
} | |
function parseDiskTweet(disktweet, donor) | |
{ | |
return new Tweet(tweet, donor); | |
} | |
function parseDiskTweets(diskTweets, donor) | |
{ | |
_.map(function (t) { return diskTweets(t, donor) }, parseDiskTweet); | |
} | |
function parseDiskTweetsFileContent(content, donor) | |
{ | |
var diskTweets = JSON.parse(content.substring(fileContents.indexOf("["))); | |
parseDiskTweets(diskTweets); | |
} | |
function parseDiskTweetFile(filename, callback, donor) | |
{ | |
fs.readFile(file, 'utf8', function(err, fileContents) { // Read in file and pass to callback | |
if (err) { | |
console.log(err); | |
} | |
else if (fileContents.substr(0,9) !== "Grailbird") { // If the file is not valid, skip and notify. | |
console.log("-- File " + file + " was not a valid Grailbird data file and was skipped."); | |
callback([]); // Still call back an empty array so it's accounted for. | |
} | |
else | |
callback(parseDiskTweetsFileContent(fileContent, donor)); | |
}); | |
} | |
function parseDirectory(dirname) | |
{ | |
... | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment