1
0
generated from mirzaev/pot

5 Commits
1.0.1 ... 1.0.5

6 changed files with 134 additions and 115 deletions

View File

@@ -5,7 +5,7 @@ Wants=network.target
After=syslog.target network-online.target After=syslog.target network-online.target
[Service] [Service]
ExecStart=sudo -u www-data /usr/bin/php /var/www/project/mirzaev/parser_from_interneturok/system/public/telegram.php ExecStart=sudo -u www-data /usr/bin/php /var/www/parser_from_interneturok/mirzaev/parser_from_interneturok/system/public/telegram.php
PIDFile=/var/run/php/parser_from_interneturok-telegram.pid PIDFile=/var/run/php/parser_from_interneturok-telegram.pid
RemainAfterExit=no RemainAfterExit=no
RuntimeMaxSec=3600s RuntimeMaxSec=3600s

View File

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

View File

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

View File

@@ -32,9 +32,6 @@ define('VIEWS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'view
// Initializing path to the directory of settings // Initializing path to the directory of settings
define('SETTINGS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'settings'); define('SETTINGS', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'settings');
// Initializing system settings
require SETTINGS . DIRECTORY_SEPARATOR . 'system.php';
// Initializing path to the directory of the storage // Initializing path to the directory of the storage
define('STORAGE', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'storage'); define('STORAGE', INDEX . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'storage');

View File

@@ -5,5 +5,7 @@
*/ */
return [ return [
1053489457 // Arsen Mirzaev Tatyano-Muradovich @redloser 1053489457, // Arsen Mirzaev Tatyano-Muradovich @redloser
6831961323, // @IU_K1LLER777
1142807069 // @kysakapro
]; ];

View File

@@ -1,4 +0,0 @@
<?php
// Initializing default theme for the views templater
define('THEME', 'default');