Created
May 10, 2012 16:08
-
-
Save nfreear/2654151 to your computer and use it in GitHub Desktop.
Parse the OU Drupal supported modules Wiki page, and extract project names and hopefully Git tags
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 | |
| /** | |
| * Parse the OU Drupal supported modules Wiki page, and extract project names and hopefully Git tags. | |
| * | |
| * $ git tag -l "6.x-2.*" | |
| * | |
| * N.D.Freear, 2012-05-10. | |
| */ | |
| $url = 'http://www.open.ac.uk/wikis/drupal/Drupal_supported_modules_(6.21)'; | |
| $url_raw = 'http://www.open.ac.uk/wikis/drupal/index.php?title=Drupal_supported_modules_(6.21)&action=raw'; | |
| $res = _http_request_curl($url_raw); | |
| $ouput = $human = ''; | |
| $describe = array(); | |
| if (preg_match('#Alphabetical.+?Version.+?\|-(.+)#ms', $res->data, $matches_outer)) { | |
| #var_dump($matches_outer); | |
| $data = $matches_outer[1]; | |
| if (preg_match_all('#\|([\w ]+?)\s\|(http:.+?)\s\|(6.\w-[\w-.]+)#ms', $data, $matches, PREG_SET_ORDER)) { | |
| #var_dump(count($matches), $matches); | |
| foreach ($matches as $record) { | |
| $label = trim($record[1]); | |
| $url = $record[2]; | |
| $tag = $record[3]; | |
| $version = preg_replace('/.*-([\d\.x]{3,5}).*/', "$1", $tag); | |
| $project = NULL; #$label; | |
| if (preg_match('#.org\/project\/(.+)#', $url, $matches_url)) { | |
| $project = $matches_url[1]; | |
| } | |
| if ($project) { | |
| $ouput .= "$project,$tag".PHP_EOL; | |
| $human .= "$label\t$project\t$tag\t$url".PHP_EOL; | |
| $describe[] = (object) array( | |
| 'project' => $project, | |
| 'tag' => $tag, | |
| 'version' => $version, | |
| ); | |
| } | |
| } | |
| } | |
| } | |
| var_dump($describe); | |
| /** Perform the HTTP request using cURL. | |
| */ | |
| function _http_request_curl($url, $spoof=false, $options=array()) { | |
| if (!function_exists('curl_init')) die('Error, cURL is required.'); | |
| $result = (object)array(); | |
| $h_curl = curl_init($url); | |
| #curl_setopt($h_curl, CURLOPT_USERAGENT, $options['ua']); | |
| if (!$spoof) { | |
| #curl_setopt($h_curl, CURLOPT_REFERER, base_url()); | |
| } | |
| if (isset($options['cookie'])) { | |
| curl_setopt($h_curl, CURLOPT_COOKIE, $options['cookie']); | |
| header('X-Proxy-Cookie: '.$options['cookie']); | |
| } | |
| curl_setopt($h_curl, CURLOPT_AUTOREFERER, TRUE); | |
| #curl_setopt($h_curl, CURLOPT_MAXREDIRS, $options['max_redirects']); | |
| curl_setopt($h_curl, CURLOPT_FOLLOWLOCATION, TRUE); | |
| #curl_setopt($h_curl, CURLOPT_TIMEOUT, $options['timeout']); | |
| $http_proxy = 'wwwcache.open.ac.uk:80'; #$this->CI->config->item('http_proxy'); | |
| if ($http_proxy) { | |
| curl_setopt($h_curl, CURLOPT_PROXY, $http_proxy); | |
| } | |
| curl_setopt($h_curl, CURLOPT_RETURNTRANSFER, TRUE); | |
| $result->data = curl_exec($h_curl); | |
| if ($errno = curl_errno($h_curl)) { | |
| //Error. Quietly log? | |
| $this->CI->_log('error', "cURL $errno, ".curl_error($h_curl)." GET $url"); | |
| #$this->CI->firephp->fb("cURL $errno", "cURL error", "ERROR"); | |
| } | |
| $result->info = curl_getinfo($h_curl); | |
| $result->success = ($result->info['http_code'] < 300); | |
| return (object) $result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment