Skip to content

Instantly share code, notes, and snippets.

@ahmedash95
Last active November 11, 2020 21:26
Show Gist options
  • Save ahmedash95/e13b898426efedd7e50f623c44fb8b34 to your computer and use it in GitHub Desktop.
Save ahmedash95/e13b898426efedd7e50f623c44fb8b34 to your computer and use it in GitHub Desktop.
Codeforces problems scrapper
<?php
$data = file_get_contents('https://codeforces.com/api/problemset.problems?tags=greedy');
$data = json_decode($data, true)['result']['problems'];
$out = collect($data)
->filter(function($row){
return isset($row['rating']) && $row['rating'] >= 500;
})
->sortBy('rating')
->map(function($row){
return [
'contest' => $row['contestId'].$row['index'],
'name' => $row['name'],
'rating' => $row['rating'],
'link' => "https://codeforces.com/contest/{$row['contestId']}/problem/{$row['index']}",
'tags' => implode(', ', $row['tags'])
];
})
->values()->toJson()
;
file_put_contents('/home/greedy.json', $out);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment