commit 5bb8f61a2ada8f591434fddfa84a61ed7eb37b16
parent 4b37764326de5e9ea148c32685923f768ce26bef
Author: underd0g1 <hide4@comcast.net>
Date: Wed, 20 May 2020 23:52:20 -0400
added leaflet page
Diffstat:
4 files changed, 74 insertions(+), 4 deletions(-)
diff --git a/index.js b/index.js
@@ -29,8 +29,7 @@ console.log('got request made on / route! Sending the EJS page now!');
res.render('index');
});
-//optional array of terms to track
-//var watchList = ['love', 'hate'];
+
//decalre the post route
@@ -107,10 +106,41 @@ app.post('/userstatspage', function(req, res){
res.render('userstats', {
username: username,
- //pass the variables outside of the function.
+ //pass the variables outside of the function.
ratio: ratio,
friends: friends,
followers: followers
})
})
+
+app.post('/locations', function(req, res){
+ console.log(' sending the locations page!');
+ //get the input from the user and log it in the console.
+ var tag = req.body.tag;
+ console.log(tag);
+
+ //add my credentials to allow access to the api.
+ var T = new twit(creds);
+
+ //connect socket to the index page.
+ io.on('connection', function (socket) {
+ console.log('Connected');
+
+ //use the twit API to get a constant flow of data from twitter about a certain keyword.(s)
+ var sanFrancisco = [ '-122.75', '36.8', '-121.75', '37.8' ]
+
+ var stream = T.stream('statuses/filter', { locations: sanFrancisco })
+
+ //twit fucntion with callback to log the tweets and send them to socket.io
+ stream.on('tweet', function (tweet) {
+ console.log(tweet.text);
+ //socket.io function to send the text of the tweet to the front end page .
+ socket.emit('stream',tweet.text);
+
+ //render the sendit page
+});
+
+});
+res.render("locationspage");
+});
diff --git a/public/css/leafstyles.css b/public/css/leafstyles.css
@@ -0,0 +1 @@
+#mapid { height: 780px; }
diff --git a/views/index.ejs b/views/index.ejs
@@ -101,7 +101,7 @@
</div>
<div id = "locations" >
-<form id = 'locationtrends' action = "/locationpage" method = "post">
+<form id = 'locationtrends' action = "/locations" method = "post">
<div class="input-group mb-3">
<div class="input-group-append">
<span>
diff --git a/views/locationspage.ejs b/views/locationspage.ejs
@@ -0,0 +1,39 @@
+<html>
+ <head>
+ <title>locations</title>
+
+ <link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css"
+ integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
+ crossorigin=""/>
+ <link rel = 'stylesheet' href = '/css/leafstyles.css'>
+
+ <script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"
+ integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
+ crossorigin=""></script>
+
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
+ </head>
+ <body>
+
+ <script>
+ var socket = io.connect('http://localhost:3000');
+ socket.on('stream', function(tweet){
+ $('#tweetd').append(tweet+'<br>');
+ });
+ </script>
+
+<div id="mapid"></div>
+ <script>
+
+ var mymap = L.map('mapid').setView([51.505, -0.09], 13);
+ L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
+ attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
+ }).addTo(mymap);
+ </script>
+
+
+
+
+
+ </body>
+ </html>