Bladeren bron

moved securities map from class constant to .env

master
Evgeniy Ierusalimov 11 maanden geleden
bovenliggende
commit
8158dd9e4a

+ 2
- 0
.env Bestand weergeven

@@ -40,3 +40,5 @@ TELEGRAM_DSN=telegram://bot_token@default?channel=channel_id
40 40
 
41 41
 TELEGRAM_BOT_TOKEN=
42 42
 TELEGRAM_CHAT_ID=
43
+
44
+SECURITIES_MAP='{"RU000A1014L8":"LQDT", "RU000A107UL4":"T", "RU000A108X38":"X5"}'

+ 1
- 0
README.md Bestand weergeven

@@ -9,3 +9,4 @@ The main goal is
9 9
 NB:
10 10
 Do not forget to remove `var/imap/attachments/*.bin` files after
11 11
 
12
+Use .env:SECURITIES_MAP to substitute more human-readable titles instead of given ones

+ 5
- 0
config/services.yaml Bestand weergeven

@@ -4,6 +4,7 @@
4 4
 # Put parameters here that don't need to change on each machine where the app is deployed
5 5
 # https://symfony.com/doc/current/best_practices.html#use-parameters-for-application-configuration
6 6
 parameters:
7
+    securitiesMap: '%env(json:SECURITIES_MAP)%'
7 8
 
8 9
 services:
9 10
     # default configuration for services in *this* file
@@ -26,3 +27,7 @@ services:
26 27
         arguments:
27 28
             $telegramBotToken: '%env(TELEGRAM_BOT_TOKEN)%'
28 29
             $telegramChatId: '%env(TELEGRAM_CHAT_ID)%'
30
+
31
+    App\Presentation\PortfolioPresenter:
32
+        arguments:
33
+            $securitiesMap: '%securitiesMap%'

+ 1
- 4
src/Command/FetchEmailsCommand.php Bestand weergeven

@@ -14,12 +14,9 @@ use Symfony\Component\Console\Output\OutputInterface;
14 14
 )]
15 15
 class FetchEmailsCommand extends Command
