Automatically Generate XML Files
Implement xml-generator.php that will automatically generate XML files from the database based on an ID passed in a get query. This allows new calls to be added using new MP3s without having to create a new XML file by hand everytime. This is the first step to a full web implementation.
This commit is contained in:
parent
e2563a973f
commit
b7fb4c8ced
6 changed files with 31 additions and 13 deletions
10
add-call.php
10
add-call.php
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
if(count($argv) != 4) {
|
||||
die("Usage: php ./add-call 15555555555 '* * * * *' http://domain.com/file.xml\n");
|
||||
die("Usage: php ./add-call 15555555555 '* * * * *' http://domain.com/file.mp3\n");
|
||||
}
|
||||
|
||||
$phone = $argv[1];
|
||||
$schedule = $argv[2];
|
||||
$xml = $argv[3];
|
||||
$mp3 = $argv[3];
|
||||
|
||||
if(preg_match('/^\d{11}$/', $phone) != 1) {
|
||||
die("Phone should be all numbers with no symbols. ex: 15555555555\n");
|
||||
|
@ -16,8 +16,8 @@ if(count(split(' ', $schedule)) != 5) {
|
|||
die("Schedule requires a properly formed cron schedule.\n");
|
||||
}
|
||||
|
||||
if(!filter_var($xml, FILTER_VALIDATE_URL)) {
|
||||
die("XML must be a vaild url.\n");
|
||||
if(!filter_var($mp3, FILTER_VALIDATE_URL)) {
|
||||
die("MP3 must be a vaild url.\n");
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -27,7 +27,7 @@ try {
|
|||
die("PDOException (connect): " . $e->getMessage() . "\n");
|
||||
}
|
||||
try {
|
||||
$db->exec("INSERT INTO calls (phone, schedule, xml) VALUES($phone, '$schedule', '$xml')");
|
||||
$db->exec("INSERT INTO calls (phone, schedule, mp3) VALUES($phone, '$schedule', '$mp3')");
|
||||
} catch(PDOException $e) {
|
||||
die("PDOException (query): " . $e->getMessage() . "\n");
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ $client = new Services_Twilio(
|
|||
$settings['twilio']['token']
|
||||
);
|
||||
|
||||
$result = $db->query('SELECT * FROM calls');
|
||||
$result = $db->query('SELECT id, schedule, phone FROM calls');
|
||||
|
||||
foreach($result as $row) {
|
||||
$crontab->add_job(
|
||||
|
@ -25,7 +25,7 @@ foreach($result as $row) {
|
|||
$call = $client->account->calls->create(
|
||||
$settings['application']['from'],
|
||||
$row['phone'],
|
||||
$row['xml']
|
||||
$settings['application']['generator'] . '?id=' . $row['id']
|
||||
);
|
||||
})
|
||||
);
|
||||
|
|
|
@ -6,5 +6,6 @@
|
|||
id integer PRIMARY KEY,
|
||||
phone integer,
|
||||
schedule varchar(50),
|
||||
xml varchar(255)
|
||||
);');
|
||||
mp3 varchar(255)
|
||||
);'
|
||||
);
|
||||
|
|
0
files/.gitinclude
Normal file
0
files/.gitinclude
Normal file
|
@ -1,3 +0,0 @@
|
|||
<Response>
|
||||
<Play>http://www.atomaka.com/song-caller/golden-girls.mp3</Play>
|
||||
</Response>
|
20
xml-generator.php
Normal file
20
xml-generator.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
$id = isset($_GET['id']) ? $_GET['id'] : 'bad';
|
||||
|
||||
if(!filter_var($id, FILTER_VALIDATE_INT)) {
|
||||
die("\n");
|
||||
}
|
||||
|
||||
$db = new PDO('sqlite:db/songcaller.db');
|
||||
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$result = $db->query("SELECT mp3 FROM calls WHERE id=$id LIMIT 1");
|
||||
|
||||
$row = $result->fetch();
|
||||
|
||||
header('Content-Type: text/xml');
|
||||
?>
|
||||
<Response>
|
||||
<Play><?php echo $row['mp3']; ?></Play>
|
||||
</Response>
|
Loading…
Reference in a new issue