We follow the vote on "Russia 10"

Like many Russians, recently I visit every day to vote on the site 10russia.ru . If someone does not know, Russia 10 is an all-Russian project in which everyone can vote for their favorite geographical or architectural object in Russia. The objective of the project is the selection of ten new visual symbols of Russia.
The numbers in TOP2 in the voting seemed strange to me, and I decided to see how they change. There was little time, and whipped up a small parser that saves every 2-3 seconds data on the number of votes on the site and SMS. To display this data, I created a site (The design and the basis of the schedule were taken from here habrahabr.ru/post/176547. I hope the author will not mind). I didn’t want to spend money, but I had only a weak personal VDS at my disposal, which would quickly go down if the data were generated dynamically. Therefore, it was decided to do with static html and generate json files on the crown. It will be interesting to see what load VDS can withstand without changing the current configuration (CPU 300MHz, RAM 128 Mb), given that there are two small services and one low-visited site. At the end of the voting, I will post, if anyone needs it, all the voting data received.

Parser listing


([^<]+)/iu', $html, $match) ) {
        $site = (int)str_replace(' ', '', $match[1]);
    }
    if( preg_match('/([^<]+)/iu', $html, $match) ) {
        $sms = (int)str_replace(' ', '', $match[1]);
    }
    if($site && $sms) {
        $all = $sms + $site;
        mysql_query("INSERT INTO stat(`key`, sms, site, `all`) VALUES('$key', $sms, $site, $all)");
    }
}
$urls = array(
    'object_31' => 'http://10russia.ru/object_31',
    'object_61' => 'http://10russia.ru/object_61'
);
while(true) {
    foreach($urls as $key => $url) {
        try {
            $result = file_get_contents($url);
            addNewData($result, $key);
            sleep(1);
        } catch(Exception $e) {}
    }
}


Listing script to create json files by crown


 'object31.json',
    'object_61' => 'object61.json'
);
foreach($keys as $key => $file) {
    $filename = dirname(__FILE__) . '/' . $file . '.tmp';
    $fLink = fopen($filename, 'w');
    if($fLink) {
        $result = mysql_query("SELECT `date`, `all` FROM stat WHERE `key`='$key' ORDER BY id ASC");
        fwrite($fLink, "[\n");
        $row = mysql_fetch_assoc($result);
        $first = true;
        do {
            $str = '';
            if(!$first){
                $str = ",";
            } else {
                $first = false;
            }
            fwrite($fLink, $str . '['.strtotime($row['date']) . "000,{$row['all']}]" );
        } while($row = mysql_fetch_assoc($result));
        fwrite($fLink, "]");
        fclose($fLink);
        rename($filename, dirname(__FILE__) . '/' . $file);
    }
}

An interesting point is that I first generate a .tmp file, and then I overwrite the file generated an hour ago, thereby avoiding the situation when the file does not exist or is not fully generated.

Interesting points on the charts


Maximum growth in 30 minutes.
Maximum growth in 30 minutes

Overall dynamics for the whole monitoring time.
The overall dynamics for the entire monitoring period

VGTRK


I hope that I did not create big problems for you, given the great popularity of the project, you, I think, were ready for a large flow of visitors. By the way, if anyone is looking for a system administrator in Moscow, then the creators of the site are looking for employees, not in an entirely original, but rare way:
Work

References


See what I did, get acquainted with the detailed statistics of the vote and draw conclusions: http://10russia.miningdata.ru/

Also popular now: