Browse Source

Merge pull request #1700 from visuddhinanda/agile

add tulip download pg dict
visuddhinanda 2 years ago
parent
commit
48824ca9e4
2 changed files with 50 additions and 0 deletions
  1. 1 0
      rpc/tulip/tulip/config.sample.php
  2. 49 0
      rpc/tulip/tulip/dict_maker.php

+ 1 - 0
rpc/tulip/tulip/config.sample.php

@@ -10,4 +10,5 @@ define("Config", [
         "user" => "postgres",
         "user" => "postgres",
         "password" => "123456",
         "password" => "123456",
     ],
     ],
+    'api_server' => 'http://127.0.0.1:8000/api',
 ]);
 ]);

+ 49 - 0
rpc/tulip/tulip/dict_maker.php

@@ -0,0 +1,49 @@
+<?php
+require dirname(__FILE__) . '/vendor/autoload.php';
+require dirname(__FILE__) . '/config.php';
+
+$dir = dirname(__FILE__) . '/storage';
+if(!is_dir($dir)){
+    $res = mkdir($dir,0700,true);
+    if(!$res){
+        echo "error: mkdir fail path=".$dir;
+        return 0;
+    }
+}
+$filename = $dir.'/pali-'.date("Y-m-d-h-i-sa").'.syn';
+$fp = fopen($filename,'a');
+if(!$fp){
+    echo "open file fail filename=".$filename;
+    return 0;
+}
+$client = new GuzzleHttp\Client();
+$currPage = 1;
+
+    $urlBase = Config['api_server'] . '/v2/pg-pali-dict-download';
+    echo $urlBase.PHP_EOL;
+    do {
+        $goNext = false;
+        $url = $urlBase . "?page={$currPage}";
+        echo $url.PHP_EOL;
+        $res = $client->request('GET', $url);
+        $status = $res->getStatusCode();
+        if($status === 200){
+            $json = json_decode($res->getBody());
+            if($json->ok){
+                $content = $json->data;
+                echo strlen($content).PHP_EOL;
+                fwrite($fp,$content."\n");
+                $goNext = true;
+            }else{
+                echo 'all done';
+            }
+        }else{
+            echo 'error:'.$status;
+        }
+        $currPage++;
+    } while ($goNext);
+    
+fclose($fp);
+echo 'all done filename='.$filename;
+
+