diff --git a/core.js b/core.js new file mode 100644 index 0000000..d0b6dbc --- /dev/null +++ b/core.js @@ -0,0 +1,40 @@ +var twitter = require('twitter'); +const fs = require('fs'); + +var twitter = new twitter({ +consumer_key: 'mOUpwzhjCGYrPpqBL03n8cbtg', +consumer_secret: 'CFEMDfwkiMnLAO7ofi0ConXlDAmwqUmaAKkx8XQRtfQnMWxI4N', +access_token_key: '261608471-ATGdO8ydPJ3l36vMKJgqTSecpoQZsHNIaBbXjJCJ', +access_token_secret: 'Lwo2SrXGLHapLoXhp3LWiWELpnT1JhPcCEvEgsRmlrkKZ' +}); + + +var search = "earthquake" + +//Stream data +twitter.stream('statuses/filter', {track: search}, function(stream) { +stream.on('data', function(tweet) { +console.log(tweet.text); +}); +stream.on('error', function(error) { +}); +}); + + +//twitter.get('search/tweets', {q: 'earthquake'}, function(error, tweets, response) {console.log(tweets);}); + + + + + +/* +//Getting keys from json object +var op=Object.keys(tweets); +console.log(op); +*/ + +/* +//Saving JSON to file + let data = JSON.stringify(tweet); + fs.writeFileSync('student.json', data); +*/ diff --git a/index.js b/index.js new file mode 100644 index 0000000..8d9e9df --- /dev/null +++ b/index.js @@ -0,0 +1,87 @@ +/* +Created By:Kunal Dwivedi on 27/10/2018 +*/ + +//Declaration +const express = require('express'); +const app = express(); +var twitter = require('twitter'); +var NodeGeocoder = require('node-geocoder'); +var options = { + provider: 'google', + httpAdapter: 'https', + apiKey: 'AIzaSyCXLoGrNXHCazTfVETItNy95g8lJPurI4w', + formatter: null +}; +var geocoder = NodeGeocoder(options); +var twitter = new twitter({ + consumer_key: 'mOUpwzhjCGYrPpqBL03n8cbtg', + consumer_secret: 'CFEMDfwkiMnLAO7ofi0ConXlDAmwqUmaAKkx8XQRtfQnMWxI4N', + access_token_key: '261608471-ATGdO8ydPJ3l36vMKJgqTSecpoQZsHNIaBbXjJCJ', + access_token_secret: 'Lwo2SrXGLHapLoXhp3LWiWELpnT1JhPcCEvEgsRmlrkKZ' +}); + +// front-end declarations +app.set('view engine','ejs'); +app.use(express.static('public')); + +//Ensure unique tweets are published +var newpost="first"; + +/************Async requests*********/ +//for displaying tweets +app.get('/loadlocation', function (req, res) +{ + twitter.get('search/tweets', {q: 'earthquake',count:1}, function(error, tweets, response) { + if(error){ res.send({statusCode:404,statusMessage:"INTERNET NOT WORKING"}); } + else{ + if(response.statusCode!=200){res.send({statusCode:400,statusMessage:response.statusMessage});} + else{ + geocoder.geocode(tweets.statuses[0].user.location, function ( err, data ) { + if(err){res.send({statusCode:400,statusMessage:"Error: Status is OVER_QUERY_LIMIT."}); } + else{res.send({statusCode:200,latitude:data[0].latitude,longitude:data[0].longitude});} + }); + } + } + }); +}); + + +app.get('/loaddata', function (req, res) +{ + var funcvalue,output; + twitter.get('search/tweets', {q: 'earthquake',count:1}, function(error, tweets, response) { + if(error || tweets.statuses===undefined){ + res.send("
`s get reset. However, we also reset the\n// bottom margin to use `rem` units instead of `em`.\np {\n margin-top: 0;\n margin-bottom: $paragraph-margin-bottom;\n}\n\n// Abbreviations\n//\n// 1. Remove the bottom border in Firefox 39-.\n// 2. Add the correct text decoration in Chrome, Edge, IE, Opera, and Safari.\n// 3. Add explicit cursor to indicate changed behavior.\n// 4. Duplicate behavior to the data-* attribute for our tooltip plugin\n\nabbr[title],\nabbr[data-original-title] { // 4\n text-decoration: underline; // 2\n text-decoration: underline dotted; // 2\n cursor: help; // 3\n border-bottom: 0; // 1\n}\n\naddress {\n margin-bottom: 1rem;\n font-style: normal;\n line-height: inherit;\n}\n\nol,\nul,\ndl {\n margin-top: 0;\n margin-bottom: 1rem;\n}\n\nol ol,\nul ul,\nol ul,\nul ol {\n margin-bottom: 0;\n}\n\ndt {\n font-weight: $dt-font-weight;\n}\n\ndd {\n margin-bottom: .5rem;\n margin-left: 0; // Undo browser default\n}\n\nblockquote {\n margin: 0 0 1rem;\n}\n\ndfn {\n font-style: italic; // Add the correct font style in Android 4.3-\n}\n\n// stylelint-disable font-weight-notation\nb,\nstrong {\n font-weight: bolder; // Add the correct font weight in Chrome, Edge, and Safari\n}\n// stylelint-enable font-weight-notation\n\nsmall {\n font-size: 80%; // Add the correct font size in all browsers\n}\n\n//\n// Prevent `sub` and `sup` elements from affecting the line height in\n// all browsers.\n//\n\nsub,\nsup {\n position: relative;\n font-size: 75%;\n line-height: 0;\n vertical-align: baseline;\n}\n\nsub { bottom: -.25em; }\nsup { top: -.5em; }\n\n\n//\n// Links\n//\n\na {\n color: $link-color;\n text-decoration: $link-decoration;\n background-color: transparent; // Remove the gray background on active links in IE 10.\n -webkit-text-decoration-skip: objects; // Remove gaps in links underline in iOS 8+ and Safari 8+.\n\n @include hover {\n color: $link-hover-color;\n text-decoration: $link-hover-decoration;\n }\n}\n\n// And undo these styles for placeholder links/named anchors (without href)\n// which have not been made explicitly keyboard-focusable (without tabindex).\n// It would be more straightforward to just use a[href] in previous block, but that\n// causes specificity issues in many other styles that are too complex to fix.\n// See https://github.com/twbs/bootstrap/issues/19402\n\na:not([href]):not([tabindex]) {\n color: inherit;\n text-decoration: none;\n\n @include hover-focus {\n color: inherit;\n text-decoration: none;\n }\n\n &:focus {\n outline: 0;\n }\n}\n\n\n//\n// Code\n//\n\npre,\ncode,\nkbd,\nsamp {\n font-family: $font-family-monospace;\n font-size: 1em; // Correct the odd `em` font sizing in all browsers.\n}\n\npre {\n // Remove browser default top margin\n margin-top: 0;\n // Reset browser default of `1em` to use `rem`s\n margin-bottom: 1rem;\n // Don't allow content to break outside\n overflow: auto;\n // We have @viewport set which causes scrollbars to overlap content in IE11 and Edge, so\n // we force a non-overlapping, non-auto-hiding scrollbar to counteract.\n -ms-overflow-style: scrollbar;\n}\n\n\n//\n// Figures\n//\n\nfigure {\n // Apply a consistent margin strategy (matches our type styles).\n margin: 0 0 1rem;\n}\n\n\n//\n// Images and content\n//\n\nimg {\n vertical-align: middle;\n border-style: none; // Remove the border on images inside links in IE 10-.\n}\n\nsvg:not(:root) {\n overflow: hidden; // Hide the overflow in IE\n}\n\n\n//\n// Tables\n//\n\ntable {\n border-collapse: collapse; // Prevent double borders\n}\n\ncaption {\n padding-top: $table-cell-padding;\n padding-bottom: $table-cell-padding;\n color: $table-caption-color;\n text-align: left;\n caption-side: bottom;\n}\n\nth {\n // Matches default `