mirror of
https://github.com/thewesker/greptweet.git
synced 2025-12-22 13:01:06 -05:00
About to hack Oauth
This commit is contained in:
@@ -9,26 +9,13 @@ else
|
||||
mkdir lock
|
||||
fi
|
||||
|
||||
trap "rm -vrf $temp $temp2 lock; exit" EXIT
|
||||
trap "rm -vrf $temp $temp2 lock" EXIT
|
||||
|
||||
umask 002
|
||||
api="http://api.twitter.com/1/statuses/user_timeline.xml?"
|
||||
|
||||
if ! test "$1"
|
||||
then
|
||||
printf "Please specify twitter username\n e.g. %s kaihendry\n" $0
|
||||
exit 1
|
||||
fi
|
||||
|
||||
command -v xmlstarlet >/dev/null && xml() { xmlstarlet "$@"; }
|
||||
if ! type xml >/dev/null; then echo Please install http://xmlstar.sourceforge.net/; exit 1; fi
|
||||
|
||||
twitter_total=$(curl -s "http://api.twitter.com/1/users/lookup.xml?screen_name=$1" |
|
||||
xml sel -t -m "//users/user/statuses_count" -v .)
|
||||
|
||||
if ! test "$twitter_total" -gt 0 2>/dev/null
|
||||
then
|
||||
echo 'Twitter API not working' >&2
|
||||
printf "Please specify twitter username\ne.g. %s kaihendry\n" $0
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -46,81 +33,13 @@ echo T:"$twitter_total" S:"$saved"
|
||||
while test "$twitter_total" -gt "$saved" # Start of the important loop
|
||||
do
|
||||
|
||||
echo $1 tweet total "$twitter_total" is greater than the already saved "$saved"
|
||||
echo Trying to get $(($twitter_total - $saved))
|
||||
|
||||
temp=$(mktemp "$1.XXXX")
|
||||
temp2=$(mktemp "$1.XXXX")
|
||||
|
||||
url="${api}screen_name=${1}&count=200&page=${page}${since}&include_rts=1&trim_user=0&include_entities=1"
|
||||
|
||||
echo "curl -s \"$url\""
|
||||
curl -si "$url" | tee $temp2 > $temp
|
||||
echo $?
|
||||
|
||||
# keep only headers in $temp2
|
||||
ed -s $temp2 << "EOF_ED1"
|
||||
/^[[:space:]]*$/
|
||||
.,$d
|
||||
wq
|
||||
EOF_ED1
|
||||
|
||||
# keep only content in $temp
|
||||
ed -s $temp << "EOF_ED2"
|
||||
/^[[:space:]]*$/
|
||||
1,.d
|
||||
wq
|
||||
EOF_ED2
|
||||
url="screen_name=${1}&count=200&page=${page}${since}&include_rts=1&trim_user=0&include_entities=1"
|
||||
|
||||
|
||||
grep -iE 'rate|status' $temp2 # show the interesting twitter rate limits
|
||||
|
||||
if test "$(xml sel -t -v "count(//statuses/status)" $temp 2>/dev/null)" -eq 0
|
||||
then
|
||||
head $temp | grep -q "Over capacity" && echo "Twitter is OVER CAPACITY"
|
||||
if test "$2" && test "$since"
|
||||
then
|
||||
echo No old tweets ${since}
|
||||
elif test "$since"
|
||||
then
|
||||
echo No new tweets ${since}
|
||||
else
|
||||
echo "Twitter is returning empty responses on page ${page} :("
|
||||
fi
|
||||
rm -f $temp $temp2
|
||||
exit
|
||||
fi
|
||||
|
||||
xml sel -t -m "statuses/status" -n -o "text " -v "id" -o "|" -v "created_at" -o "|" \
|
||||
-m ".|retweeted_status" -i "(name() = 'status' and not(retweeted_status)) or name() = 'retweeted_status'" \
|
||||
-i "name() = 'retweeted_status'" -o "RT @" -v "user/screen_name" -o ": " -b \
|
||||
-v "normalize-space(text)" \
|
||||
-m "entities/urls/url" -i "expanded_url != ''" -n -o "url " -v "url" -o " " -v "expanded_url" -b -b \
|
||||
-m "entities/media/creative" -i "expanded_url != ''" -n -o "url " -v "url" -o " " -v "expanded_url" -b -b \
|
||||
$temp |
|
||||
{
|
||||
while read -r first rest
|
||||
while curl -f -s ./oauth.php $url | json -d '|' -a id created_at text > temp2; test $(wc -l < temp2) -gt 0;
|
||||
do
|
||||
case $first in
|
||||
"text") echo "$text"; text="$rest" ;;
|
||||
"url")
|
||||
set -- $(echo $rest)
|
||||
text=${text//"$1"/$2} # BASHism #11
|
||||
;;
|
||||
esac
|
||||
done
|
||||
echo "$text"
|
||||
} > $temp2
|
||||
|
||||
perl -MHTML::Entities -pe 'decode_entities($_)' < $temp2 > $temp
|
||||
sed '/^$/d' < $temp > $temp2
|
||||
|
||||
if test -z $temp2
|
||||
then
|
||||
echo $temp2 is empty
|
||||
rm -f $temp $temp2
|
||||
continue
|
||||
fi
|
||||
cat temp2
|
||||
|
||||
if test -f $1.txt
|
||||
then
|
||||
|
||||
8
oauth.php
Normal file → Executable file
8
oauth.php
Normal file → Executable file
@@ -1,3 +1,4 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
function buildBaseString($baseURI, $method, $params) {
|
||||
@@ -30,7 +31,7 @@ $oauth = array( 'oauth_consumer_key' => $consumer_key,
|
||||
'oauth_timestamp' => time(),
|
||||
'screen_name' => 'kaihendry',
|
||||
'count' => 200,
|
||||
'max_id' => 292551485714227200,
|
||||
'page' => $argv[1],
|
||||
'oauth_version' => '1.0');
|
||||
|
||||
$base_info = buildBaseString($url, 'GET', $oauth);
|
||||
@@ -43,7 +44,7 @@ $header = array(buildAuthorizationHeader($oauth), 'Expect:');
|
||||
$options = array( CURLOPT_HTTPHEADER => $header,
|
||||
//CURLOPT_POSTFIELDS => $postfields,
|
||||
CURLOPT_HEADER => false,
|
||||
CURLOPT_URL => $url . '?screen_name=kaihendry&count=200&max_id=292551485714227200',
|
||||
CURLOPT_URL => $url . '?screen_name=kaihendry&count=200&page=' . $argv[1],
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_SSL_VERIFYPEER => false);
|
||||
|
||||
@@ -52,6 +53,9 @@ curl_setopt_array($feed, $options);
|
||||
$json = curl_exec($feed);
|
||||
curl_close($feed);
|
||||
|
||||
// No results returned, Twitter API issue
|
||||
if (strlen($json) == 2) { exit(1); };
|
||||
|
||||
echo $json;
|
||||
// $twitter_data = json_decode($json);
|
||||
// print_r ($twitter_data);
|
||||
|
||||
Reference in New Issue
Block a user