Skip to content
This repository has been archived by the owner on Dec 10, 2017. It is now read-only.

Commit

Permalink
added a --force option to the phptwitterbot command line to force bot…
Browse files Browse the repository at this point in the history
…s updates, added the recently introduced 'geo' property to the Tweet class
  • Loading branch information
n1k0 committed Dec 15, 2009
1 parent 319691d commit ff221a7
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 11 deletions.
9 changes: 7 additions & 2 deletions bin/phptwitterbot.php
Expand Up @@ -5,8 +5,9 @@

$configFile = null;
$botName = null;
$debug = false;
$cronLogsFile = null;
$debug = false;
$forceUpdate = false;

foreach (array_slice($argv, 1) as $argValue)
{
Expand All @@ -31,6 +32,10 @@
$debug = true;
break;

case 'force':
$forceUpdate = true;
break;

case 'help':
exit(help($argv[0]));
break;
Expand All @@ -53,7 +58,7 @@

try
{
$farm = TwitterBotsFarm::create($configFile, $cronLogsFile, $debug);
$farm = TwitterBotsFarm::create($configFile, $cronLogsFile, $debug, $forceUpdate);

if (!is_null($botName))
{
Expand Down
1 change: 1 addition & 0 deletions lib/Tweet.class.php
Expand Up @@ -14,6 +14,7 @@ class Tweet extends TwitterEntity
public
$created_at,
$id,
$geo,
$text,
$source,
$truncated,
Expand Down
2 changes: 1 addition & 1 deletion lib/TweetCollection.class.php
Expand Up @@ -17,7 +17,7 @@ public function createFromJSON($json)
{
throw new InvalidArgumentException('Unable to decode JSON response');
}

$tweetCollection = array();

foreach ($tweets['results'] as $tweetArray)
Expand Down
2 changes: 1 addition & 1 deletion lib/TwitterApiClient.class.php
Expand Up @@ -62,7 +62,7 @@ public function __construct(TwitterApiServer $server = null, $debug = false)
protected function doCall($url, $parameters = array(), $authenticate = false, $usePost = true, $type = 'entity')
{
$response = $this->server->request(sprintf('%s.xml', $url), $parameters, $usePost ? 'POST' : 'GET');

switch ($type)
{
case 'entity':
Expand Down
2 changes: 1 addition & 1 deletion lib/TwitterBot.class.php
Expand Up @@ -364,7 +364,7 @@ public function searchAndRetweet($terms, array $options = array())
}

$message = null;

$entries = $this->client->search($terms, array('source' => $options['source']));

$this->debug(sprintf('Found %d results', count($entries)));
Expand Down
20 changes: 14 additions & 6 deletions lib/TwitterBotsFarm.class.php
Expand Up @@ -37,20 +37,22 @@ class TwitterBotsFarm

protected
$config = array(),
$debug = false,
$cronLogs = array(),
$cronLogsFile = null;
$cronLogsFile = null,
$debug = false,
$forceUpdate = false;

/**
* Constructor
*
* @param string $configFile Absolute path to the yaml configuration file
* @param string $cronLogsFile Absolute path to the cronLogs file (optional)
* @param Boolean $debug Enables debug mode
* @param Boolean $forceUpdate Forces updates
*
* @throws InvalidArgumentException if path to file doesn't exist or is invalid
*/
public function __construct($configFile, $cronLogsFile = null, $debug = false)
public function __construct($configFile, $cronLogsFile = null, $debug = false, $forceUpdate = false)
{
if (!file_exists($configFile) || !is_file($configFile))
{
Expand All @@ -68,6 +70,11 @@ public function __construct($configFile, $cronLogsFile = null, $debug = false)

$this->debug = $this->getGlobalConfigValue('debug', $debug);

if (true === $this->forceUpdate = $forceUpdate)
{
$this->debug('Forcing updates');
}

$this->debug(sprintf('Creating farm from config file "%s"', $configFile));

if (!is_null($cronLogsFile))
Expand All @@ -86,12 +93,13 @@ public function __construct($configFile, $cronLogsFile = null, $debug = false)
* @param string $configFile Absolute path to the yaml configuration file
* @param string $cronLogsFile Absolute path to the cronLogs file (optional)
* @param Boolean $debug Enables debug mode
* @param Boolean $forceUpdate Forces updates
*
* @throws InvalidArgumentException if path to file doesn't exist or is invalid
*/
static public function create($configFile, $cronLogsFile = null, $debug = false)
static public function create($configFile, $cronLogsFile = null, $debug = false, $forceUpdate = false)
{
return new TwitterBotsFarm($configFile, $cronLogsFile, $debug);
return new TwitterBotsFarm($configFile, $cronLogsFile, $debug, $forceUpdate);
}

/**
Expand Down Expand Up @@ -306,7 +314,7 @@ public function runBot($name, array $config = null)
}

// Periodicity Check
if (isset($methodConfig['periodicity']) && !$this->isBotOperationExpired($name, $method, (int) $methodConfig['periodicity']))
if (!$this->forceUpdate && (isset($methodConfig['periodicity']) && !$this->isBotOperationExpired($name, $method, (int) $methodConfig['periodicity'])))
{
$this->debug(sprintf('Operation "%s" of bot "%s" is not expired, skipping', $method, $name));

Expand Down

0 comments on commit ff221a7

Please sign in to comment.