3 for ($iTimestamp = mktime(0, 0, 0, 5, 1, 2013); $iTimestamp < mktime(0, 0, 0, 6, 15, 2013); $iTimestamp += 24*60*60) {
4 $sYear = date('Y', $iTimestamp);
5 $sMonth = date('Y-m', $iTimestamp);
6 $sDay = date('Ymd', $iTimestamp);
8 for ($iHour = 0; $iHour < 24; $iHour++) {
9 $sFilename = sprintf('pagecounts-'.$sDay.'-%02d0000', $iHour);
11 if (!file_exists($sFilename.'.gz')) {
12 exec('wget http://dumps.wikimedia.org/other/pagecounts-raw/'.$sYear.'/'.$sMonth.'/'.$sFilename.'.gz');
15 exec('gzip -dc '.$sFilename.'.gz'.' | grep -e "^[a-z]\{2\} [^ :]\+ [0-9]\+" > hour.txt');
17 $hPrevTotals = @fopen('totals.txt', 'r');
18 $hDayTotals = @fopen('hour.txt', 'r');
19 $hNewTotals = @fopen('newtotals.txt', 'w');
21 $sPrevKey = $sDayKey = true;
26 if ($sPrevKey === $sDayKey) {
27 if ($sPrevLine !== true) fputs($hNewTotals, "$sPrevKey ".($iPrevValue+$iDayValue)."\n");
30 } elseif ($sDayKey !== false && ($sPrevKey > $sDayKey || $sPrevKey === false)) {
31 fputs($hNewTotals, "$sDayKey ".($iDayValue)."\n");
33 } elseif ($sPrevKey !== false && ($sDayKey > $sPrevKey || $sDayKey === false)) {
34 fputs($hNewTotals, "$sPrevKey ".($iPrevValue)."\n");
38 if ($sPrevLine === true) {
39 $sPrevLine = $hPrevTotals?fgets($hPrevTotals, 4096):false;
40 if ($sPrevLine !== false) {
41 $aPrevLine = explode(' ', $sPrevLine);
42 $sPrevKey = $aPrevLine[0].' '.$aPrevLine[1];
43 $iPrevValue = (int)$aPrevLine[2];
50 if ($sDayLine === true) {
51 $sDayLine = $hDayTotals?fgets($hDayTotals, 4096):false;
52 if ($sDayLine !== false) {
53 preg_match('#^([a-z]{2}) ([^ :]+) ([0-9]+) [0-9]+$#', $sDayLine, $aMatch);
54 $sDayKey = $aMatch[1].' '.$aMatch[2];
55 $iDayValue = (int)$aMatch[3];
61 } while ($sPrevLine !== false || $sDayLine !== false);
63 @fclose($hPrevTotals);
67 @unlink('totals.txt');
68 rename('newtotals.txt', 'totals.txt');
74 gzip -dc $FILE.gz | grep -e "^en [^ :]\+ [0-9]\+" |
75 sed "s#\(^[a-z]\{2\}\) \([^ :]\+\) \([0-9]\+\) [0-9]\+#update wikipedia_article set hit_count = coalesce(hit_count,0) + \3 where language = '\1'
76 and title = catch_decode_url_part('\2');#g" | /opt/mapquest/stdbase-dev$
77 cat totals.txt | sed "s#\(^[a-z]\{2\}\) \([^ ]\+\) \([0-9]\+\)\$#update entity_link set hits = s,0) + \3 where target = '\1wiki' and value = catch_decode_url_part('\2');#g"
78 cat totals.txt | sed "s#\(^[a-z]\{2\}\) \([^ ]\+\) \([0-9]\+\)\$#update entity_link set hits = coalesce(hits,0) + \3 where target = '\1wiki' and value = catch_decode_url_part('\2');#g"