Permalink
Browse files

added a --force option to the phptwitterbot command line to force bot…

…s updates, added the recently introduced 'geo' property to the Tweet class
  • Loading branch information...
1 parent 319691d commit ff221a780552555b361661d3b4d3b9e6491b2fbd @n1k0 n1k0 committed Dec 15, 2009
@@ -5,8 +5,9 @@
$configFile = null;
$botName = null;
-$debug = false;
$cronLogsFile = null;
+$debug = false;
+$forceUpdate = false;
foreach (array_slice($argv, 1) as $argValue)
{
@@ -31,6 +32,10 @@
$debug = true;
break;
+ case 'force':
+ $forceUpdate = true;
+ break;
+
case 'help':
exit(help($argv[0]));
break;
@@ -53,7 +58,7 @@
try
{
- $farm = TwitterBotsFarm::create($configFile, $cronLogsFile, $debug);
+ $farm = TwitterBotsFarm::create($configFile, $cronLogsFile, $debug, $forceUpdate);
if (!is_null($botName))
{
View
@@ -14,6 +14,7 @@ class Tweet extends TwitterEntity
public
$created_at,
$id,
+ $geo,
$text,
$source,
$truncated,
@@ -17,7 +17,7 @@ public function createFromJSON($json)
{
throw new InvalidArgumentException('Unable to decode JSON response');
}
-
+
$tweetCollection = array();
foreach ($tweets['results'] as $tweetArray)
@@ -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':
@@ -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)));
@@ -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))
{
@@ -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))
@@ -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);
}
/**
@@ -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));

0 comments on commit ff221a7

Please sign in to comment.