coolestdude1
coolestdude1

Reputation: 65

Using curl to update mysql when curl spits out json

Ok a rather strange question here (or maybe not)

I am trying to pull tweets out of twitter using curl here is the command

curl http://stream.twitter.com/1/statuses/filter.json?track=XXhashtagXX -XXuserXX:XXpassXX

Every where there is an x that is a place for variables like twitter username and password and also the hashtag to look for.

And this is using the twitter restful api which alerts your script everytime a change was made.

In a console this curl command works perfectly but now i just need to take the output and save it to my mysql tables.

Any help would be greatly appreciated.

Upvotes: 1

Views: 1325

Answers (1)

josefnpat
josefnpat

Reputation: 58

IRL buddy. Here's what you want pretty much.

chmod a+x watch_twitter.sh ./watch_twitter.sh

or

sh watch_twitter.sh

watch_twitter.sh

#!/usr/bin/sh
nohup curl http://stream.twitter.com/1/statuses/filter.json?track=hashtag -uusername:password\!\! -o test.txt -N &
nohup php watch_test.php &
exit

watch_test.php

<?php
while(1){
        echo ".";
        $data = file_get_contents('test.txt');
        if($data){
                file_put_contents('test.txt',"");
                $dataarry = explode("\n",$data);
                foreach($dataarry as $data){
                        print_r(json_decode(trim($data)));
                }
                echo "FOUND SOMETHING!";
        }
        sleep(1);
}
print_r($data);
?>

Upvotes: 1

Related Questions