mirror of
https://github.com/thewesker/greptweet.git
synced 2025-12-22 21:11:06 -05:00
Made xmlstarlet finding code hopefully more POSIX
http://mywiki.wooledge.org/BashFAQ/081
This commit is contained in:
@@ -6,6 +6,7 @@ Cache-Control: no-cache
|
|||||||
Content-Type: text/html
|
Content-Type: text/html
|
||||||
|
|
||||||
END
|
END
|
||||||
|
|
||||||
badinput() {
|
badinput() {
|
||||||
echo "<h1>Bad input, parameter id $@</h1>"
|
echo "<h1>Bad input, parameter id $@</h1>"
|
||||||
exit
|
exit
|
||||||
@@ -57,15 +58,14 @@ then
|
|||||||
echo Attempting an update
|
echo Attempting an update
|
||||||
else
|
else
|
||||||
|
|
||||||
if curl -sI http://api.twitter.com/1/users/lookup.xml?screen_name=${id} |
|
if curl -sI http://api.twitter.com/1/users/lookup.xml?screen_name=${id} |
|
||||||
grep -q "Status: 404 Not Found"
|
grep -q "Status: 404 Not Found"
|
||||||
then
|
then
|
||||||
echo "$id does not exist on twitter.com :("
|
echo "$id does not exist on twitter.com :("
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo Need to create u/$id
|
mkdir -p u/$id
|
||||||
mkdir u/$id
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -10,14 +10,12 @@ then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# xmlstarlet is often just xml
|
command -v xmlstarlet >/dev/null && XMLSTARLET=xmlstarlet
|
||||||
if which xmlstarlet >> /dev/null; then
|
command -v xml >/dev/null && XMLSTARLET=xml
|
||||||
XMLSTARLET=xmlstarled
|
if ! test $XMLSTARLET
|
||||||
elif which xml >> /dev/null; then
|
then
|
||||||
XMLSTARLET=xml
|
echo "xmlstarlet not found :("
|
||||||
else
|
exit 1
|
||||||
echo "xmlstarlet not found :("
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
twitter_total=$(curl -s "http://api.twitter.com/1/users/lookup.xml?screen_name=$1" |
|
twitter_total=$(curl -s "http://api.twitter.com/1/users/lookup.xml?screen_name=$1" |
|
||||||
@@ -98,14 +96,14 @@ do
|
|||||||
case $first in
|
case $first in
|
||||||
"text") echo "$text"; text="$rest" ;;
|
"text") echo "$text"; text="$rest" ;;
|
||||||
"url")
|
"url")
|
||||||
set -- $(echo $rest)
|
set -- $(echo $rest)
|
||||||
finUrl=$2
|
finUrl=$2
|
||||||
domain=$(echo $finUrl | cut -d'/' -f3)
|
domain=$(echo $finUrl | cut -d'/' -f3)
|
||||||
if [ "$shortDomains" = *$domain* ]
|
if echo $shortDomains | grep -q $domain # TODO might match greedily, e.g. with t.co
|
||||||
then
|
then
|
||||||
finUrl=$(curl "$finUrl" -s -L -I -o /dev/null -w '%{url_effective}')
|
finUrl=$(curl "$finUrl" -s -L -I -o /dev/null -w '%{url_effective}')
|
||||||
fi
|
fi
|
||||||
text=$(echo $text | sed s,$1,$finUrl,g)
|
text=$(echo $text | sed s,$1,$finUrl,g)
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|||||||
5
grep.php
5
grep.php
@@ -1,10 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
header('Content-type: application/json');
|
header('Content-type: application/json');
|
||||||
if (empty($_GET['q'])) { die(); }
|
if (empty($_GET['q'])) { die(); }
|
||||||
|
|
||||||
|
// Is this the correct way to sanitise args to shell from PHP?
|
||||||
$QUERY=urldecode(escapeshellarg(urlencode($_GET['q'])));
|
$QUERY=urldecode(escapeshellarg(urlencode($_GET['q'])));
|
||||||
|
|
||||||
|
// Debug Logging
|
||||||
//$fp = fopen('debug.log', 'a');
|
//$fp = fopen('debug.log', 'a');
|
||||||
//fwrite($fp, $_GET['q'] . " : " . $QUERY . "\n");
|
//fwrite($fp, $_GET['q'] . " : " . $QUERY . "\n");
|
||||||
//fclose($fp);
|
//fclose($fp);
|
||||||
|
|
||||||
exec("grep -hi $QUERY *.txt", $array);
|
exec("grep -hi $QUERY *.txt", $array);
|
||||||
$data = json_encode($array);
|
$data = json_encode($array);
|
||||||
echo $_GET['jsoncallback'] . '(' . $data . ');';
|
echo $_GET['jsoncallback'] . '(' . $data . ');';
|
||||||
|
|||||||
Reference in New Issue
Block a user