-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.php
41 lines (33 loc) · 1.12 KB
/
main.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
<?php
/**
* REQUIREMENT:
*
* Parse message board posts
*
* USAGE:
*
* []$ php main.php < data/posts.csv
*
* OUTPUT:
*
* 1. top_posts.csv will contain a list of top post id's, according to the rules below.
* 2. other_posts.csv will contain a list of remaining post id's.
* 3. daily_top_posts.csv will contain the single highest scoring top post of the day, based on likes.
*/
$time_start = microtime(true);
include_once dirname(__FILE__) . '/init.php';
$config = include_once ROOT . '/config.php';
// check if it's input file
if (isset($argv[1]) && is_file($argv[1]))
$filename = $argv[1];
else
echo 'Invalid input file. Usage: []$ php main.php /path/to/file' . PHP_EOL;
// configuarable output writer
$postWriter = new PostWriter($config['output_files']);
// if ($config['output_format'] == 'CSV')
$postWriter->setFormatter(new CSVFormatter);
$processer = new PostProcesser($filename, $postWriter);
$processer->run();
$time_end = microtime(true);
echo "PROCESS TIME: " . number_format($time_end - $time_start, 4) . PHP_EOL;
echo "MEMORY USAGED: " . memory_get_usage() . 'KB' . PHP_EOL;