Przeglądaj źródła

moved securities map from class constant to .env

master
Evgeniy Ierusalimov 11 miesięcy temu
rodzic
commit
8158dd9e4a

+ 2
- 0
.env Wyświetl plik

40
 
40
 
41
 TELEGRAM_BOT_TOKEN=
41
 TELEGRAM_BOT_TOKEN=
42
 TELEGRAM_CHAT_ID=
42
 TELEGRAM_CHAT_ID=
43
+
44
+SECURITIES_MAP='{"RU000A1014L8":"LQDT", "RU000A107UL4":"T", "RU000A108X38":"X5"}'

+ 1
- 0
README.md Wyświetl plik

9
 NB:
9
 NB:
10
 Do not forget to remove `var/imap/attachments/*.bin` files after
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 Wyświetl plik

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

+ 1
- 4
src/Command/FetchEmailsCommand.php Wyświetl plik

14
 )]
14
 )]
15
 class FetchEmailsCommand extends Command
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
         parent::__construct();
19
         parent::__construct();
22
-        $this->mailFetcher = $mailFetcher;
23
     }
20
     }
24
 
21
 
25
     protected function execute(InputInterface $input, OutputInterface $output): int
22
     protected function execute(InputInterface $input, OutputInterface $output): int

+ 7
- 7
src/Command/ImportFromXmlCommand.php Wyświetl plik

2
 
2
 
3
 namespace App\Command;
3
 namespace App\Command;
4
 
4
 
5
-use App\Presentation\PortfolioPresenter as PresentationPortfolio;
5
+use App\Presentation\PortfolioPresenter;
6
 use App\Service\TelegramNotifier;
6
 use App\Service\TelegramNotifier;
7
 use App\Service\XmlParser;
7
 use App\Service\XmlParser;
8
 use Symfony\Component\Console\Attribute\AsCommand;
8
 use Symfony\Component\Console\Attribute\AsCommand;
20
 class ImportFromXmlCommand extends Command
20
 class ImportFromXmlCommand extends Command
21
 {
21
 {
22
     public function __construct(
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
         parent::__construct();
28
         parent::__construct();
32
         $this
33
         $this
33
             //->addArgument('xml-file', null, InputArgument::REQUIRED, 'XML file with portfolio data')
34
             //->addArgument('xml-file', null, InputArgument::REQUIRED, 'XML file with portfolio data')
34
             ->addOption('xml-file', null, InputOption::VALUE_REQUIRED, 'XML file with Portfolio data')
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
     protected function execute(InputInterface $input, OutputInterface $output): int
39
     protected function execute(InputInterface $input, OutputInterface $output): int
49
         $xml = simplexml_load_string($xmlString);
49
         $xml = simplexml_load_string($xmlString);
50
 
50
 
51
         $parsedPortfolio = $this->xmlParser->processXml($xml);
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
         if ($input->getOption('notify')) {
55
         if ($input->getOption('notify')) {
56
             $this->telegramNotifier->notify('', 'portfolio.png');
56
             $this->telegramNotifier->notify('', 'portfolio.png');

+ 11
- 9
src/Presentation/PortfolioPresenter.php Wyświetl plik

9
 
9
 
10
 class PortfolioPresenter
10
 class PortfolioPresenter
11
 {
11
 {
12
-    private const SecurityMapPrint = [
13
-        ['RU000A1014L8', 'RU000A107UL4', '(в пути)'], ['LQDT', 'T', '±'],
14
-    ];
15
-
16
     private const FONT_SIZE = 12;
12
     private const FONT_SIZE = 12;
17
     private const FONT_NAME = 'droid_sans_mono';
13
     private const FONT_NAME = 'droid_sans_mono';
18
     private const COPYRIGHT_MARK = ' ©ЕИ';
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
     public function toImage(ParsedPortfolio $parsedPortfolio, string $filename): void
24
     public function toImage(ParsedPortfolio $parsedPortfolio, string $filename): void
23
     {
25
     {
118
 
120
 
119
     private function getPrintableSecurityTitle(array $security): string
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
         if (!str_starts_with($security['ЦБ'], 'RU00')) {
125
         if (!str_starts_with($security['ЦБ'], 'RU00')) {
124
             return $security['ЦБ'];
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
         if (!isset($security['Эмитент'])) {
133
         if (!isset($security['Эмитент'])) {
133
         }
135
         }
134
 
136
 
135
         $title = str_replace(['МКПАО', 'ПАО', '"', ' ', '(', ')'], ['', '', '', '', '', ''], $security['Эмитент']);
137
         $title = str_replace(['МКПАО', 'ПАО', '"', ' ', '(', ')'], ['', '', '', '', '', ''], $security['Эмитент']);
136
-        $this->MapSecuritiesPrintable[$security['ЦБ']] = $title;
138
+        $this->mapSecurityTitle[$security['ЦБ']] = $title;
137
 
139
 
138
         return $title;
140
         return $title;
139
     }
141
     }

+ 3
- 2
src/Service/MailFetcher.php Wyświetl plik

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

Ładowanie…
Anuluj
Zapisz