Skip to content

Instantly share code, notes, and snippets.

@ntlk
Created December 12, 2013 15:10
Show Gist options
  • Save ntlk/7929507 to your computer and use it in GitHub Desktop.
Save ntlk/7929507 to your computer and use it in GitHub Desktop.
visual twitter
<!doctype html>
<html>
<head>
<title>Visual Twitter</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
// search twitter for a keyword
var url = "http://twitcher.steer.me/search?q=christmas&key=XXX";
$.get(url, function(data) {
var tweet_text = data[0]["text"];
put_tweet_on_page(tweet_text);
var words_array = separate_words(tweet_text);
// search flickr for a matching photo for each word
for (var i = 0; i < words_array.length; i++) {
var word = words_array[i];
console.log(word);
fetch_photo_from_flickr(word);
}
});
function put_tweet_on_page(text) {
$('#tweet').html(text);
}
// break it down into separate words
function separate_words(tweet_text) {
tweet_text = tweet_text.replace(/\!/g, '')
.replace(/\./g, '')
.replace(/\?/g, '')
.replace(/\//g, '')
.replace(/\:/g, '')
.replace(/\&/g, 'and')
.replace(/\@/g, '')
.replace(/\#/g, '')
.replace(/RT/g, '');
var words = tweet_text.split(' ');
return words;
}
function fetch_photo_from_flickr(word) {
var flickr_url = "http://api.flickr.com/services/rest/?api_key=XXX&text=" + word + "&method=flickr.photos.search&format=json&nojsoncallback=1";
if (word) {
$.ajax({
url: flickr_url,
success: flickr_handler
});
}
}
function flickr_handler(data) {
console.log(data);
}
// Key:
// XXX
// Secret:
// XXX
// show the pictures on the page
});
</script>
</head>
<body>
<h1>Visual Twitter</h1>
<p id="tweet"></p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment