-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f426e3
commit e43f2da
Showing
3 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
var twitter = require("twitter"); | ||
|
||
var twitter = new twitter({ | ||
consumer_key: "mOUpwzhjCGYrPpqBL03n8cbtg", | ||
consumer_secret: "CFEMDfwkiMnLAO7ofi0ConXlDAmwqUmaAKkx8XQRtfQnMWxI4N", | ||
access_token_key: "261608471-ATGdO8ydPJ3l36vMKJgqTSecpoQZsHNIaBbXjJCJ", | ||
access_token_secret: "Lwo2SrXGLHapLoXhp3LWiWELpnT1JhPcCEvEgsRmlrkKZ" | ||
}); | ||
|
||
var methods = {}; | ||
|
||
methods.twitter = twitter; | ||
|
||
methods.gettweet = function(callback) { | ||
twitter.get("search/tweets", { q: "earthquake", count: 1 }, function( | ||
error, | ||
tweets, | ||
response | ||
) { | ||
console.log("Request made to twitter...."); | ||
if (error) { | ||
console.log("Error occurred...." + error.errno); | ||
return callback({ statusCode: 404, statusMessage: error.errno }); | ||
} else if (response.statusCode != 200) { | ||
console.log("Error occured...." + response.statusMessage); | ||
return callback({ | ||
statusCode: 404, | ||
statusMessage: response.statusMessage + " Try again later...." | ||
}); | ||
} else if (tweets.statuses.length === 0) { | ||
console.log("No tweets returned...."); | ||
return callback({ | ||
statusCode: 404, | ||
statusMessage: "No tweets returned try again later....." | ||
}); | ||
} else { | ||
console.log("Tweet returned successfully...."); | ||
//profile_image_url friends_count: 76 | ||
return callback({ | ||
statusCode: 200, | ||
statusMessage: "Success", | ||
user: tweets.statuses[0].user.name, | ||
text: tweets.statuses[0].text, | ||
created_at: tweets.statuses[0].created_at, | ||
location: tweets.statuses[0].user.location, | ||
profile_image: tweets.statuses[0].user.profile_image_url | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
module.exports = methods; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
var bayes = require("bayes"); | ||
var classifier = bayes(); | ||
var fs = require('fs'); | ||
var CsvReadableStream = require('csv-reader'); | ||
var filename = "../FINALYEARPROJECT/public/datasets/file4.csv"; | ||
var outputflename="../FINALYEARPROJECT/public/classification/classifier.json"; | ||
var inputStream = fs.createReadStream(filename, 'utf8'); | ||
|
||
inputStream | ||
.pipe(CsvReadableStream({ parseNumbers: true, parseBooleans: true, trim: true })) | ||
.on('data', function (row) { | ||
classifier.learn(row[0],row[1]); | ||
}) | ||
.on('end', function (data) { | ||
var classifier_json=classifier.toJson(); | ||
fs.writeFile(outputflename, classifier_json, function(err, data){ | ||
if (err) console.log(err); | ||
console.log('Program is ready for prediction.........') | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const createCsvWriter = require("csv-writer").createObjectCsvWriter; | ||
const twitter = require("./gettweet.js").twitter; | ||
const fs = require("fs"); | ||
var paths = require("path"); | ||
var path = paths.join(__dirname, "../public/datasets"); | ||
|
||
var filename = "../FINALYEARPROJECT/public/datasets/file"; | ||
|
||
var methods = {}; | ||
|
||
methods.loaddataset = function() { | ||
fs.readdir(path, function(err, items) { | ||
|
||
filename += items.length + 1 + ".csv"; | ||
console.log("Dataset is loaded in file " + filename); | ||
const csvWriter = createCsvWriter({ | ||
path: filename, | ||
header: [{ id: "text", title: "TEXT" }] | ||
}); | ||
twitter.stream("statuses/filter", { track: "earthquake" }, function( | ||
stream | ||
) { | ||
stream.on("data", function(tweet) { | ||
let data = [{ text: tweet.text }]; | ||
csvWriter | ||
.writeRecords(data) // returns a promise | ||
.then(() => { | ||
console.log("Tweet written on file"); | ||
}); | ||
}); | ||
|
||
stream.on("error", function(error) { | ||
console.log("Error occured"); | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
module.exports = methods; |