-
Notifications
You must be signed in to change notification settings - Fork 2
/
inauspicious-period.php
95 lines (79 loc) · 2.93 KB
/
inauspicious-period.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
declare(strict_types=1);
use Prokerala\Api\Astrology\Location;
use Prokerala\Api\Astrology\Service\InauspiciousPeriod;
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 = 'inauspicious-period';
$arSupportedLanguages = [
'en' => 'English',
'hi' => 'Hindi',
'ta' => 'Tamil',
'te' => 'Telugu',
'ml' => 'Malayalam',
];
$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 = [];
if ($submit) {
try {
$method = new InauspiciousPeriod($client);
$method->setAyanamsa($ayanamsa);
$method->setTimeZone($tz);
$result = $method->process($location, $datetime, $la);
$inauspiciousPeriod = [];
$arData = $result->getMuhurat();
foreach ($arData as $idx => $data) {
$inauspiciousPeriod[$idx] = [
'id' => $data->getId(),
'name' => $data->getName(),
'type' => $data->getType(),
];
$arPeriod = $data->getPeriod();
foreach ($arPeriod as $period) {
$inauspiciousPeriod[$idx]['period'][] = [
'start' => $period->getStart(),
'end' => $period->getEnd(),
];
}
}
} 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/inauspicious-period.tpl.php';