/
getFollower.php
executable file
·96 lines (72 loc) · 2.29 KB
/
getFollower.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/php
<?php
require_once('config.php');
define('USERDIR', DIR.'/'.strtolower(USER));
if (!file_exists(USERDIR)) {
mkdir(USERDIR, 0755);
}
$filename = USERDIR.'/'.strftime("%Y%m%d").'_'.strtolower(USER).".txt";
if (file_exists($filename)) {
exit($filename.' already exists.'."\n");
}
// Twitter
define('USER_URL', 'http://twitter.com/users/show/'.USER.'.xml');
define('FOLLOWER_URL', 'http://twitter.com/statuses/followers.xml');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, USER_URL);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 0);
curl_setopt($curl, CURLOPT_USERPWD, USER.':'.PASSWD);
function parse($xml) {
$users = array();
foreach($xml->user as $user) {
$out['id'] = (int)$user->id;
$out['screen_name'] = (string)$user->screen_name;
$out['name'] = (string)$user->name;
$out['follower'] = (int)$user->followers_count;
$users[] = array('datetime' => DATETIME, 'user' => $out);
}
return $users;
}
function printList($arr) {
if (count($arr) == 0)
return;
foreach($arr as $user)
$o[] = strtolower($user['user']['screen_name']);
sort($o);
foreach($o as $user)
$out .= $user.", ";
echo "(".count($arr)."): " . substr($out, 0, strlen($out)-2)."\n";
}
#curl_setopt($curl, CURLOPT_POSTFIELDS, "status=".$msg);
$buffer = curl_exec($curl);
$xml = simplexml_load_string($buffer);
file_put_contents(DIR.'/'.strtolower(USER).'.xml', $buffer);
$follower = $xml->followers_count;
$friends = $xml->friends_count;
$updates = $xml->statuses_count;
$created = strtotime($xml->created_at);
$days = floor((mktime()-$created)/(60*60*24));
$pages = ceil($follower / 100);
$score = ($follower / $friends) * 1 / ($updates / $days);
$arrFollower = array();
for($i = 1; $i <= $pages; $i++) {
curl_setopt($curl, CURLOPT_URL, FOLLOWER_URL.'?page='.$i);
$xml = simplexml_load_string(curl_exec($curl));
$append = parse($xml);
$arrFollower = array_merge($arrFollower, $append);
}
curl_close($curl);
// Save
foreach($arrFollower as $user)
$o[] = strtolower($user['user']['screen_name']);
if (count($o) < 1) {
exit("No followers were found. That's unlikey so that no file was created.\n");
}
sort($o);
$out = implode("\n", $o);
file_put_contents($filename, $out);
echo $out;
#printList($arrFollower);
?>