Created
February 10, 2016 18:45
-
-
Save cebe/be156b99a3957447aaa0 to your computer and use it in GitHub Desktop.
Script for fetching all google code download files for migration.
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 downloadfiles($url) | |
{ | |
$json = file_get_contents($url); | |
if (!$json) { | |
return false; | |
} | |
//print_r(json_decode($json)); | |
$data = json_decode($json); | |
foreach($data->downloads as $d) { | |
$url = downUrl($d->filename); | |
echo "downloading {$d->filename}..."; | |
if ($cont = file_get_contents($url)) { | |
file_put_contents("files/{$d->filename}", $cont); | |
file_put_contents("files/{$d->filename}.info.json", json_encode($d, JSON_PRETTY_PRINT)); | |
echo "done.\n"; | |
} else { | |
echo "FAILED!\n"; | |
} | |
} | |
return true; | |
} | |
function downUrl($file) | |
{ | |
return 'https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/yii/' . $file; | |
} | |
mkdir('files', 0755, true); | |
$page = 1; | |
do { | |
$url = 'https://www.googleapis.com/storage/v1/b/google-code-archive/o/v2%2Fcode.google.com%2Fyii%2Fdownloads-page-'.$page.'.json?alt=media&stripTrailingSlashes=false'; | |
++$page; | |
} while(downloadfiles($url)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment