Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 113 lines (84 sloc) 2.994 kb
c85be22 @jk init
authored
1 #!/usr/bin/php
2 <?php
0001df3 @jk README überarbeitet, Avatar-Hinweis geschrieben
authored
3 require_once('config.php');
4
618b9cf @jk Einige Bugs in getFollower.php behoben
authored
5 define('USERDIR', DIR.'/'.strtolower(USER));
6
7 if (!file_exists(USERDIR)) {
f2d04f7 @jk Noch ein paar Bugs gefixt. Diese Version funktioniert nun auch auf de…
authored
8 mkdir(USERDIR, 0755);
0001df3 @jk README überarbeitet, Avatar-Hinweis geschrieben
authored
9 }
c85be22 @jk init
authored
10
1fa0edf @jk Schutz vor fehlerhaften Daten von Twitter
authored
11 $yesterday = strftime("%Y%m%d", strtotime('-1 day', mktime()));
12
13 $fileYesterday = USERDIR.'/'.$yesterday.'_'.strtolower(USER).".txt";
618b9cf @jk Einige Bugs in getFollower.php behoben
authored
14 $filename = USERDIR.'/'.strftime("%Y%m%d").'_'.strtolower(USER).".txt";
1fa0edf @jk Schutz vor fehlerhaften Daten von Twitter
authored
15
618b9cf @jk Einige Bugs in getFollower.php behoben
authored
16 if (file_exists($filename)) {
c85be22 @jk init
authored
17 exit($filename.' already exists.'."\n");
18 }
19
1fa0edf @jk Schutz vor fehlerhaften Daten von Twitter
authored
20 define('FLAG_YESTERDAY_EXISTS', file_exists($fileYesterday));
21
22 $countYesterday = 0;
23 if (FLAG_YESTERDAY_EXISTS)
24 $countYesterday = count(explode("\n", file_get_contents($fileYesterday)));
25
c85be22 @jk init
authored
26 // Twitter
27 define('USER_URL', 'http://twitter.com/users/show/'.USER.'.xml');
28 define('FOLLOWER_URL', 'http://twitter.com/statuses/followers.xml');
29 $curl = curl_init();
30 curl_setopt($curl, CURLOPT_URL, USER_URL);
31 curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
32 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
33 curl_setopt($curl, CURLOPT_POST, 0);
34 curl_setopt($curl, CURLOPT_USERPWD, USER.':'.PASSWD);
35
36 function parse($xml) {
37 $users = array();
38
39 foreach($xml->user as $user) {
40 $out['id'] = (int)$user->id;
41 $out['screen_name'] = (string)$user->screen_name;
42 $out['name'] = (string)$user->name;
43 $out['follower'] = (int)$user->followers_count;
44
45 $users[] = array('datetime' => DATETIME, 'user' => $out);
46 }
47
48 return $users;
49 }
50
51 function printList($arr) {
52 if (count($arr) == 0)
53 return;
54
55 foreach($arr as $user)
56 $o[] = strtolower($user['user']['screen_name']);
57 sort($o);
58
59 foreach($o as $user)
60 $out .= $user.", ";
61
62 echo "(".count($arr)."): " . substr($out, 0, strlen($out)-2)."\n";
63 }
64
65 #curl_setopt($curl, CURLOPT_POSTFIELDS, "status=".$msg);
66 $buffer = curl_exec($curl);
67 $xml = simplexml_load_string($buffer);
68
aabb4af Durch die Unerreichbarkeit habe ich noch nen Fehler festgestellt. Der…
Jens Kohl authored
69 if (strlen($buffer) < 10) {
70 echo "User-Data downloaded from Twitter was too short, so the local copy, if it exists, isn't replaced.\n";
71 } else {
72 file_put_contents(DIR.'/'.strtolower(USER).'.xml', $buffer);
73 }
1b4da08 @jk getFollower.php holt sich jetzt auch die aktuellen Userinfos und spei…
authored
74
c85be22 @jk init
authored
75 $follower = $xml->followers_count;
76 $friends = $xml->friends_count;
77 $updates = $xml->statuses_count;
78 $created = strtotime($xml->created_at);
79 $days = floor((mktime()-$created)/(60*60*24));
80 $pages = ceil($follower / 100);
81 $score = ($follower / $friends) * 1 / ($updates / $days);
82
83 $arrFollower = array();
84 for($i = 1; $i <= $pages; $i++) {
85 curl_setopt($curl, CURLOPT_URL, FOLLOWER_URL.'?page='.$i);
86 $xml = simplexml_load_string(curl_exec($curl));
87
88 $append = parse($xml);
89 $arrFollower = array_merge($arrFollower, $append);
90 }
91
92 curl_close($curl);
93
94 // Save
95 foreach($arrFollower as $user)
96 $o[] = strtolower($user['user']['screen_name']);
97
0001df3 @jk README überarbeitet, Avatar-Hinweis geschrieben
authored
98 if (count($o) < 1) {
618b9cf @jk Einige Bugs in getFollower.php behoben
authored
99 exit("No followers were found. That's unlikey so that no file was created.\n");
1fa0edf @jk Schutz vor fehlerhaften Daten von Twitter
authored
100 } elseif (FLAG_YESTERDAY_EXISTS && ($countYesterday * 0.8 >= count($o))) {
101 exit("More than a 20% follower lost opposed to yesterday. It's very likely that a dataloss occured.");
0001df3 @jk README überarbeitet, Avatar-Hinweis geschrieben
authored
102 }
103
c85be22 @jk init
authored
104 sort($o);
105
106 $out = implode("\n", $o);
107
108 file_put_contents($filename, $out);
109 echo $out;
110
111 #printList($arrFollower);
112 ?>
Something went wrong with that request. Please try again.