-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaddLikes.php
61 lines (54 loc) · 2.14 KB
/
addLikes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
require_once 'data/defines.php';
$doc = new DOMDocument();
$doc->loadHTML(file_get_contents("data/fav.html"));
$tables = $doc->getElementsByTagName('table');
$finder = new DomXPath($doc);
$classname = "problems";
$nodes = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' $classname ')]");
$finder = new DomXPath($doc);
$problemIds = array();
$classname = "id left";
$problemsTd = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' $classname ')]");
foreach ($problemsTd as $problemTd) {
array_push($problemIds, trim($problemTd->nodeValue));
}
$classname = "id dark left";
$problemsTd = $finder->query("//*[contains(concat(' ', normalize-space(@class), ' '), ' $classname ')]");
foreach ($problemsTd as $problemTd) {
array_push($problemIds, trim($problemTd->nodeValue));
}
$problemIds = array_unique($problemIds);
$allProblemsArray = json_decode(file_get_contents("https://codeforces.com/api/problemset.problems"), true)['result'];
$allProblems = array();
foreach ($allProblemsArray['problems'] as $problem) {
$allProblems[$problem['contestId'] . $problem['index']] = $problem;
}
foreach ($allProblemsArray['problemStatistics'] as $problem) {
$allProblems[$problem['contestId'] . $problem['index']]['solvedCount']['solvedCount'] = $problem;
}
problemset::readFromFile();
echo "all problems downloaded\n";
echo "processing likes...\n";
$newProblemsCount = 0;
$likedProblemsCount = 0;
foreach ($problemIds as $problemId) {
if (!isset(problemset::$problems[$problemId])) {
if (!isset($allProblems[$problemId]) || !isset($allProblems[$problemId]["tags"]) || !isset($allProblems[$problemId]["rating"])) {
continue;
}
$problem = $allProblems[$problemId];
$newProblemsCount++;
problemset::addProblem(
$problemId,
$problem["tags"],
$problem["rating"],
0, false, 0, 0, null, true);
}
$likedProblemsCount++;
problemset::addUserLiked(strtolower('shayan.p'), $problemId, true);
}
echo "$newProblemsCount new problems added to problemset\n";
echo $likedProblemsCount . " problems liked\n";
problemset::update();
?>