1
0
generated from mirzaev/pot

3 Commits
1.0.2 ... 1.0.5

Author SHA1 Message Date
8ea9e7ef3d try catch for accounts 2025-03-06 06:28:41 +07:00
05143b6865 fixed messages 2025-03-06 06:21:52 +07:00
accfe5a496 fixes 2025-03-06 06:17:11 +07:00
2 changed files with 130 additions and 106 deletions

View File

@@ -184,138 +184,143 @@ final class interneturok extends core
// Waiting for processing the request
sleep($waiting);
if ($this->authentication($account)->wait()) {
// Authenticated the account
try {
// Writing into the output buffer
echo 'Аутентифицирован: ' . $account['mail'] . "\n";
// Waiting for processing the request
sleep($waiting);
// Initializing the user journal
$journal = $this->journal(grade: $grade)->wait();
if (!empty($journal)) {
// Initialized the user journal
if ($this->authentication($account)->wait()) {
// Authenticated the account
// Writing into the output buffer
echo "Инициализирован журнал\n";
echo 'Аутентифицирован: ' . $account['mail'] . "\n";
// Initializing the actual date
$date = new datetime();
// Waiting for processing the request
sleep($waiting);
// Initializing the homeworks database
$model = new homework();
// Initializing the user journal
$journal = $this->journal(grade: $grade)->wait();
// Initializing the schedule subject events
$schedule = $journal?->schedule_events;
if (!empty($journal)) {
// Initialized the user journal
foreach ($schedule as $_subject) {
// Iterating over scheduled subject events
// Writing into the output buffer
echo "Инициализирован журнал\n";
if ($_subject->subject?->name === $subject->value) {
// Found the target suject
// Initializing the actual date
$date = new datetime();
foreach ($_subject->events as $event) {
// Iterating over the target subject events
// Initializing the homeworks database
$model = new homework();
// Normalizing the event variable (events can be more than one)
$event = $event[0] ?? null;
// Initializing the schedule subject events
$schedule = $journal?->schedule_events;
if (!empty($event)) {
// Initialized the target subject event (the homework exists)
foreach ($schedule as $_subject) {
// Iterating over scheduled subject events
if (new datetime($event->date) <= $date && new datetime($event->date)->modify('+6 days') >= $date) {
// Found the current event
if ($_subject->subject?->name === $subject->value) {
// Found the target suject
if ($event->subject?->name === $subject->value && $event->subject->grade === $grade) {
// Found the target subject
foreach ($_subject->events as $event) {
// Iterating over the target subject events
// Writing into the output buffer
echo "Найден школьный предмет: $subject->value для $grade класса (с " . new datetime($event->date)->format('d.m') . ' по ' . new datetime($event->date)->modify('+6 days')->format('d.m') . ")\n";
// Normalizing the event variable (events can be more than one)
$event = $event[0] ?? null;
// Initializing the unblock time
$unblock = svoboda::timestamp() - 31536000;
if (!empty($event)) {
// Initialized the target subject event (the homework exists)
foreach ($event->homeworks as $homework) {
// Iterating over scheduled event homeworks
if (new datetime($event->date) <= $date && new datetime($event->date)->modify('+6 days') >= $date) {
// Found the current event
if ($homework->status === 'checked' && $homework->mark === 5) {
// Homework checked and completed for a grade of 5
if ($event->subject?->name === $subject->value && $event->subject->grade === $grade) {
// Found the target subject
// Checking for the block record
$blocked = $model->database->read(
filter: fn(record $record) => $record->identifier === $homework->item_id && $record->created > $unblock,
amount: 1
)[0] ?? null;
// Writing into the output buffer
/* echo "Найден школьный предмет: $subject->value для $grade класса (с " . new datetime($event->date)->format('d.m') . ' по ' . new datetime($event->date)->modify('+6 days')->format('d.m') . ")\n"; */
if ($blocked instanceof record) {
// The account homework has been downloaded for 1 year
// Initializing the unblock time
$unblock = svoboda::timestamp() - 31536000;
continue 3;
} else {
// The account homework has not been downloaded for 1 year
foreach ($event->homeworks as $homework) {
// Iterating over scheduled event homeworks
// Writing into the output buffer
echo "Найдено домашнее задание: $homework->item_id с оценкой $homework->mark\n";
if ($homework->status === 'checked' && $homework->mark === 5) {
// Homework checked and completed for a grade of 5
// Waiting for processing the request
sleep($waiting);
// Checking for the block record
$blocked = $model->database->read(
filter: fn(record $record) => $record->identifier === $homework->item_id && $record->created > $unblock,
amount: 1
)[0] ?? null;
// Initializing the homework files
$files = $this->homework(lesson: $event->lesson->id, homework: $homework->item_id)->wait();
if ($blocked instanceof record) {
// The account homework has been downloaded for 1 year
if (!empty($files)) {
// Initialized the homework files
continue 3;
} else {
// The account homework has not been downloaded for 1 year
// Writing into the output buffer
echo "Получено домашнее задание\n";
echo "Найдено домашнее задание: $homework->item_id с оценкой $homework->mark\n";
// Blocking the homework downloading for 1 year
$blocked = $model->create(identifier: $homework->item_id);
// Waiting for processing the request
sleep($waiting);
if ($blocked !== false) {
// The homework was blocked for 1 year
// Initializing the homework files
$files = $this->homework(lesson: $event->lesson->id, homework: $homework->item_id)->wait();
if (!empty($files)) {
// Initialized the homework files
// Writing into the output buffer
echo "Заблокировано на 1 год домашнее задание\n";
echo "Получено домашнее задание\n";
// Exit (success)
return $files;
// Blocking the homework downloading for 1 year
$blocked = $model->create(identifier: $homework->item_id);
if ($blocked !== false) {
// The homework was blocked for 1 year
// Writing into the output buffer
echo "Заблокировано на 1 год домашнее задание\n";
// Exit (success)
return $files;
}
}
}
}
}
}
}
// Stopping processing events and starting processing the next account
break 2;
// Stopping processing events and starting processing the next account
break 2;
}
}
}
}
// Stopping processing events and starting processing the next account
break;
// Stopping processing events and starting processing the next account
break;
}
}
} else {
// Not initialized the user journal
// Writing into the output buffer
echo "Аккаунт не подходит под требования\n";
// Proceed to processing the next account
continue;
}
} else {
// Not initialized the user journal
// Not authenticated the account
// Writing into the output buffer
echo "Аккаунт не подходит под требования\n";
echo "Не аутентифицирован\n";
// Proceed to processing the next account
continue;
}
} else {
// Not authenticated the account
// Writing into the output buffer
echo "Не аутентифицирован\n";
// Proceed to processing the next account
} catch (exception $exception) {
continue;
}
}
@@ -900,16 +905,21 @@ final class interneturok extends core
*/
public static function amount(): int
{
// Opening the interneturok accounts file
$file = new spl(INTERNETUROK_ACCOUNTS_FILE, 'r');
try {
// Opening the interneturok accounts file
$file = new spl(INTERNETUROK_ACCOUNTS_FILE, 'r');
// Move the cursor to the last row
$file->seek(PHP_INT_MAX);
// Move the cursor to the last row
$file->seek(PHP_INT_MAX);
// Initializing number of the last row
$rows = $file->key();
// Initializing number of the last row
$rows = $file->key();
// Exit (success)
return $rows;
// Exit (success)
return $rows;
} catch (exception $exception) {
// Exit (fail)
return 0;
}
}
}

View File

@@ -17,6 +17,9 @@ use Zanzara\Context as context,
// Framework for asynchronous PHP
use function React\Async\await;
// Built-in libraries
use Exception as exception;
/**
* Telegram shcool subjects parser
*
@@ -205,26 +208,37 @@ final class parser extends core
// Initializing the parser
$parser = new interneturok();
// Parsing homework files
$files = $parser->parse(subject: $subject, grade: $grade, waiting: 3);
try {
// Parsing homework files
$files = $parser->parse(subject: $subject, grade: $grade, waiting: 3);
if (!empty($files)) {
// Initialized homework files
if (!empty($files)) {
// Initialized homework files
foreach ($files as $file) {
// Iterating over files in the storage
foreach ($files as $file) {
// Iterating over files in the storage
// Sending the file
await($context->sendDocument(new file_input($file)));
// Sending the file
await($context->sendDocument(new file_input($file)));
}
// Deleting in the telegram user buffer
$context->deleteUserDataItem(static::PROCESS);
} else {
// Not initialized homework files
// Sending the message
$context->sendMessage('❌ *Не найдены домашние задания*')
->then(function (message $message) use ($context) {
// Sended the message
// Sending the menu with subjects
commands::menu($context);
});
}
// Deleting in the telegram user buffer
$context->deleteUserDataItem(static::PROCESS);
} else {
// Not initialized homework files
} catch (exception $exception) {
// Sending the message
$context->sendMessage('❌ *Не найдены домашние задания')
$context->sendMessage('⚠️ *Произошла ошибка при обработке домашних заданий*')
->then(function (message $message) use ($context) {
// Sended the message