Bläddra i källkod

压缩添加参数id

visuddhinanda 1 år sedan
förälder
incheckning
e348b7730c

+ 33 - 26
api-v8/app/Console/Commands/ExportAiTrainingData.php

@@ -43,8 +43,8 @@ class ExportAiTrainingData extends Command
     public function handle()
     {
         Log::debug('task export offline sentence-table start');
-        $filename = 'wikipali-offline-ai-training-'.date("Y-m-d").'.tsv';
-        $exportFile = storage_path('app/public/export/offline/'.$filename);
+        $filename = 'wikipali-offline-ai-training-' . date("Y-m-d") . '.tsv';
+        $exportFile = storage_path('app/public/export/offline/' . $filename);
         $fp = fopen($exportFile, 'w');
         if ($fp === false) {
             die('无法创建文件');
@@ -55,41 +55,48 @@ class ExportAiTrainingData extends Command
         ];
         $start = time();
         foreach ($channels as $key => $channel) {
-            $db = Sentence::where('channel_uid',$channel);
+            $db = Sentence::where('channel_uid', $channel);
             $bar = $this->output->createProgressBar($db->count());
-            $srcDb = $db->select(['book_id','paragraph',
-                                    'word_start','word_end',
-                                    'content','content_type'])->cursor();
+            $srcDb = $db->select([
+                'book_id',
+                'paragraph',
+                'word_start',
+                'word_end',
+                'content',
+                'content_type'
+            ])->cursor();
             foreach ($srcDb as $sent) {
-                $content = MdRender::render($sent->content,
-                                [$channel],
-                                null,
-                                'read',
-                                'translation',
-                                $sent->content_type,
-                                'text',
-                                );
-                $origin = PaliSentence::where('book',$sent->book_id)
-                                        ->where('paragraph',$sent->paragraph)
-                                        ->where('word_begin',$sent->word_start)
-                                        ->where('word_end',$sent->word_end)
-                                        ->value('text');
+                $content = MdRender::render(
+                    $sent->content,
+                    [$channel],
+                    null,
+                    'read',
+                    'translation',
+                    $sent->content_type,
+                    'text',
+                );
+                $origin = PaliSentence::where('book', $sent->book_id)
+                    ->where('paragraph', $sent->paragraph)
+                    ->where('word_begin', $sent->word_start)
+                    ->where('word_end', $sent->word_end)
+                    ->value('text');
                 $currData = array(
                     $origin,
                     str_replace("\n", "", $content),
-                    );
+                );
 
-                fwrite($fp, implode("\t", $currData)."\n");
+                fwrite($fp, implode("\t", $currData) . "\n");
 
                 $bar->advance();
             }
         }
         fclose($fp);
