-
Notifications
You must be signed in to change notification settings - Fork 0
/
gca2word.php
executable file
·63 lines (56 loc) · 1.97 KB
/
gca2word.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env php
<?php
require_once __DIR__.'/vendor/autoload.php';
$configPath = __DIR__.'/config';
$configJsonPath = $configPath.'/custom.json';
if (!file_exists($configJsonPath)) {
$configJsonPath = $configPath.'/default.json';
}
if (!file_exists($configJsonPath)) {
exit('Fatal Error: config json not found'.PHP_EOL);
}
$configJson = file_get_contents($configJsonPath);
$config = json_decode($configJson, true);
if (null === $config) {
exit('Fatal Error: invalid config json format'.PHP_EOL);
}
$options = getopt('h:u:pc:o:');
foreach ($options as $option => $value) {
switch ($option) {
case 'h':
$config['host'] = trim($value);
break;
case 'u':
$config['auth']['user'] = trim($value);
break;
case 'p':
$value = NIJC\PasswordUtility::input();
if (null === $value) {
exit('Fatal Error: failed to set password'.PHP_EOL);
}
$config['auth']['password'] = trim($value);
break;
case 'c':
$config['conference'] = trim($value);
break;
case 'o':
$config['output'] = trim($value);
break;
}
}
$gca = new NIJC\GcaClient($config['host'], $config['auth']['user'], $config['auth']['password']);
$conferenceJson = $gca->getConference($config['conference']);
if (false === $conferenceJson) {
exit('Fatal Error: failed to get conference information: '.$config['conference'].PHP_EOL);
}
$abstractsJson = $gca->getAbstracts($config['conference']);
if (false === $abstractsJson) {
exit('Fatal Error: failed to get all abstracts data: '.$config['conference'].PHP_EOL);
}
$tempDir = new NIJC\TempDirectory();
$imageDir = $tempDir->get();
if (!$gca->saveImages($abstractsJson, $imageDir)) {
exit('Fatal Error: failed to get image data: '.$config['conference'].PHP_EOL);
}
$writer = new NIJC\AbstractsWriter($abstractsJson, $conferenceJson, $imageDir);
$writer->save($config['output']);