kinda working

This commit is contained in:
Kai Hendry
2012-07-14 20:29:25 +02:00
parent fb99a1c5f4
commit cd48fa4286
5 changed files with 70 additions and 39 deletions

View File

@@ -1 +1,2 @@
DirectoryIndex index.shtml index.html
AddType text/cache-manifest .manifest

View File

@@ -103,6 +103,8 @@ cat <<END
END
fi
ln -sf $id.txt tweets.txt # Application cache greptweet.appcache
else
rm -rf $oldpwd/u/$id
echo '<h1 class="alert alert-error">Sorry the Twitter API is failing. Try again later.</h1>'

View File

@@ -10,7 +10,7 @@ $QUERY=urldecode(escapeshellarg(urlencode($_GET['q'])));
//fwrite($fp, $_GET['q'] . " : " . $QUERY . "\n");
//fclose($fp);
exec("grep -hi $QUERY *.txt", $array);
exec("grep -hi $QUERY tweets.txt", $array);
$data = json_encode($array);
echo $_GET['jsoncallback'] . '(' . $data . ');';
?>

View File

@@ -1,5 +1,5 @@
<!DOCTYPE HTML>
<html>
<html manifest="greptweet.appcache">
<head>
<meta charset="utf-8" />
<title>Grepping twitter backup</title>
@@ -28,7 +28,7 @@
<p class="help-inline">Type a search query like <a href="?foo">foo</a></p>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="/jquery-1.7.2.min.js"></script>
<script async src="/main.js"></script>
<footer><span id="source"></span></footer>

36
main.js
View File

@@ -1,6 +1,11 @@
function grep(query) {
$.getJSON("/u/" + NAME + "/grep.php?jsoncallback=?", { q: query }, function(data) {
if (navigator.onLine) {
$.getJSON("/u/" + NAME + "/grep.php?jsoncallback=?", {
q: query
},
function(data) {
var results = "<p class=\"label\">Searched for: " + query + "</p><ol>";
for (var i in data) {
tweet = data[i].split('|');
@@ -13,6 +18,26 @@ function grep(query) {
$('#results').prepend(results + "</ol>");
});
} else {
if (! lines) {
$.get('tweets.txt', function(data) {
lines = data.split("\n");
});
}
var results = "<p class=\"label\">Searched for: " + query + "</p><ol>";
for (var i = 0; i < lines.length - 1; i++) {
tweet = lines[i].split('|');
var re = new RegExp(query, 'i');
if (tweet[2].match(re)) {
results += "<li><a href=\"http://twitter.com/" + NAME + "/status/" + tweet[0] + "\">" + tweet.slice(2) + "</a></li>";
}
}
$('#results').prepend(results + "</ol>");
}
}
$(document).ready(function() {
@@ -22,7 +47,7 @@ $(document).ready(function() {
$("input[type=search]").change(function() {
query = this.value;
window.location.search = query;
// window.location.search = query; // Triggers Reload the page to get source for: http://greptweet/u/kaihendry/?food
grep(query);
});
@@ -35,11 +60,14 @@ $(document).ready(function() {
$("input[type=text]").focus();
footer = '<p><a href="' + NAME + '.txt" class="btn primary"><i class="icon-download"></i> Download</a>';
footer += '<a href="' + "/create.cgi?id=" + NAME +'" class="btn"><i class="icon-refresh"></i> Update</a></p>'
footer += '<a href="' + "/create.cgi?id=" + NAME + '" class="btn"><i class="icon-refresh"></i> Update</a></p>';
$("#source").html(footer);
document.title = "Greptweet " + NAME;
document.cookie = 'u=' + NAME + '; expires=Thu, 2 Aug 2021 20:47:11 UTC; path=/';
$("#home").click(function(){ document.cookie = 'u=' + NAME + '; expires=Thu, 2 Aug 2001 20:47:11 UTC; path=/'; });
$("#home").click(function() {
document.cookie = 'u=' + NAME + '; expires=Thu, 2 Aug 2001 20:47:11 UTC; path=/';
});
});