-
Notifications
You must be signed in to change notification settings - Fork 2
/
anandadi-yoga.php
73 lines (61 loc) · 2.27 KB
/
anandadi-yoga.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
64
65
66
67
68
69
70
71
72
73
<?php
declare(strict_types=1);
use Prokerala\Api\Astrology\Location;
use Prokerala\Api\Astrology\Service\AnandadiYoga;
use Prokerala\Common\Api\Exception\AuthenticationException;
use Prokerala\Common\Api\Exception\Exception;
use Prokerala\Common\Api\Exception\QuotaExceededException;
use Prokerala\Common\Api\Exception\RateLimitExceededException;
use Prokerala\Common\Api\Exception\ValidationException;
require __DIR__ . '/bootstrap.php';
$time_now = new DateTimeImmutable();
$input = [
'datetime' => $time_now->format('c'),
'latitude' => '19.0821978',
'longitude' => '72.7411014', // Mumbai
];
$coordinates = $input['latitude'] . ',' . $input['longitude'];
$submit = $_POST['submit'] ?? 0;
$ayanamsa = 1;
$la = $_POST['la'] ?? 'en';
$sample_name = 'anandadi-yoga';
$arSupportedLanguages = [
'en' => 'English',
'ta' => 'Tamil',
];
$timezone = 'Asia/Kolkata';
if ($submit) {
$input['datetime'] = $_POST['datetime'];
$coordinates = $_POST['coordinates'];
$arCoordinates = explode(',', $coordinates);
$input['latitude'] = $arCoordinates[0] ?? '';
$input['longitude'] = $arCoordinates[1] ?? '';
$ayanamsa = $_POST['ayanamsa'];
$timezone = $_POST['timezone'] ?? '';
}
$tz = new DateTimeZone($timezone);
$datetime = new DateTimeImmutable($input['datetime'], $tz);
$location = new Location((float)$input['latitude'], (float)$input['longitude'], 0, $tz);
$result = [];
$errors = [];
$arData = [];
if ($submit) {
try {
$method = new AnandadiYoga($client);
$method->setAyanamsa($ayanamsa);
$method->setTimeZone($tz);
$result = $method->process($location, $datetime, $la);
} catch (ValidationException $e) {
$errors = $e->getValidationErrors();
} catch (QuotaExceededException $e) {
$errors['message'] = 'ERROR: You have exceeded your quota allocation for the day';
} catch (RateLimitExceededException $e) {
$errors['message'] = 'ERROR: Rate limit exceeded. Throttle your requests.';
} catch (AuthenticationException $e) {
$errors = ['message' => $e->getMessage()];
} catch (Exception $e) {
$errors = ['message' => "API Request Failed with error {$e->getMessage()}"];
}
}
$apiCreditUsed = $client->getCreditUsed();
include DEMO_BASE_DIR . '/templates/anandadi-yoga.tpl.php';