コード例 #1
0
 @Override
 public boolean anyClassThisSchoolYear(SchoolYear schoolYear) {
   return ClassSchedule.count(
           ClassSchedule.class, "semester = ?", new String[] {schoolYear.toString()})
       > 0;
 }
コード例 #2
0
  public void sync() throws SyncFailedException {
    try {
      String html = classesPage.getHtml();
      classesPage.checkDataAvailable(html);

      int pos = SyncDataHelper.getIndexAndGoToEnd("Letivo:", html);
      int endPos = SyncDataHelper.getIndexOf("<", html, pos);

      actualSchoolYear = new SchoolYear(html.substring(pos, endPos).trim());
      if (actualSchoolYear.isBefore(SchoolYear.getCurrent())) {
        throw new UnavailableDataException(
            "Você não tem aulas no semestre corrente",
            classesPage.getUrl(),
            classesPage.getPageName());
      }

      pos = SyncDataHelper.getIndexAndGoToEnd("table id=\"horarios\"", html);
      endPos = SyncDataHelper.getIndexOf("</table>", html);

      html = html.substring(pos, endPos);

      List<ClassScheduleDataHolder> dataHolderList = new ArrayList<>();

      endPos = 0;
      do {
        ClassScheduleDataHolder dataHolder = new ClassScheduleDataHolder();

        // Id
        pos = SyncDataHelper.getIndexAndGoToEnd("data-id=\"", html, endPos);
        endPos = SyncDataHelper.getIndexOf("\"", html, pos);
        dataHolder.id = html.substring(pos, endPos);
        UnisantaApplication.Log_i("ID: " + dataHolder.id);

        // Dia da semana
        pos = SyncDataHelper.getIndexAndGoToEnd("strong>", html, endPos);
        endPos = SyncDataHelper.getIndexOf("<", html, pos);
        dataHolder.weekDay = html.substring(pos, endPos);
        UnisantaApplication.Log_i(
            "Dia da semana encontrado: "
                + dataHolder.weekDay
                + " | na posição "
                + pos
                + " até "
                + endPos);

        // Horário
        pos = SyncDataHelper.getIndexAndGoToEnd("<td class=\"colunaDuracaHorario", html, endPos);
        pos = SyncDataHelper.getIndexOf(">", html, pos);
        endPos = SyncDataHelper.getIndexOf("<", html, pos);

        String horario = html.substring(pos, endPos);
        int aux = horario.indexOf("-");
        dataHolder.startTime = horario.substring(1, aux).trim();
        dataHolder.endTime = horario.substring(aux + 1, horario.length()).trim();
        UnisantaApplication.Log_i(
            "A aula começa às: " + dataHolder.startTime + " e acaba às " + dataHolder.endTime);

        // Matéria
        pos = SyncDataHelper.getIndexAndGoToEnd("alinhamentoEsquerda", html, endPos);
        pos = SyncDataHelper.getIndexOf(">", html, pos) + 3;
        endPos = SyncDataHelper.getIndexOf("<", html, pos);

        dataHolder.subjectName =
            SyncDataHelper.fixSpecialCharacters(html.substring(pos, endPos).trim());
        dataHolder.isDP = dataHolder.subjectName.contains("- DP");
        UnisantaApplication.Log_i("Matéria encontrada: " + dataHolder.subjectName);

        // Professor
        pos = SyncDataHelper.getIndexAndGoToEnd("alinhamentoEsquerda", html, endPos);
        pos = SyncDataHelper.getIndexOf(">", html, pos) + 1;
        endPos = SyncDataHelper.getIndexOf("<", html, pos);

        dataHolder.teacherName = SyncDataHelper.fixSpecialCharacters(html.substring(pos, endPos));
        UnisantaApplication.Log_i("Professor encontrado: " + dataHolder.teacherName);

        // Sala
        pos = SyncDataHelper.getIndexAndGoToEnd("colunaSalaHorario", html, endPos);
        pos = SyncDataHelper.getIndexOf(">", html, pos) + 1;
        endPos = SyncDataHelper.getIndexOf("<", html, pos);
        dataHolder.classroom = html.substring(pos, endPos);
        UnisantaApplication.Log_i("Sala de aula encontrada: " + dataHolder.classroom);

        dataHolderList.add(dataHolder);
      } while (html.indexOf("<tr", endPos) > -1);

      saveClasses(dataHolderList);

    } catch (StringNotFoundException e) {
      throw new MissingTagException(classesPage.getUrl(), classesPage.getPageName(), e.getString());
    } catch (UnavailableDataException e) {
      throw e;
    } catch (Exception e) {
      throw new SyncFailedException(e, classesPage.getUrl(), classesPage.getPageName());
    }
  }
コード例 #3
0
 @Override
 public List<ClassSchedule> findBySchoolYear(SchoolYear schoolYear) {
   return Lists.newArrayList(
       ClassSchedule.find(ClassSchedule.class, "semester = ?", schoolYear.toString()));
 }