Skip to content

Commit

Permalink
That img module.
Browse files Browse the repository at this point in the history
(Since I had only one test case, no guarantees on what happens when someone else posts another twitter picture.)
  • Loading branch information
kevinychen committed Apr 27, 2013
1 parent 7b6d899 commit 269c79c
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
1 change: 1 addition & 0 deletions node/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ app.configure('development', function(){
app.get('/users', user.list);
app.get('/menu.json', info.getItems);
app.get('/news.json', info.getNews);
app.get('/img.json', info.getImg);
app.get('/', routes.index);

app.get('/:num', routes.index);
Expand Down
21 changes: 21 additions & 0 deletions node/public/javascripts/img.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var imgURL = '/img.json';

function getImg() {
tweetfeed = $("#tweet_feed").html();
match = tweetfeed.match(/pic\.twitter([^<]+)/);
if (match == null) {
$("#imgpanel").slideUp("slow");
return;
}
imgurl = 'http://' + match[0];
$.getJSON(imgURL + '?imgurl=' + encodeURIComponent(imgurl), function(data) {
if (jQuery.isEmptyObject(data)) {
$("#imgpanel").slideUp("slow");
return;
}

$("#imgpanel").slideDown("slow");
$("#img").html("<img src='" + data.imgurl + "' alt='Image Not Found'/>");
});
};

18 changes: 18 additions & 0 deletions node/routes/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ function getNews(req, res) {
return;
};

function getImg(req, res) {
var imgurl = req.query.imgurl;
request(imgurl, function(error, response, body) {
if (error || response.statusCode != 200) {
res.json({});
return;
};
var imageLink = body.match(new RegExp('<img class="large media-slideshow-image"[^>]+'));
if (imageLink == null) {
res.json({});
return;
}
var realurl = imageLink[0].match(/src="[^"]+/)[0].substring(5); // trim to only url
res.json({'imgurl': realurl});
});
};

exports.getItems = getItems;
exports.getNews = getNews;
exports.getImg = getImg;

22 changes: 4 additions & 18 deletions node/views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<script src="/javascripts/menu.js"></script>
<script src="/javascripts/news.js"></script>
<script src="/javascripts/fancy.js"></script>
<script src="/javascripts/img.js"></script>

<script type='text/javascript'>
lastUpdated = -1;
Expand Down Expand Up @@ -49,27 +50,12 @@
getPredictions();
getMenu();
getNews();
getFancy();
getImg();
}
}, 1000);
$("#tweetpanel").delay(600).slideDown("slow");
t = setInterval(function(){
if ($("#tweet_feed").html() != ""){
clearInterval(t);
processPic();
}
},300);
function processPic(){
tweetfeed = $("#tweet_feed").html();
match = tweetfeed.match(/pic\.twitter([^<]+)/);
imgurl = match[0];
$("#img").html("<img src='http://" + imgurl + "' />");
$("#imgpanel").delay(600).slideDown("slow");
}
});
</script>

Expand Down Expand Up @@ -134,6 +120,7 @@
</div>
</div>

<!--
<div class="row">
<div class="large-12 columns" id='fancypanel'>
<h3 class='fancy-header'>Fancy</h3>
Expand All @@ -142,7 +129,7 @@
</div>
</div>
</div>
<!--
-->
<div class="row">
<div class="large-12 columns" id='imgpanel'>
<h3 class='img-header'>Image</h3>
Expand All @@ -151,7 +138,6 @@
</div>
</div>
</div>
-->
</div>
<!--
<div id='' class='panel'>
Expand Down

0 comments on commit 269c79c

Please sign in to comment.