-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnews.php
executable file
·64 lines (58 loc) · 1.42 KB
/
news.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
$newsdb = sqlite_open('./news.db',0777,$msg);
if (!$newsdb) die($msg);
require_once('config.php');
require_once('twitteroauth/twitteroauth.php');
function is_new($db,$id)
{
$sql = "select count(id) from news where id=$id";
$dbres = sqlite_query($db,$sql);
$num=sqlite_fetch_single($dbres);
if ($num == 0) return TRUE;
else return FALSE;
}
function splitURL($text)
{
$parts= preg_split("/[\s,]+/",$text);
for ($i=0 ; $i <= count($parts) ; $i++)
{
if (substr($parts[$i],0,7)=="http://")
{
$url=$parts[$i];
unset ($parts[$i]);
}
$realText=implode($parts,' ');
}
$ret=array("text"=>"$realText","url"=>$url);
return $ret;
}
function store($db,$t)
{
$sp=splitURL($t->text);
$text=sqlite_escape_string($sp["text"]);
$url=$sp["url"];
$date=strtotime($t->created_at);
$user=$t->user;
$user_id=$user->id_str;
$sql="insert into news (id,date,user_id,text,url) values ('$t->id_str','$date','$user_id','$text','$url')";
$ret=sqlite_exec($db,$sql,$message);
if (!$ret) print "$message\n";
return $ret;
}
function retweet($connection,$t)
{
return $connection->post('statuses/retweet/'.$t->id_str);
}
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$res=$connection->get('statuses/friends_timeline');
# print_r($newsdb,FALSE);die();
foreach($res as $t)
{
if (is_new($newsdb,$t->id_str))
{
if (retweet($connection,$t))
store($newsdb,$t);
//echo $t->text;
}
# break;
}