Browse Source

some fixed and code cleanup

master
Evgeniy Ierusalimov 1 year ago
parent
commit
3a6fa99983

+ 1
- 0
.gitignore View File

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

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

@@ -34,6 +34,7 @@ class FetchEmailsCommand extends Command
34 34
 
35 35
     protected function execute(InputInterface $input, OutputInterface $output): int
36 36
     {
37
+        /*
37 38
         $io = new SymfonyStyle($input, $output);
38 39
         $arg1 = $input->getArgument('arg1');
39 40
 
@@ -44,11 +45,12 @@ class FetchEmailsCommand extends Command
44 45
         if ($input->getOption('option1')) {
45 46
             // ...
46 47
         }
48
+        */
47 49
 
48 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 55
         return Command::SUCCESS;
54 56
     }

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

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

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

@@ -10,23 +10,17 @@ use Symfony\Component\DependencyInjection\Attribute\Target;
10 10
 use Symfony\Component\Filesystem\Filesystem;
11 11
 use Symfony\Component\Filesystem\Path;
12 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 13
 use App\Service\TelegramNotifier;
20 14
 
21 15
 readonly class MailFetcher
22 16
 {
23 17
     public function __construct(
24 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,13 +40,13 @@ readonly class MailFetcher
46 40
         if (!$mailsIds) {
47 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 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 51
         foreach ($mailsIds as $mailId) {
58 52
             $mail = $mailbox->getMail($mailId);
@@ -72,7 +66,7 @@ readonly class MailFetcher
72 66
 
73 67
                 }
74 68
 
75
-                //$mailbox->deleteMail($mailId);
69
+                $mailbox->deleteMail($mailId);
76 70
                 $this->logger->debug("Deleted email with id=" . $mailId);
77 71
             } else {
78 72
                 $this->logger->debug("Skipped mail with id=" . $mailId);
@@ -141,8 +135,8 @@ readonly class MailFetcher
141 135
             $parsedPortfolio = $this->xmlParser->processXml($xml);
142 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 142
             $fs = new Filesystem();

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

@@ -9,20 +9,15 @@ use Symfony\Component\Notifier\Message\ChatMessage;
9 9
 
10 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 16
     public function notify(string $message): void
22 17
     {
23 18
         $telegramTransport = new TelegramTransport($this->telegramBotToken, $this->telegramChatId);
24 19
         $chatter = new Chatter($telegramTransport);
25
-        $chatMessage = new ChatMessage('<pre>' . $message . '</pre>');
20
+        $chatMessage = new ChatMessage($message);
26 21
 
27 22
         $telegramOptions = new TelegramOptions();
28 23
         $telegramOptions->parseMode(TelegramOptions::PARSE_MODE_HTML);

Loading…
Cancel
Save