Basically working, now I need to resolve some jsontool wranglings

This commit is contained in:
Kai Hendry
2013-02-09 15:34:33 +08:00
parent a38709d76a
commit 4a13e5abc3
2 changed files with 16 additions and 22 deletions

View File

@@ -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

View File

@@ -1,6 +1,11 @@
#!/usr/bin/php
#!/usr/bin/env php
<?php
if (empty($argv[1])) { exit(1); }
$urlargs = $argv[1];
parse_str($urlargs, $merge_to_oauth);
function buildBaseString($baseURI, $method, $params) {
$r = array();
ksort($params);
@@ -29,11 +34,10 @@ $oauth = array( 'oauth_consumer_key' => $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);