Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
dwivedikunal100 authored Mar 14, 2019
1 parent 4f426e3 commit e43f2da
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
52 changes: 52 additions & 0 deletions helper./gettweet.js
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;
20 changes: 20 additions & 0 deletions helper./learn.js
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.........')
});
});
39 changes: 39 additions & 0 deletions helper./loaddataset.js
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;

0 comments on commit e43f2da

Please sign in to comment.