Created
October 12, 2013 17:47
-
-
Save deekayen/6952792 to your computer and use it in GitHub Desktop.
Scrape user statistics from drupal.org.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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