Browse Source

some fixed and code cleanup

master
Evgeniy Ierusalimov 1 year ago
parent
commit
3a6fa99983

+ 1
- 0
.gitignore View File

8
 /var/
8
 /var/
9
 /vendor/
9
 /vendor/
10
 ###< symfony/framework-bundle ###
10
 ###< symfony/framework-bundle ###
11
+.idea

+ 3
- 1
src/Command/FetchEmailsCommand.php View File

34
 
34
 
35
     protected function execute(InputInterface $input, OutputInterface $output): int
35
     protected function execute(InputInterface $input, OutputInterface $output): int
36
     {
36
     {
37
+        /*
37
         $io = new SymfonyStyle($input, $output);
38
         $io = new SymfonyStyle($input, $output);
38
         $arg1 = $input->getArgument('arg1');
39
         $arg1 = $input->getArgument('arg1');
39
 
40
 
44
         if ($input->getOption('option1')) {
45
         if ($input->getOption('option1')) {
45
             // ...
46
             // ...
46
         }
47
         }
48
+        */
47
 
49
 
48
         $this->mailFetcher->fetchNewEmails();
50
         $this->mailFetcher->fetchNewEmails();
49
 
51
 
50
 
52
 
51
-        $io->success('You have a new command! Now make it your own! Pass --help to see your options.');
53
+        //$io->success('You have a new command! Now make it your own! Pass --help to see your options.');
52
 
54
 
53
         return Command::SUCCESS;
55
         return Command::SUCCESS;
54
     }
56
     }

+ 9
- 4
src/Presentation/PortfolioPresenter.php View File

9
 
9
 
10
 class PortfolioPresenter
10
 class PortfolioPresenter
