2013-02-24 14:16:57 -05:00
|
|
|
<?php
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
require 'vendor/twilio/sdk/Services/Twilio.php';
|
|
|
|
|
|
|
|
use Symfony\Component\Yaml\Yaml;
|
2013-03-04 19:27:42 -05:00
|
|
|
|
2013-02-26 17:27:12 -05:00
|
|
|
$crontab = new \HybridLogic\Cron\Crontab;
|
2013-02-24 14:16:57 -05:00
|
|
|
|
2013-03-04 19:27:42 -05:00
|
|
|
$db = new PDO('sqlite:db/songcaller.db');
|
|
|
|
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
|
|
|
|
$settings = Yaml::parse('conf/settings.yml');
|
2013-02-24 14:16:57 -05:00
|
|
|
$client = new Services_Twilio(
|
|
|
|
$settings['twilio']['sid'],
|
|
|
|
$settings['twilio']['token']
|
|
|
|
);
|
|
|
|
|
2013-03-05 11:37:28 -05:00
|
|
|
$result = $db->query('SELECT id, schedule, phone FROM calls');
|
2013-02-26 17:27:12 -05:00
|
|
|
|
2013-03-04 19:27:42 -05:00
|
|
|
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'],
|
2013-03-05 11:37:28 -05:00
|
|
|
$settings['application']['generator'] . '?id=' . $row['id']
|
2013-03-04 19:27:42 -05:00
|
|
|
);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
2013-02-26 17:27:12 -05:00
|
|
|
|
|
|
|
$crontab->run();
|
2013-03-04 19:27:42 -05:00
|
|
|
|
|
|
|
$db = null;
|