[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: (fwd)
From: |
Sven Axelsson |
Subject: |
Re: (fwd) |
Date: |
Wed, 22 Mar 2017 19:58:27 +0100 |
On 22 March 2017 at 19:18, Martin Tarenskeen <address@hidden> wrote:
> Thanks! It seems to be working, but I am not sure if I'm understanding the
> usage correctly.
> It looks like I have to ru the script twice.
>
> lilybin example.ly
>
> returns a message in my terminal telling me what to type next, which is
> something like
>
> lilybin -d d-numbers-and-characters.pdf
>
> Right? Isn't it possible to make the script do this automatically? Because
> I'm not familiar with PHP I have written myself a little shellscrpt that
> calls your php script, redirects the output to a temporary file, runs this
> file as a shelllscript, extracts the name of the downloaded file, renames it
> to a human-radable file. In short:
>
> lilybin.sh example.ly
> will give me a score named example.pdf
>
> And I have run this succesfully in an Android terminal app called termux.
> Lilypond running in Android now! Cool!
>
> I can send you my script if you are interested. But maybe you can improve
> your PHP script to only need one run instead of two?
Of course it is possible to do that. I thought it a good idea to use
separate calls, since when a file is processed at lilybin the result
is stored there and it could be useful to download it again without
having to process it anew.
Also, you can use lilybin -d remote-name.pdf local-path.pdf to rename
the downloaded file to something more convenient in one go.
Anyways, now you can use the -a flag to do both steps in one go.
--->>> snip <<<---
#!/usr/bin/env php
<?php
function do_curl($url, $opts)
{
$curl = curl_init($url);
curl_setopt_array($curl, $opts);
$result = curl_exec($curl);
curl_close($curl);
return $result;
}
$opts = getopt('ad', $argv);
$sep = array_search('--', $argv);
$files = array_slice($argv, $sep ? ++$sep : count($opts) + 1);
if (count($files) === 0 || count($files) > 2) {
die("Usage: lilybin [-ad] file [file]\n");
}
$all = isset($opts['a']);
$download = isset($opts['d']);
if ($all || !$download) {
$url =
'https://7icpm9qr6a.execute-api.us-west-2.amazonaws.com/prod/prepare_preview/stable';
$result = json_decode(do_curl($url, [
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => json_encode(['code' =>
file_get_contents($files[0])]),
CURLOPT_RETURNTRANSFER => true,
]));
if (!$result->id) {
echo "ERROR:\n", $result->stderr;
exit(1);
}
if ($all) {
$files[0] = $result->id . '.pdf';
} else {
echo $argv[0], ' -d ', $result->id, ".pdf\n";
exit;
}
}
if ($all || $download) {
$url = 'https://s3-us-west-2.amazonaws.com/lilybin-scores/' . $files[0];
$file = fopen(@$files[1] ?: $files[0], 'w');
do_curl($url, [CURLOPT_FILE => $file]);
fclose($file);
}
--->>> end snip <<<---
--
Sven Axelsson
++++++++++[>++++++++++>+++++++++++>++++++++++>++++++
>++++<<<<<-]>++++.+.++++.>+++++.>+.<<-.>>+.>++++.<<.
+++.>-.<<++.>>----.<++.>>>++++++.<<<<.>>++++.<----.
- Re: (fwd), Martin Tarenskeen, 2017/03/21
- Re: (fwd), Urs Liska, 2017/03/21
- Re: (fwd), Martin Tarenskeen, 2017/03/21
- Re: (fwd), Sven Axelsson, 2017/03/21
- Re: (fwd), Martin Tarenskeen, 2017/03/21
- Re: (fwd), Sven Axelsson, 2017/03/22
- Message not available
- Re: (fwd),
Sven Axelsson <=
- Re: (fwd), Martin Tarenskeen, 2017/03/22
- Re: (fwd), Sven Axelsson, 2017/03/22
- Message not available
- lilybin php script (was: Re: (fwd)), Martin Tarenskeen, 2017/03/23
- Re: lilybin php script (was: Re: (fwd)), Trevor, 2017/03/23
- Re: lilybin php script (was: Re: (fwd)), Martin Tarenskeen, 2017/03/23
- Re: lilybin php script (was: Re: (fwd)), Martin Tarenskeen, 2017/03/24
- Re: lilybin php script (was: Re: (fwd)), Martin Tarenskeen, 2017/03/27
Re: (fwd), Dmytro O. Redchuk, 2017/03/21