11
 {
11
 {
12
+    public const SecurityMapPrint = [
13
+        'RU000A1014L8' => 'LQDT',
14
+    ];
15
+
16
+
12
     public static function toPrint(ParsedPortfolio $parsedPortfolio): string
17
     public static function toPrint(ParsedPortfolio $parsedPortfolio): string
13
     {
18
     {
14
         $output = new BufferedOutput();
19
         $output = new BufferedOutput();
26
 
31
 
27
         foreach ($parsedPortfolio->getDetails() as $detail) {
32
         foreach ($parsedPortfolio->getDetails() as $detail) {
28
             $table->addRow([
33
             $table->addRow([
29
-                $detail['ЦБ'],// . ' ' . $detail['Эмитент'],
34
+                self::SecurityMapPrint[$detail['ЦБ']] ?? $detail['ЦБ'],// . ' ' . $detail['Эмитент'],
30
                 $detail['КоличествоНО'],
35
                 $detail['КоличествоНО'],
31
                 $detail['НОЦена'],
36
                 $detail['НОЦена'],
32
                 //$detail['СуммаНКДНО'],
37
                 //$detail['СуммаНКДНО'],
51
 
56
 
52
         foreach ($parsedPortfolio->getMovements() as $movement) {
57
         foreach ($parsedPortfolio->getMovements() as $movement) {
53
             $table->addRow([
58
             $table->addRow([
54
-                $movement['ЦБ'],
59
+                self::SecurityMapPrint[$movement['ЦБ']] ?? $movement['ЦБ'],
55
                 //$movement['Период'],
60
                 //$movement['Период'],
56
                 $movement['НО'],
61
                 $movement['НО'],
57
-                $movement['Приход']>0 ? '+'.$movement['Приход'] : $movement['Приход'],
58
-                $movement['Расход']>0 ? '-'.$movement['Расход'] : $movement['Расход'],
62
+                $movement['Приход'] > 0 ? '+' . $movement['Приход'] : $movement['Приход'],
63
+                $movement['Расход'] > 0 ? '-' . $movement['Расход'] : $movement['Расход'],
59
                 $movement['КО'],
64
                 $movement['КО'],
60
             ]);
65
             ]);
61
         }
66
         }

+ 11
- 17
src/Service/MailFetcher.php View File

10
 use Symfony\Component\Filesystem\Filesystem;
10
 use Symfony\Component\Filesystem\Filesystem;
11
 use Symfony\Component\Filesystem\Path;
11
 use Symfony\Component\Filesystem\Path;
12
 use App\Presentation\PortfolioPresenter as PresentationPortfolio;
12
 use App\Presentation\PortfolioPresenter as PresentationPortfolio;
13
-use Symfony\Component\Notifier\Bridge\Telegram\TelegramOptions;
14
-use Symfony\Component\Notifier\Bridge\Telegram\TelegramTransport;
15
-use Symfony\Component\Notifier\Chatter;
16
-use Symfony\Component\Notifier\Message\ChatMessage;
17
-use Symfony\Component\Notifier\Notifier;
18
-use Symfony\Component\Notifier\NotifierInterface;
19
 use App\Service\TelegramNotifier;
13
 use App\Service\TelegramNotifier;
20
 
14
 
21
 readonly class MailFetcher
15
 readonly class MailFetcher
22
 {
16
 {
23
     public function __construct(
17
     public function __construct(
24
         #[Target('finfollowConnection')]
18
         #[Target('finfollowConnection')]
25
-        private ConnectionInterface   $connection,
26
-        private XmlParser             $xmlParser,
27
-        private PortfolioManager      $portfolioManager,
28
-        private LoggerInterface       $logger,
29
-        private TelegramNotifier      $telegramNotifier,
19
+        private ConnectionInterface $connection,
20
+        private XmlParser           $xmlParser,
21
+        private PortfolioManager    $portfolioManager,
22
+        private LoggerInterface     $logger,
23
+        private TelegramNotifier    $telegramNotifier,
30
     )
24
     )
31
     {
25
     {
32
     }
26
     }
46
         if (!$mailsIds) {
40
         if (!$mailsIds) {
47
             $this->logger->info('Mailbox is empty');
41
             $this->logger->info('Mailbox is empty');
48
 
42
 
49
-            $this->logger->warn("Here we should send info about no changes performed..");
43
+            $this->logger->warning("Here we should send info about no changes performed..");
50
 
44
 
51
             return;
45
             return;
52
         }
46
         }
53
 
47
 
54
-// If '__DIR__' was defined in the first line, it will automatically
55
-// save all attachments to the specified directory
48
+        // If '__DIR__' was defined in the first line, it will automatically
49
+        // save all attachments to the specified directory
56
 
50
 
57
         foreach ($mailsIds as $mailId) {
51
         foreach ($mailsIds as $mailId) {
58
             $mail = $mailbox->getMail($mailId);
52
             $mail = $mailbox->getMail($mailId);
72
 
66
 
73
                 }
67
                 }
74
 
68
 
75
-                //$mailbox->deleteMail($mailId);
69
+                $mailbox->deleteMail($mailId);
76
                 $this->logger->debug("Deleted email with id=" . $mailId);
70
                 $this->logger->debug("Deleted email with id=" . $mailId);
77
             } else {
71
             } else {
78
                 $this->logger->debug("Skipped mail with id=" . $mailId);
72
                 $this->logger->debug("Skipped mail with id=" . $mailId);
141
             $parsedPortfolio = $this->xmlParser->processXml($xml);
135
             $parsedPortfolio = $this->xmlParser->processXml($xml);
142
             $message = PresentationPortfolio::toPrint($parsedPortfolio);
136
             $message = PresentationPortfolio::toPrint($parsedPortfolio);
143
 
137
 
144
-             if ($this->portfolioManager->updatePortfolio($parsedPortfolio, $xmlString)) {
145
-                 $this->telegramNotifier->notify($message);
138
+            if ($this->portfolioManager->updatePortfolio($parsedPortfolio, $xmlString)) {
139
+                $this->telegramNotifier->notify('<pre>' . $message . '</pre>');
146
             }
140
             }
147
 
141
 
148
             $fs = new Filesystem();
142
             $fs = new Filesystem();

+ 2
- 7
src/Service/TelegramNotifier.php View File

9
 
9
 
10
 readonly class TelegramNotifier
10
 readonly class TelegramNotifier
11
 {
11
 {
12
-    private string $telegramBotToken;
13
-    private string $telegramChatId;
14
-
15
-    public function __construct(string $telegramBotToken, string $telegramChatId)
12
+    public function __construct(private string $telegramBotToken, private string $telegramChatId)
16
     {
13
     {
17
-        $this->telegramBotToken = $telegramBotToken;
18
-        $this->telegramChatId = $telegramChatId;
19
     }
14
     }
20
 
15
 
21
     public function notify(string $message): void
16
     public function notify(string $message): void
22
     {
17
     {
23
         $telegramTransport = new TelegramTransport($this->telegramBotToken, $this->telegramChatId);
18
         $telegramTransport = new TelegramTransport($this->telegramBotToken, $this->telegramChatId);
24
         $chatter = new Chatter($telegramTransport);
19
         $chatter = new Chatter($telegramTransport);
25
-        $chatMessage = new ChatMessage('<pre>' . $message . '</pre>');
20
+        $chatMessage = new ChatMessage($message);
26
 
21
 
27
         $telegramOptions = new TelegramOptions();
22
         $telegramOptions = new TelegramOptions();
28
         $telegramOptions->parseMode(TelegramOptions::PARSE_MODE_HTML);
23
         $telegramOptions->parseMode(TelegramOptions::PARSE_MODE_HTML);

Loading…
Cancel
Save