From 4a13e5abc3433ad8f1dd53b89d906ff2a694d905 Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Sat, 9 Feb 2013 15:34:33 +0800 Subject: [PATCH] Basically working, now I need to resolve some jsontool wranglings --- fetch-tweets.sh | 24 +++++++----------------- oauth.php | 14 +++++++++----- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/fetch-tweets.sh b/fetch-tweets.sh index 8a77c4c..1c34be0 100755 --- a/fetch-tweets.sh +++ b/fetch-tweets.sh @@ -9,6 +9,9 @@ else mkdir lock fi +temp=$(mktemp "$1.XXXX") +temp2=$(mktemp "$1.XXXX") + trap "rm -vrf $temp $temp2 lock" EXIT umask 002 @@ -29,17 +32,10 @@ then test "$2" && since='&max_id='$(tail -n1 $1.txt | cut -d'|' -f1) # use max_id to get older tweets fi -echo T:"$twitter_total" S:"$saved" -while test "$twitter_total" -gt "$saved" # Start of the important loop +while urlargs="screen_name=${1}&count=200&page=${page}${since}&include_rts=1&trim_user=0&include_entities=1"; echo $urlargs; ./oauth.php $urlargs | json -d '|' -a id created_at text > $temp2; test $(wc -l < $temp2) -gt 0; do -url="screen_name=${1}&count=200&page=${page}${since}&include_rts=1&trim_user=0&include_entities=1" - - -while curl -f -s ./oauth.php $url | json -d '|' -a id created_at text > temp2; test $(wc -l < temp2) -gt 0; -do - -cat temp2 +#cat temp2 if test -f $1.txt then @@ -54,18 +50,12 @@ sort -r -n -u $temp $temp2 > "$1.txt" rm -f $temp $temp2 after=$(wc -l < "$1.txt") -echo Before: $before After: $after -if test "$before" -eq "$after" -then - echo Unable to retrieve anything new. Approximately $(( $twitter_total - $after)) missing tweets - exit -fi +echo Before: $before After: $after page=$(($page + 1)) saved=$(wc -l < "$1.txt") -echo $saved done -echo $1 saved $saved tweets of "$twitter_total": You are up-to-date! +echo $1 saved $saved tweets diff --git a/oauth.php b/oauth.php index 0a9d978..4ef2f11 100755 --- a/oauth.php +++ b/oauth.php @@ -1,6 +1,11 @@ -#!/usr/bin/php +#!/usr/bin/env php $consumer_key, 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $oauth_access_token, 'oauth_timestamp' => time(), - 'screen_name' => 'kaihendry', - 'count' => 200, - 'page' => $argv[1], 'oauth_version' => '1.0'); +$oauth = array_merge($oauth, $merge_to_oauth); + $base_info = buildBaseString($url, 'GET', $oauth); $composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret); $oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true)); @@ -44,7 +48,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&page=' . $argv[1], + CURLOPT_URL => $url . '?'. $urlargs, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);