mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Stepic now paginates it's output
This commit is contained in:
@@ -142,14 +142,11 @@ public class EduStepicConnector {
|
||||
public static List<CourseInfo> getCourses() {
|
||||
try {
|
||||
List<CourseInfo> result = new ArrayList<CourseInfo>();
|
||||
final List<CourseInfo> courseInfos = getFromStepic("courses", CoursesContainer.class).courses;
|
||||
for (CourseInfo info : courseInfos) {
|
||||
final String courseType = info.getType();
|
||||
if (StringUtil.isEmptyOrSpaces(courseType)) continue;
|
||||
final List<String> typeLanguage = StringUtil.split(courseType, " ");
|
||||
if (typeLanguage.size() == 2 && PYCHARM_PREFIX.equals(typeLanguage.get(0))) {
|
||||
result.add(info);
|
||||
}
|
||||
int pageNumber = 0;
|
||||
boolean hasNext = addCoursesFromStepic(result, pageNumber);
|
||||
while (hasNext) {
|
||||
pageNumber += 1;
|
||||
hasNext = addCoursesFromStepic(result, pageNumber);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -159,6 +156,21 @@ public class EduStepicConnector {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private static boolean addCoursesFromStepic(List<CourseInfo> result, int pageNumber) throws IOException {
|
||||
final String url = pageNumber == 0 ? "courses" : "courses?page=" + String.valueOf(pageNumber);
|
||||
final CoursesContainer coursesContainer = getFromStepic(url, CoursesContainer.class);
|
||||
final List<CourseInfo> courseInfos = coursesContainer.courses;
|
||||
for (CourseInfo info : courseInfos) {
|
||||
final String courseType = info.getType();
|
||||
if (StringUtil.isEmptyOrSpaces(courseType)) continue;
|
||||
final List<String> typeLanguage = StringUtil.split(courseType, " ");
|
||||
if (typeLanguage.size() == 2 && PYCHARM_PREFIX.equals(typeLanguage.get(0))) {
|
||||
result.add(info);
|
||||
}
|
||||
}
|
||||
return coursesContainer.meta.containsKey("has_next") && coursesContainer.meta.get("has_next") == Boolean.TRUE;
|
||||
}
|
||||
|
||||
public static Course getCourse(@NotNull final CourseInfo info) {
|
||||
final Course course = new Course();
|
||||
course.setAuthors(info.getInstructors());
|
||||
@@ -337,6 +349,7 @@ public class EduStepicConnector {
|
||||
|
||||
private static class CoursesContainer {
|
||||
public List<CourseInfo> courses;
|
||||
public Map meta;
|
||||
}
|
||||
|
||||
static class StepSourceWrapper {
|
||||
|
||||
Reference in New Issue
Block a user