From 1c680703c6bcfb2337092855d7a7e26f6982cfb9 Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Tue, 22 Nov 2011 00:22:53 +0800 Subject: [PATCH] Switch create.cgi to output HTML instead of text to allow for better feedback --- README.markdown | 12 ++++++++---- create.cgi | 48 +++++++++++++++++++++++++++++++++--------------- fetch-tweets.sh | 2 +- grep.php | 2 +- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/README.markdown b/README.markdown index a0304d4..5064128 100644 --- a/README.markdown +++ b/README.markdown @@ -12,7 +12,13 @@ * Won't work on protected accounts (duh!) * No @mentions or DMs from other accounts -# Twitter can be flaky +## Fetching already! + +Closing a tab whilst creating an account, +, can cause issues. Need to study +. + +## Twitter can be flaky Twitter does not allow the possibility of retrieving more than 3200 tweets. However twitter generally stalls before coming close to this limit. Please @@ -23,8 +29,6 @@ to any already existing tweets. I did file , which later seemed to be fixed. -# Shell script feedback on the Web is unsolved :( +# Shell script feedback (progressive loading) on the Web is solved by outputing more than one should - -Could do with some help here to make shell scripts show nicely, like `tail` in a console. diff --git a/create.cgi b/create.cgi index 81596a3..ef8421b 100755 --- a/create.cgi +++ b/create.cgi @@ -1,11 +1,5 @@ #!/bin/bash -e # vim: set ts=4 sw=4 - -cat <&1 oldpwd=$PWD @@ -29,16 +23,32 @@ then test "${parm[3]}" && old=1 fi -# Trying to workaround: -# http://stackoverflow.com/questions/3547488/showing-a-long-running-shell-process-with-apache -# Maybe needs a bigger buffer ??? -figlet $id +cat < + + + + Fetching tweets of $id + + + + +

Greptweet is running a long operation to fetch upto 3200 tweets from $id

+ +

Please be patient. If you close this page prematurely you can limit the tweets fetch-tweets.sh gets and trigger a locking bug.

+ +
+END
+
+hash figlet 2>/dev/null && figlet $id
 
 if test -d u/$id
 then
 
 	echo Directory $id already exists
-	echo Visit http://greptweet.com/u/$id
 	echo Attempting an update
 
 	cd u/$id
@@ -48,18 +58,18 @@ then
 
 	if ! test -f lock
 	then
-		touch lock
+		touch lock # Bug here if tab is closed before it's finished
 		../../fetch-tweets.sh $id $old
-		rm lock
+		rm lock # We need to also clear to lock if fetch-tweets was killed by Apache
 	else
 		echo Fetching already!
 	fi
 
 else
 
-	if curl -I http://api.twitter.com/1/users/lookup.xml?screen_name=${id} | grep -q "Status: 404 Not Found"
+	if curl -sI http://api.twitter.com/1/users/lookup.xml?screen_name=${id} | grep -q "Status: 404 Not Found"
 	then
-		echo $id does not exist on twitter.com
+		echo "$id does not exist on twitter.com :("
 		exit
 	fi
 
@@ -85,3 +95,11 @@ fi
 test -s $oldpwd/u/$id/$id.txt || rm -rf $oldpwd/u/$id
 
 cd $oldpwd; ./users.sh > users.shtml
+
+cat <
+

Visit http://$HTTP_HOST/u/$id

+ + +END + diff --git a/fetch-tweets.sh b/fetch-tweets.sh index 4eaca5b..b9b4311 100755 --- a/fetch-tweets.sh +++ b/fetch-tweets.sh @@ -63,7 +63,7 @@ mv $temp2 $temp if test $(xmlstarlet sel -t -v "count(//statuses/status)" $temp) -eq 0 then - head $temp + head $temp | perl -MHTML::Entities -pe 'encode_entities($_)' if test "$2" && test "$since" then echo No old tweets ${since} diff --git a/grep.php b/grep.php index 2fd85fa..785dafa 100644 --- a/grep.php +++ b/grep.php @@ -1,4 +1,4 @@ -