Skip to content

Instantly share code, notes, and snippets.

@ronnywang
Created December 6, 2019 06:05
Show Gist options
  • Save ronnywang/e11231c24cee7549cddb6deddf999bf4 to your computer and use it in GitHub Desktop.
Save ronnywang/e11231c24cee7549cddb6deddf999bf4 to your computer and use it in GitHub Desktop.
<?php
// download fb-ad.jsonl
// php fb-ad-to-csv.php > output.csv
$fp = fopen('fb-ad.jsonl', 'r');
$output = fopen('php://output', 'w');
fputs($output, "選區,參選人,AD_ID,登錄為政治廣告,開始日期,結束日期,廣告內容,曝光\n");
while ($line = fgets($fp)) {
$obj = json_decode($line);
@fputcsv($output, array(
$obj->{'選區'},
$obj->{'參選人'},
$obj->{'AD_ID'},
$obj->{'登錄為政治廣告'},
$obj->{'開始日期'},
$obj->{'結束日期'},
$obj->{'廣告內容'},
$obj->{'廣告詳情'}->impressions->lower_bound,
$obj->{'廣告詳情'}->impressions->upper_bound,
$obj->{'廣告詳情'}->spend->lower_bound,
$obj->{'廣告詳情'}->spend->upper_bound,
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment