This repository was archived by the owner on Feb 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtwitstash.php
54 lines (43 loc) · 1.61 KB
/
twitstash.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
<?php
/**
* twitstash: Tweetin' care of business and stashing overtime.
*
* @author Scott Smitelli
* @package twitstash
*/
// Support autoloading classes as they are needed
define('APP_DIR', realpath(dirname(__FILE__)));
spl_autoload_register(function($class_name) {
$class_file = sprintf(APP_DIR . "/classes/{$class_name}.class.php");
if (is_readable($class_file)) {
// File exists; load it
require_once $class_file;
}
});
// Load and parse the configuration file
$config = @parse_ini_file(APP_DIR . '/config.ini', TRUE);
if (empty($config)) {
die("The file config.ini is missing or malformed.\n\n");
}
date_default_timezone_set($config['misc']['timezone']);
// These classes do all the gruntwork for this script
$twitter = new TwitterScraper($config['twitter']);
$database = new DBModel($config['mysql']);
// Ensure the DB is in a good state; find the most recently stored ID
$database->resetTouched();
$stop_at = $database->getHighID();
// Go through every "page" of API results
$page = 0;
while ($tweets = $twitter->fetchTimeline()) {
echo 'Reading page ' . (++$page) . "...\n";
$database->insertTweets($tweets);
// If we've seen an ID that the DB already has, stop making requests
if ($twitter->getLowID() < $stop_at) break;
}
// Mark tweets that have "gone away" as being deleted
$database->deleteUntouchedSince($twitter->getLowID());
// Send all places and URLs seen during API parsing to the DB
$database->insertPlaces($twitter->getPlaceCache());
$database->insertURLs($twitter->getURLCache());
echo "Done.\n";
?>