-        $this->info((time() - $start).' seconds');
-        $this->call('export:zip',[
-            'filename'=>$filename,
-            'title' => 'wikipali ai training data',
-            'format'=> $this->option('format'),
+        $this->info((time() - $start) . ' seconds');
+        $this->call('export:zip', [
+            'id' => 'ai-translating-training-data',
+            'filename' => $filename,
+            'title' => 'wikipali ai translating training data',
+            'format' => $this->option('format'),
         ]);
         return 0;
     }

+ 28 - 26
api-v8/app/Console/Commands/ExportOffline.php

@@ -42,30 +42,30 @@ class ExportOffline extends Command
      */
     public function handle()
     {
-        if(\App\Tools\Tools::isStop()){
+        if (\App\Tools\Tools::isStop()) {
             return 0;
         }
         $exportDir = storage_path('app/public/export/offline');
-        if(!is_dir($exportDir)){
-            $res = mkdir($exportDir,0755,true);
-            if(!$res){
-                Log::error('mkdir fail path='.$exportDir);
+        if (!is_dir($exportDir)) {
+            $res = mkdir($exportDir, 0755, true);
+            if (!$res) {
+                Log::error('mkdir fail path=' . $exportDir);
                 return 1;
             }
         }
 
         //清空redis
-        RedisClusters::put('/offline/index',[]);
+        RedisClusters::put('/offline/index', []);
 
         //删除全部的旧文件
         foreach (scandir($exportDir) as $key => $file) {
-            if(is_file($exportDir.'/'.$file)){
-                unlink($exportDir.'/'.$file);
+            if (is_file($exportDir . '/' . $file)) {
+                unlink($exportDir . '/' . $file);
             }
         }
         //添加 .stop
-        $exportStop = $exportDir.'/.stop';
-        $file = fopen($exportStop,'w');
+        $exportStop = $exportDir . '/.stop';
+        $file = fopen($exportStop, 'w');
         fclose($file);
 
         //建表
@@ -78,42 +78,44 @@ class ExportOffline extends Command
 
         //导出channel
         $this->info('export channel start');
-        $this->call('export:channel',['db'=>'wikipali-offline']);
-        $this->call('export:channel',['db'=>'wikipali-offline-index']);
+        $this->call('export:channel', ['db' => 'wikipali-offline']);
+        $this->call('export:channel', ['db' => 'wikipali-offline-index']);
 
-        if(!$this->option('shortcut')){
+        if (!$this->option('shortcut')) {
             //tag
             $this->info('export tag start');
-            $this->call('export:tag',['db'=>'wikipali-offline']);
-            $this->call('export:tag.map',['db'=>'wikipali-offline']);
+            $this->call('export:tag', ['db' => 'wikipali-offline']);
+            $this->call('export:tag.map', ['db' => 'wikipali-offline']);
             //
             $this->info('export pali text start');
             $this->call('export:pali.text');
             //导出章节索引
             $this->info('export chapter start');
-            $this->call('export:chapter.index',['db'=>'wikipali-offline']);
-            $this->call('export:chapter.index',['db'=>'wikipali-offline-index']);
+            $this->call('export:chapter.index', ['db' => 'wikipali-offline']);
+            $this->call('export:chapter.index', ['db' => 'wikipali-offline-index']);
             //导出译文
             $this->info('export sentence start');
-            $this->call('export:sentence',['--type'=>'translation','--driver'=>$this->option('driver')]);
-            $this->call('export:sentence',['--type'=>'nissaya','--driver'=>$this->option('driver')]);
+            $this->call('export:sentence', ['--type' => 'translation', '--driver' => $this->option('driver')]);
+            $this->call('export:sentence', ['--type' => 'nissaya', '--driver' => $this->option('driver')]);
             //导出原文
-            $this->call('export:sentence',['--type'=>'original','--driver'=>$this->option('driver')]);
+            $this->call('export:sentence', ['--type' => 'original', '--driver' => $this->option('driver')]);
         }
 
         $this->info('zip');
         Log::info('export offline: db写入完毕 开始压缩');
 
         sleep(5);
-        $this->call('export:zip',[
-            'filename'=>'wikipali-offline-index'.'-'.date("Y-m-d").'.db3',
+        $this->call('export:zip', [
+            'id' => 'index',
+            'filename' => 'wikipali-offline-index' . '-' . date("Y-m-d") . '.db3',
             'title' => 'wikipali 离线包索引',
-            'format'=>$this->argument('format'),
+            'format' => $this->argument('format'),
         ]);
-        $this->call('export:zip',[
-            'filename'=>'wikipali-offline'.'-'.date("Y-m-d").'.db3',
+        $this->call('export:zip', [
+            'id' => 'date-package',
+            'filename' => 'wikipali-offline' . '-' . date("Y-m-d") . '.db3',
             'title' => 'wikipali 离线包',
-            'format'=>$this->argument('format'),
+            'format' => $this->argument('format'),
         ]);
 
         $this->call('export:ai.training.data');

+ 2 - 1
api-v8/app/Console/Commands/ExportZip.php

@@ -18,7 +18,7 @@ class ExportZip extends Command
      *
      * @var string
      */
-    protected $signature = 'export:zip {filename : filename} {title : title} {format?  : zip file format 7z,lzma,gz }';
+    protected $signature = 'export:zip {filename : filename} {title : title} {id : 标识符} {format?  : zip file format 7z,lzma,gz }';
 
     /**
      * The console command description.
@@ -167,6 +167,7 @@ class ExportZip extends Command
             $info = array();
         }
         $info[] = [
+            'id' => $this->argument('id'),
             'title' => $this->argument('title'),
             'filename' => $zipFile,
             'url' => $url,