-
Notifications
You must be signed in to change notification settings - Fork 53
/
collect.php
67 lines (48 loc) · 1.77 KB
/
collect.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
<?php namespace OpenFuego;
/** This script connects to the Twitter stream
* and captures raw data into a queue for processing.
**/
use OpenFuego\app\Universe as Universe;
use OpenFuego\app\Collector as Collector;
use OpenFuego\lib\Logger as Logger;
use OpenFuego\lib\TwitterHandle as TwitterHandle;
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) {
die(__NAMESPACE__ . ' requires PHP 5.3.0 or higher.');
}
if (php_sapi_name() != 'cli') {
die('This script must be invoked from the command line.');
}
if (!defined('OPENFUEGO') && function_exists('pcntl_fork')) {
$error_message = "\n"
. 'Do not run this script directly. Run fetch.php to start.'
. "\n\n";
die($error_message);
}
require_once(__DIR__ . '/init.php');
register_shutdown_function(function() {
Logger::fatal(__NAMESPACE__ . " collector was terminated.");
});
$twitter = new TwitterHandle();
$twitter->get("account/verify_credentials", array("include_entities" => 0, "skip_status" => 1));
if ($twitter->http_code !== 200) {
$error_message = "Cannot continue. Your Twitter credentials appear to be invalid. Error code {$twitter->http_code}";
Logger::info($error_message);
die($error_message);
}
unset($twitter_handle);
$authorities = unserialize(\OpenFuego\AUTHORITIES);
$universe = new Universe();
/** The next line is commented out by default.
* Uncomment it to repopulate the universe on each fetch. */
// $universe->populate($authorities, 1);
$citizens = $universe->getCitizens(1);
if (!$citizens) {
$universe->populate($authorities, 1);
$citizens = $universe->getCitizens(1);
}
$citizens = array_slice($citizens, 0, TWITTER_PREDICATE_LIMIT);
// Start streaming/collecting
$collector = new Collector(TWITTER_OAUTH_TOKEN, TWITTER_OAUTH_SECRET);
$collector->setFollow($citizens);
$collector->consume();
exit;