diff --git a/add-call.php b/add-call.php new file mode 100644 index 0000000..dbd69aa --- /dev/null +++ b/add-call.php @@ -0,0 +1,34 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); +} catch(PDOException $e) { + die("PDOException (connect): " . $e->getMessage() . "\n"); +} +try { + $db->exec("INSERT INTO calls (phone, schedule, xml) VALUES($phone, '$schedule', '$xml')"); +} catch(PDOException $e) { + die("PDOException (query): " . $e->getMessage() . "\n"); +} +echo "Successfully added call.\n"; \ No newline at end of file diff --git a/caller.php b/caller.php index ca12ca2..c945039 100644 --- a/caller.php +++ b/caller.php @@ -3,26 +3,34 @@ require 'vendor/autoload.php'; require 'vendor/twilio/sdk/Services/Twilio.php'; use Symfony\Component\Yaml\Yaml; + $crontab = new \HybridLogic\Cron\Crontab; -$settings = Yaml::parse('conf/settings.yaml'); +$db = new PDO('sqlite:db/songcaller.db'); +$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + +$settings = Yaml::parse('conf/settings.yml'); $client = new Services_Twilio( $settings['twilio']['sid'], $settings['twilio']['token'] ); +$result = $db->query('SELECT * FROM calls'); - -$crontab->add_job( - \HybridLogic\Cron\Job::factory('test') - ->on('0 10-16 * * *') - ->trigger(function() use($settings, $client) { - $call = $client->account->calls->create( - $settings['application']['from'], - $settings['application']['to'], - $settings['application']['xml'] - ); - }) -); +foreach($result as $row) { + $crontab->add_job( + \HybridLogic\Cron\Job::factory('test') + ->on($row['schedule']) + ->trigger(function() use($settings, $client, $row) { + $call = $client->account->calls->create( + $settings['application']['from'], + $row['phone'], + $row['xml'] + ); + }) + ); +} $crontab->run(); + +$db = null; diff --git a/create-table.php b/create-table.php new file mode 100644 index 0000000..527839b --- /dev/null +++ b/create-table.php @@ -0,0 +1,10 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + + $db->exec('create table calls ( + id integer PRIMARY KEY, + phone integer, + schedule varchar(50), + xml varchar(255) + );');