16 16
 {
17
-    private MailFetcher $mailFetcher;
18
-
19
-    public function __construct(MailFetcher $mailFetcher)
17
+    public function __construct(private readonly MailFetcher $mailFetcher)
20 18
     {
21 19
         parent::__construct();
22
-        $this->mailFetcher = $mailFetcher;
23 20
     }
24 21
 
25 22
     protected function execute(InputInterface $input, OutputInterface $output): int

+ 7
- 7
src/Command/ImportFromXmlCommand.php Bestand weergeven

@@ -2,7 +2,7 @@
2 2
 
3 3
 namespace App\Command;
4 4
 
5
-use App\Presentation\PortfolioPresenter as PresentationPortfolio;
5
+use App\Presentation\PortfolioPresenter;
6 6
 use App\Service\TelegramNotifier;
7 7
 use App\Service\XmlParser;
8 8
 use Symfony\Component\Console\Attribute\AsCommand;
@@ -20,8 +20,9 @@ use Symfony\Component\Console\Style\SymfonyStyle;
20 20
 class ImportFromXmlCommand extends Command
21 21
 {
22 22
     public function __construct(
23
-        private readonly XmlParser        $xmlParser,
24
-        private readonly TelegramNotifier $telegramNotifier,
23
+        private readonly XmlParser          $xmlParser,
24
+        private readonly TelegramNotifier   $telegramNotifier,
25
+        private readonly PortfolioPresenter $portfolioPresenter,
25 26
     )
26 27
     {
27 28
         parent::__construct();
@@ -32,8 +33,7 @@ class ImportFromXmlCommand extends Command
32 33
         $this
33 34
             //->addArgument('xml-file', null, InputArgument::REQUIRED, 'XML file with portfolio data')
34 35
             ->addOption('xml-file', null, InputOption::VALUE_REQUIRED, 'XML file with Portfolio data')
35
-            ->addOption('notify', null, InputOption::VALUE_NONE, 'Notify to telegram')
36
-        ;
36
+            ->addOption('notify', null, InputOption::VALUE_NONE, 'Notify to telegram');
37 37
     }
38 38
 
39 39
     protected function execute(InputInterface $input, OutputInterface $output): int
@@ -49,8 +49,8 @@ class ImportFromXmlCommand extends Command
49 49
         $xml = simplexml_load_string($xmlString);
50 50
 
51 51
         $parsedPortfolio = $this->xmlParser->processXml($xml);
52
-        print (new PresentationPortfolio)->toText($parsedPortfolio);
53
-        (new PresentationPortfolio)->toImage($parsedPortfolio, 'portfolio.png');
52
+        print $this->portfolioPresenter->toText($parsedPortfolio);
53
+        $this->portfolioPresenter->toImage($parsedPortfolio, 'portfolio.png');
54 54
 
55 55
         if ($input->getOption('notify')) {
56 56
             $this->telegramNotifier->notify('', 'portfolio.png');

+ 11
- 9
src/Presentation/PortfolioPresenter.php Bestand weergeven

@@ -9,15 +9,17 @@ use Symfony\Component\Console\Helper\TableStyle;
9 9
 
10 10
 class PortfolioPresenter
11 11
 {
12
-    private const SecurityMapPrint = [
13
-        ['RU000A1014L8', 'RU000A107UL4', '(в пути)'], ['LQDT', 'T', '±'],
14
-    ];
15
-
16 12
     private const FONT_SIZE = 12;
17 13
     private const FONT_NAME = 'droid_sans_mono';
18 14
     private const COPYRIGHT_MARK = ' ©ЕИ';
15
+    private array $securityMapPrintable = [['(в пути)'], ['±']];
16
+    private array $mapSecurityTitle = [];
19 17
 
20
-    private array $MapSecuritiesPrintable = [];
18
+    public function __construct(array $securitiesMap)
19
+    {
20
+        array_unshift($this->securityMapPrintable[0], ...array_keys($securitiesMap));
21
+        array_unshift($this->securityMapPrintable[1], ...array_values($securitiesMap));
22
+    }
21 23
 
22 24
     public function toImage(ParsedPortfolio $parsedPortfolio, string $filename): void
23 25
     {
@@ -118,14 +120,14 @@ class PortfolioPresenter
118 120
 
119 121
     private function getPrintableSecurityTitle(array $security): string
120 122
     {
121
-        $security['ЦБ'] = str_replace(self::SecurityMapPrint[0], self::SecurityMapPrint[1], $security['ЦБ']);
123
+        $security['ЦБ'] = str_replace($this->securityMapPrintable[0], $this->securityMapPrintable[1], $security['ЦБ']);
122 124
 
123 125
         if (!str_starts_with($security['ЦБ'], 'RU00')) {
124 126
             return $security['ЦБ'];
125 127
         }
126 128
 
127
-        if (isset($this->MapSecuritiesPrintable[$security['ЦБ']])) {
128
-            return $this->MapSecuritiesPrintable[$security['ЦБ']];
129
+        if (isset($this->mapSecurityTitle[$security['ЦБ']])) {
130
+            return $this->mapSecurityTitle[$security['ЦБ']];
129 131
         }
130 132
 
131 133
         if (!isset($security['Эмитент'])) {
@@ -133,7 +135,7 @@ class PortfolioPresenter
133 135
         }
134 136
 
135 137
         $title = str_replace(['МКПАО', 'ПАО', '"', ' ', '(', ')'], ['', '', '', '', '', ''], $security['Эмитент']);
136
-        $this->MapSecuritiesPrintable[$security['ЦБ']] = $title;
138
+        $this->mapSecurityTitle[$security['ЦБ']] = $title;
137 139
 
138 140
         return $title;
139 141
     }

+ 3
- 2
src/Service/MailFetcher.php Bestand weergeven

@@ -9,7 +9,7 @@ use SecIT\ImapBundle\Connection\ConnectionInterface;
9 9
 use Symfony\Component\DependencyInjection\Attribute\Target;
10 10
 use Symfony\Component\Filesystem\Filesystem;
11 11
 use Symfony\Component\Filesystem\Path;
12
-use App\Presentation\PortfolioPresenter as PresentationPortfolio;
12
+use App\Presentation\PortfolioPresenter;
13 13
 use App\Service\TelegramNotifier;
14 14
 
15 15
 readonly class MailFetcher
@@ -21,6 +21,7 @@ readonly class MailFetcher
21 21
         private PortfolioManager    $portfolioManager,
22 22
         private LoggerInterface     $logger,
23 23
         private TelegramNotifier    $telegramNotifier,
24
+        private PortfolioPresenter  $portfolioPresenter,
24 25
     )
25 26
     {
26 27
     }
@@ -135,7 +136,7 @@ readonly class MailFetcher
135 136
                 //$this->telegramNotifier->notify('<pre>' . (new PresentationPortfolio)->toText($parsedPortfolio) . '</pre>');
136 137
 
137 138
                 $pngFilename = $tmpdir . '/portfolio.png';
138
-                (new PresentationPortfolio)->toImage($parsedPortfolio, $pngFilename);
139
+                $this->portfolioPresenter->toImage($parsedPortfolio, $pngFilename);
139 140
                 $this->telegramNotifier->notify('', $pngFilename);
140 141
             }
141 142
 

Laden…
Annuleren
Opslaan