-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashtag_retweet.php
executable file
·55 lines (40 loc) · 1.27 KB
/
hashtag_retweet.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
<?php
require_once('twitteroauth/twitteroauth.php');
require_once('config.php');
require_once('database.php');
$conn = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
try {
$dbh = new PDO("sqlite:database.sdb");
} catch(PDOException $e) {
echo $e->getMessage();
}
$blacklist = $conn->get("https://api.twitter.com/1/lists/members.json?slug=".BLACKLIST."&owner_screen_name=".USER."&cursor=-1");
retweet_hashtag(HASHTAG, 1);
function in_black_list($uid) {
global $blacklist;
foreach($blacklist->users as $user) {
if ($user->id === $uid) {
return true;
}
}
return false;
}
function retweet_hashtag($name, $num=10) {
global $conn, $dbh;
$search = $conn->get("http://search.twitter.com/search.json?q=%23{$name}&result_type=recent&rpp=100&page=1");
$chronological = array_reverse($search->results, true);
foreach($chronological as $item) {
if ($item->from_user == USER OR
tweet_retweeted($item->id) OR
in_black_list($item->from_user_id)) {
continue;
}
echo "Retweeting " . $item->id . "\n";
$conn->post('http://api.twitter.com/1.1/statuses/retweet/'.$item->id.'.json');
save_tweet($item->id);
if (--$num <= 0) {
break;
}
}
}
?>