-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.php
77 lines (61 loc) · 1.36 KB
/
convert.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
$start = (int)file_get_contents('start');
if ( !$start ) die('failed to determine start');
$counter = 0;
$remainder = null;
$lastPath = '';
$lastData = '';
$line = '';
$fIn = fopen('nrjfeed.archive.logson','r');
$fOut = null;
while ( true ) {
$counter++;
$line = fgets($fIn);
if ( $line === false ) break;
$line = trim($line);
$data = json_decode($remainder.$line);
if ( !$data ) {
if ( $remainder != '' ) {
echo "\nfailed on line $counter";
break;
}
$remainder = $line;
continue;
}
$remainder = '';
if ( $lastData && $lastData[0] != ($data[0] - 1) ) {
echo "\ngap on line $counter: {$lastData[0]} => $data[0]";
}
list($idx,$milli,$times) = $data;
$ts = $start+($milli/1000);
$path = 'feed/'
.date('Y',$ts).'.'
.date('m',$ts).'.'
.date('d',$ts).'.json'
;
$post = array(
'idx'=>$idx,
'ts'=>$ts,
'milli'=>$milli,
'times'=>$times
);
if ( $fOut && $path != $lastPath ){
fwrite($fOut, "\n".']');
fclose($fOut);
}
if ( !$lastPath || $path != $lastPath ){
echo "\n".$path;
$fOut = fopen($path, 'w');
fwrite($fOut, '['."\n".json_encode($post));
} else {
fwrite($fOut, ','."\n".json_encode($post));
}
$line = '';
$lastPath = $path;
$lastData = $data;
}
if ( $fOut ) {
fwrite($fOut, "\n".']');
fclose($fOut);
}
fclose($fIn);