Skip to content

Instantly share code, notes, and snippets.

@deekayen
Created October 12, 2013 17:47
Show Gist options
  • Save deekayen/6952792 to your computer and use it in GitHub Desktop.
Save deekayen/6952792 to your computer and use it in GitHub Desktop.
Scrape user statistics from drupal.org.
<?php
function curl_request($url) {
$curl_version = curl_version();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; en-US) PHP/' . phpversion() . ' cURL/' . $curl_version['version'] . ' deekayen/1.0');
return curl_exec($ch);
}
function fetch_total_commits($uid) {
$scrape = curl_request('https://drupal.org/user/' . $uid);
preg_match('/Total: (\d+) commits/', $scrape, $matches);
if (isset($matches[1])) {
return $matches[1];
}
else {
return FALSE;
}
}
if ($return = fetch_total_commits('972')) {
echo $return;
}
function fetch_total_posts($uid) {
$scrape = curl_request('https://drupal.org/user/' . $uid . '/track');
preg_match('/track\?page=(\d+)\" title=\"Go to last/', $scrape, $matches);
if (isset($matches[1])) {
return $matches[1];
}
else {
return FALSE;
}
}
if ($return = fetch_total_posts('972')) {
echo $return * 25;
}
function fetch_uid_by_name($name) {
$scrape = curl_request('https://drupal.org/search/user_search/' . $name);
preg_match('/drupal\.org\/user\/(\d+)">' . $name . '<\/a>/', $scrape, $matches);
if (isset($matches[1])) {
return $matches[1];
}
else {
return FALSE;
}
}
if ($return = fetch_uid_by_name('deekayen')) {
echo $return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment