generated from mirzaev/pot
added tariffs check
This commit is contained in:
parent
cda2d0bcb9
commit
87b2f2ca0b
|
@ -70,6 +70,17 @@ final class interneturok extends core
|
|||
*/
|
||||
public const string USER = 'https://api-gw.interneturok.ru/api/v2/homeschool/current_user';
|
||||
|
||||
/**
|
||||
* TARIFFS
|
||||
*
|
||||
* Method: GET
|
||||
* Authrorization: Bearer
|
||||
*
|
||||
* @var const string TARIFFS The user tariffs API URL
|
||||
*/
|
||||
public const string TARIFFS = 'https://api-gw.interneturok.ru/api/v2/schedules/users/current/tariffs';
|
||||
|
||||
|
||||
/**
|
||||
* SCHEDULES
|
||||
*
|
||||
|
@ -176,7 +187,8 @@ final class interneturok extends core
|
|||
if (!empty($accounts)) {
|
||||
// Initialized accounts
|
||||
|
||||
if (shuffle($accounts)) {
|
||||
/* if (shuffle($accounts)) { */
|
||||
if (true) {
|
||||
// Shuffled accounts
|
||||
|
||||
foreach ($accounts as $account) {
|
||||
|
@ -263,7 +275,7 @@ final class interneturok extends core
|
|||
|
||||
// Counting the homework downloading for 1 last year
|
||||
$model->database->read(
|
||||
filter: function (record $record) use ($homework, $now, &$year) {
|
||||
filter: function (record $record) use ($homework, $now, &$year) {
|
||||
if ($record->identifier === $homework->item_id && $now - $record->created < 31536000) {
|
||||
// Found a downloading for 1 last year
|
||||
|
||||
|
@ -472,126 +484,153 @@ final class interneturok extends core
|
|||
// Initializing the user data
|
||||
$user = json_decode((string) $response->getBody())?->data?->homeschool?->response?->user;
|
||||
|
||||
if ($user->grade + 1 === $grade) {
|
||||
// Matched the account grade with the grade
|
||||
if (!empty($user)) {
|
||||
// Initialized the user data
|
||||
|
||||
// Initialiint the user identifier
|
||||
$identifier = $user?->id;
|
||||
// Initializing the request to the user data API
|
||||
$request = new request(
|
||||
'GET',
|
||||
static::TARIFFS,
|
||||
[
|
||||
'Authorization' => "Bearer $this->token"
|
||||
]
|
||||
);
|
||||
|
||||
if (!empty($identifier)) {
|
||||
// Initialized the user identifier
|
||||
return $this->browser->sendAsync($request)
|
||||
->then(function ($response) use ($grade, $week, $user) {
|
||||
// Sended the request and received the response
|
||||
|
||||
// Initializing the request to the user schedules API
|
||||
$request = new request(
|
||||
'GET',
|
||||
static::SCHEDULES,
|
||||
[
|
||||
'Authorization' => "Bearer $this->token"
|
||||
]
|
||||
);
|
||||
// Initializing the tariffs data
|
||||
$tariffs = json_decode((string) $response->getBody())?->data?->tariffs?->response;
|
||||
|
||||
return $this->browser->sendAsync($request)
|
||||
->then(function ($response) use ($grade, $identifier, $week) {
|
||||
// Sended the request and received the response
|
||||
foreach ($tariffs as $tariff) {
|
||||
// Iterating over tariffs
|
||||
|
||||
// Initializing the user schedules
|
||||
$schedules = json_decode((string) $response->getBody())?->data?->schedules?->response?->data;
|
||||
if ($tariff->grade === $grade) {
|
||||
// Matched the tariff grade with the target grade
|
||||
|
||||
// Initializing the study years registry
|
||||
$years = $schedules?->study_years;
|
||||
// Initializing the user identifier
|
||||
$identifier = $user?->id;
|
||||
|
||||
if (!empty($years)) {
|
||||
// Initialized the study years registry
|
||||
if (!empty($identifier)) {
|
||||
// Initialized the user identifier
|
||||
|
||||
foreach ($years as $year) {
|
||||
// Iterating over study years
|
||||
// Initializing the request to the user schedules API
|
||||
$request = new request(
|
||||
'GET',
|
||||
static::SCHEDULES,
|
||||
[
|
||||
'Authorization' => "Bearer $this->token"
|
||||
]
|
||||
);
|
||||
|
||||
if ($year->status === 'current') {
|
||||
// The current study year
|
||||
return $this->browser->sendAsync($request)
|
||||
->then(function ($response) use ($grade, $identifier, $week) {
|
||||
// Sended the request and received the response
|
||||
|
||||
// Initializing the request to the moscow time API
|
||||
$request = new request(
|
||||
'GET',
|
||||
static::TIME,
|
||||
[
|
||||
'Authorization' => "Bearer $this->token"
|
||||
]
|
||||
);
|
||||
// Initializing the user schedules
|
||||
$schedules = json_decode((string) $response->getBody())?->data?->schedules?->response?->data;
|
||||
|
||||
return $this->browser->sendAsync($request)
|
||||
->then(function ($response) use ($grade, $identifier, $year, $week) {
|
||||
// Sended the request and received the response
|
||||
// Initializing the study years registry
|
||||
$years = $schedules?->study_years;
|
||||
|
||||
// Initializing the moscow time
|
||||
$time = json_decode((string) $response->getBody())?->data?->time?->response;
|
||||
if (!empty($years)) {
|
||||
// Initialized the study years registry
|
||||
|
||||
if (!empty($time)) {
|
||||
// Initialized the moscow time
|
||||
foreach ($years as $year) {
|
||||
// Iterating over study years
|
||||
|
||||
// Implementing the moscow time
|
||||
$now = new datetime($time);
|
||||
if ($year->status === 'current') {
|
||||
// The current study year
|
||||
|
||||
// Declaring the quarter buffer
|
||||
$quarter = static::quarter(number: $week);
|
||||
|
||||
if ($quarter !== false) {
|
||||
// Initialized number of the quarter
|
||||
|
||||
// Initializing the request to the user journal API
|
||||
// Initializing the request to the moscow time API
|
||||
$request = new request(
|
||||
'GET',
|
||||
static::JOURNAL . "?grade=$grade&quarter=$quarter&year_id=$year->id&user_id=$identifier&token=$this->token"
|
||||
static::TIME,
|
||||
[
|
||||
'Authorization' => "Bearer $this->token"
|
||||
]
|
||||
);
|
||||
|
||||
return $this->browser->sendAsync($request)
|
||||
->then(function ($response) {
|
||||
->then(function ($response) use ($grade, $identifier, $year, $week) {
|
||||
// Sended the request and received the response
|
||||
|
||||
// Initializing the user journal
|
||||
$journal = json_decode((string) $response->getBody());
|
||||
// Initializing the moscow time
|
||||
$time = json_decode((string) $response->getBody())?->data?->time?->response;
|
||||
|
||||
if (!empty($journal)) {
|
||||
// Initialized the user journal
|
||||
if (!empty($time)) {
|
||||
// Initialized the moscow time
|
||||
|
||||
// Exit (success)
|
||||
return $journal;
|
||||
// Implementing the moscow time
|
||||
$now = new datetime($time);
|
||||
|
||||
// Declaring the quarter buffer
|
||||
$quarter = static::quarter(number: $week);
|
||||
|
||||
if ($quarter !== false) {
|
||||
// Initialized number of the quarter
|
||||
|
||||
// Initializing the request to the user journal API
|
||||
$request = new request(
|
||||
'GET',
|
||||
static::JOURNAL . "?grade=$grade&quarter=$quarter&year_id=$year->id&user_id=$identifier&token=$this->token"
|
||||
);
|
||||
|
||||
return $this->browser->sendAsync($request)
|
||||
->then(function ($response) {
|
||||
// Sended the request and received the response
|
||||
|
||||
// Initializing the user journal
|
||||
$journal = json_decode((string) $response->getBody());
|
||||
|
||||
if (!empty($journal)) {
|
||||
// Initialized the user journal
|
||||
|
||||
// Exit (success)
|
||||
return $journal;
|
||||
} else {
|
||||
// Not initialized the user journal
|
||||
|
||||
// Exit (fail)
|
||||
return false;
|
||||
}
|
||||
})->wait();
|
||||
} else {
|
||||
// Not initialized number of the quarter
|
||||
|
||||
// Exit (fail)
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Not initialized the user journal
|
||||
// Not initialized the moscow time
|
||||
|
||||
// Exit (fail)
|
||||
return false;
|
||||
}
|
||||
})->wait();
|
||||
} else {
|
||||
// Not initialized number of the quarter
|
||||
|
||||
// Exit (fail)
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Not initialized the moscow time
|
||||
|
||||
// Exit (fail)
|
||||
return false;
|
||||
}
|
||||
})->wait();
|
||||
}
|
||||
} else {
|
||||
// Not initialized the study years registry
|
||||
|
||||
// Exit (fail)
|
||||
return false;
|
||||
}
|
||||
})->wait();
|
||||
} else {
|
||||
// Not initialized the user identifier
|
||||
|
||||
// Exit (fail)
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Not initialized the study years registry
|
||||
|
||||
// Exit (fail)
|
||||
return false;
|
||||
}
|
||||
})->wait();
|
||||
} else {
|
||||
// Not initialized the user identifier
|
||||
|
||||
// Exit (fail)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Exit (fail)
|
||||
return false;
|
||||
});
|
||||
} else {
|
||||
// Not matched the account grade with the grade
|
||||
// Not initialized the user data
|
||||
|
||||
// Exit (fail)
|
||||
return false;
|
||||
|
|
Loading…
Reference in New Issue