1
0
Fork 0

Compare commits

..

No commits in common. "stable" and "1.1.3" have entirely different histories.

2 changed files with 87 additions and 131 deletions

View File

@ -1,12 +1,6 @@
# parser_from_interneturok # parser_from_interneturok
Chat-robot Telegram for parsing homeworks by subject name, grade and number of the week Chat-robot Telegram for parsing homeworks by subject name, grade and number of the week
## Funny story of development
The customer of this project **refused to pay** the second half of the payment for the work and wanted to steal my code.<br>
<br>
I managed to delete all the code from the server, then i changed passwords on all **40 accounts** that were planned to be used in this chat-robot.<br>
Thus **i destroyed the entire mini-business** of this customer.
## Dependencies ## Dependencies
1. [PHP 8.4](https://www.php.net/releases/8.4/en.php) 1. [PHP 8.4](https://www.php.net/releases/8.4/en.php)
2. [Composer](https://getcomposer.org/) (php package manager) 2. [Composer](https://getcomposer.org/) (php package manager)

View File

@ -70,17 +70,6 @@ final class interneturok extends core
*/ */
public const string USER = 'https://api-gw.interneturok.ru/api/v2/homeschool/current_user'; 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 * SCHEDULES
* *
@ -274,7 +263,7 @@ final class interneturok extends core
// Counting the homework downloading for 1 last year // Counting the homework downloading for 1 last year
$model->database->read( $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) { if ($record->identifier === $homework->item_id && $now - $record->created < 31536000) {
// Found a downloading for 1 last year // Found a downloading for 1 last year
@ -293,7 +282,7 @@ final class interneturok extends core
// Exit (success) // Exit (success)
return ['downloads' => ['year' => $year], 'files' => $files]; return ['downloads' => ['year' => $year], 'files' => $files];
} }
} }
} }
} }
@ -483,153 +472,126 @@ final class interneturok extends core
// Initializing the user data // Initializing the user data
$user = json_decode((string) $response->getBody())?->data?->homeschool?->response?->user; $user = json_decode((string) $response->getBody())?->data?->homeschool?->response?->user;
if (!empty($user)) { if ($user->grade + 1 === $grade) {
// Initialized the user data // Matched the account grade with the grade
// Initializing the request to the user data API // Initialiint the user identifier
$request = new request( $identifier = $user?->id;
'GET',
static::TARIFFS,
[
'Authorization' => "Bearer $this->token"
]
);
return $this->browser->sendAsync($request) if (!empty($identifier)) {
->then(function ($response) use ($grade, $week, $user) { // Initialized the user identifier
// Sended the request and received the response
// Initializing the tariffs data // Initializing the request to the user schedules API
$tariffs = json_decode((string) $response->getBody())?->data?->tariffs?->response; $request = new request(
'GET',
static::SCHEDULES,
[
'Authorization' => "Bearer $this->token"
]
);
foreach ($tariffs as $tariff) { return $this->browser->sendAsync($request)
// Iterating over tariffs ->then(function ($response) use ($grade, $identifier, $week) {
// Sended the request and received the response
if ($tariff->grade === $grade) { // Initializing the user schedules
// Matched the tariff grade with the target grade $schedules = json_decode((string) $response->getBody())?->data?->schedules?->response?->data;
// Initializing the user identifier // Initializing the study years registry
$identifier = $user?->id; $years = $schedules?->study_years;
if (!empty($identifier)) { if (!empty($years)) {
// Initialized the user identifier // Initialized the study years registry
// Initializing the request to the user schedules API foreach ($years as $year) {
$request = new request( // Iterating over study years
'GET',
static::SCHEDULES,
[
'Authorization' => "Bearer $this->token"
]
);
return $this->browser->sendAsync($request) if ($year->status === 'current') {
->then(function ($response) use ($grade, $identifier, $week) { // The current study year
// Sended the request and received the response
// Initializing the user schedules // Initializing the request to the moscow time API
$schedules = json_decode((string) $response->getBody())?->data?->schedules?->response?->data; $request = new request(
'GET',
static::TIME,
[
'Authorization' => "Bearer $this->token"
]
);
// Initializing the study years registry return $this->browser->sendAsync($request)
$years = $schedules?->study_years; ->then(function ($response) use ($grade, $identifier, $year, $week) {
// Sended the request and received the response
if (!empty($years)) { // Initializing the moscow time
// Initialized the study years registry $time = json_decode((string) $response->getBody())?->data?->time?->response;
foreach ($years as $year) { if (!empty($time)) {
// Iterating over study years // Initialized the moscow time
if ($year->status === 'current') { // Implementing the moscow time
// The current study year $now = new datetime($time);
// Initializing the request to the moscow time API // 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( $request = new request(
'GET', 'GET',
static::TIME, static::JOURNAL . "?grade=$grade&quarter=$quarter&year_id=$year->id&user_id=$identifier&token=$this->token"
[
'Authorization' => "Bearer $this->token"
]
); );
return $this->browser->sendAsync($request) return $this->browser->sendAsync($request)
->then(function ($response) use ($grade, $identifier, $year, $week) { ->then(function ($response) {
// Sended the request and received the response // Sended the request and received the response
// Initializing the moscow time // Initializing the user journal
$time = json_decode((string) $response->getBody())?->data?->time?->response; $journal = json_decode((string) $response->getBody());
if (!empty($time)) { if (!empty($journal)) {
// Initialized the moscow time // Initialized the user journal
// Implementing the moscow time // Exit (success)
$now = new datetime($time); return $journal;
// 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 { } else {
// Not initialized the moscow time // Not initialized the user journal
// Exit (fail) // Exit (fail)
return false; return false;
} }
})->wait(); })->wait();
} else {
// Not initialized number of the quarter
// Exit (fail)
return false;
} }
} else {
// Not initialized the moscow time
// Exit (fail)
return false;
} }
} else { })->wait();
// 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();
// Exit (fail) } else {
return false; // Not initialized the user identifier
});
// Exit (fail)
return false;
}
} else { } else {
// Not initialized the user data // Not matched the account grade with the grade
// Exit (fail) // Exit (fail)
return false; return false;