Skip to content

Instantly share code, notes, and snippets.

@jimyhuang
Last active August 31, 2015 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimyhuang/2dfd82cb724075247999 to your computer and use it in GitHub Desktop.
Save jimyhuang/2dfd82cb724075247999 to your computer and use it in GitHub Desktop.
company-relation
<?php
$BASE = "/mnt/tmp";
$line = file_get_contents("$BASE/tmpline");
preg_match("/^\d+,/", $line, $matches);
$id_dest = trim($matches[0], ',');
$line = str_replace($matches[0], '', $line);
$meta = json_decode($line, TRUE);
$name_dest = $meta['公司名稱'];
$board = $rows = array();
foreach($meta['董監事名單'] as $k => $m){
$row = NULL;
if(!empty($m['所代表法人'])){
$c = $m['所代表法人'];
if($m['出資額']){
$money = ''.str_replace(',', '', $m['出資額']);
}
else{
$money = 'NULL';
}
$board[$c[1]][$k] = $m['姓名'];
if(empty($c[0])){
$id_source = 'NULL';
}
else{
$id_source = $c[0];
}
$name_source = $c[1];
$rows[$c[1]] = array(
$id_source,
$name_source,
$id_dest,
$name_dest,
implode('|', $board[$c[1]]),
$money,
);
}
}
foreach($rows as $r){
$output = implode(",", $r)."\n";
file_put_contents("$BASE/result.csv", $output, FILE_APPEND);
}
#! /bin/bash
BASE="/mnt/tmp"
COMPANY="company.json"
echo "source,source name,target,target name,board member,money" > $BASE/result.csv
grep -r "所代表法人\":\[" $BASE/company.json > $BASE/filter.json
while IFS='' read -r line || [[ -n "$line" ]]; do
echo "$line" > $BASE/tmpline
php ./company-relation-line.php
done < "$BASE/filter.json"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment