Пример #1
0
  public static Pupil getSelectedPupil(Document doc) throws ParseException {

    boolean found = false;
    Pupil p, selectedP = null;

    Elements pupilSelectors =
        doc.getElementsByAttributeValue("id", "ctl00_topMenu_pupil_drdPupils");
    for (Element pupilSelector : pupilSelectors) {

      Elements pupils = pupilSelector.getAllElements();
      for (Element pupil : pupils) {
        if (pupil.tagName().equals("option")) {

          String value = pupil.attr("value");

          found = true;
          if ((p = Pupil.getByFormId(value)) == null) {

            p = new Pupil(pupil.text(), value);
            long rowId = p.insert();

            if (BuildConfig.DEBUG)
              Log.d("GshisHTMLParser", TS.get() + " Pupil.insert() = " + rowId);
          }

          if (pupil.hasAttr("selected") && pupil.attr("selected").equals("selected")) {

            selectedP = p;
          }
        }
      }
    }

    if (!found) {

      if (BuildConfig.DEBUG) Log.d("GshisParser", TS.get() + " Alternative fields found!");

      Element userName = doc.getElementsByClass("user-name").first();
      Element userId = doc.getElementsByAttributeValue("id", "ctl00_topMenu_tbUserId").first();

      String name = userName.text();
      String id = userId.attr("value");

      if (BuildConfig.DEBUG) Log.d("GshisParser", TS.get() + " name=" + name + " id=" + id);

      if ((p = Pupil.getByFormId(id)) == null) {

        p = new Pupil(name, id);
        long rowId = p.insert();

        if (BuildConfig.DEBUG) Log.d("GshisParser", TS.get() + " Pupil.insert() = " + rowId);
      }

      selectedP = p;
    }

    if (selectedP == null) throw new ParseException("Pupils not found", 0);

    return selectedP;
  }
Пример #2
0
    @Override
    public int getItemPosition(Object object) {
      if (BuildConfig.DEBUG)
        Log.d(this.toString(), TS.get() + this.toString() + " getItemPosition () started");

      return POSITION_UNCHANGED;
    }
Пример #3
0
  public static Week getSelectedWeek(Document doc, Schedule s) throws ParseException {

    boolean found = false;
    Week selectedW = null;

    SimpleDateFormat f = new SimpleDateFormat("yyyy dd.MM", Locale.ENGLISH);
    f.setTimeZone(TimeZone.getTimeZone("Europe/Moscow"));

    Elements weekSelectors = doc.getElementsByAttributeValue("id", "ctl00_body_week_drdWeeks");
    for (Element weekSelector : weekSelectors) {

      Elements weeks = weekSelector.getAllElements();
      for (Element week : weeks) {
        if (week.tagName().equals("option")) {

          String value = week.text();
          Week w;
          found = true;

          if ((w = s.getWeek(week.attr("value"))) == null) {

            w = new Week();

            String wBegin = value.substring(0, value.indexOf("-") - 1);
            String wMonth = wBegin.substring(wBegin.indexOf(".") + 1, wBegin.length());

            String year;
            if (Integer.parseInt(wMonth) > 7) {
              year = s.getFormText().substring(0, s.getFormText().indexOf("-") - 1);
            } else {
              year =
                  s.getFormText()
                      .substring(s.getFormText().indexOf("-") + 2, s.getFormText().length());
            }

            w.setStart(f.parse(year + " " + wBegin));
            w.setFormText(week.text());
            w.setFormId(week.attr("value"));

            s.addWeek(w);
          }

          if (week.hasAttr("selected") && week.attr("selected").equals("selected")) {

            selectedW = w;
            long u = w.setLoaded().update();

            if (BuildConfig.DEBUG) Log.d("GshisHTMLParser", TS.get() + " Week.update() = " + u);
          }
        }
      }
    }

    if (!found) throw new ParseException("Weeks not found", 0);

    return selectedW;
  }
Пример #4
0
  public static GradeSemester getActiveGradeSemester(Document doc, Schedule sch)
      throws ParseException {

    boolean found = false;
    GradeSemester selG = null;

    SimpleDateFormat fmt = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH);
    fmt.setTimeZone(TimeZone.getTimeZone("Europe/Moscow"));

    Elements semesterSelectors = doc.getElementsByAttributeValue("id", "ctl00_body_drdTerms");
    for (Element semesterSelector : semesterSelectors) {

      Elements semesters = semesterSelector.getAllElements();
      for (Element semester : semesters) {
        if (semester.tagName().equals("option")) {

          String value = semester.text();
          GradeSemester sem;
          found = true;

          if ((sem = sch.getSemester(semester.attr("value"))) == null) {

            sem = new GradeSemester();

            sem.setStart(fmt.parse(value.substring(12, value.indexOf("-") - 1)));
            sem.setStop(fmt.parse(value.substring(value.indexOf("-") + 2, value.length() - 2)));
            sem.setFormText(semester.text());
            sem.setFormId(semester.attr("value"));

            sch.addSemester(sem);
          }

          if (semester.hasAttr("selected") && semester.attr("selected").equals("selected")) {

            long u = sem.setLoaded().update();
            selG = sem;

            if (BuildConfig.DEBUG) Log.d("GshisHTMLParser", TS.get() + " Semester.update() = " + u);
          }
        }
      }
    }

    if (!found) throw new ParseException("Semesters not found", 0);

    return selG;
  }
Пример #5
0
  public static void getLessons(Document doc, Schedule s) throws ParseException {

    final SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm", Locale.ENGLISH);
    format.setTimeZone(TimeZone.getTimeZone("Europe/Moscow"));

    Elements lessonCells = doc.getElementsByAttribute("number");

    for (Element lessonCell : lessonCells) {

      Lesson l, lPrev = null; // lPrev to handle duplicate lesson
      int sameLesson = 0; // Also to handle duplicate lesson

      int number = Integer.parseInt(lessonCell.attr("number"));
      String time = "";

      Elements timeDetails = lessonCell.getElementsByClass("cell-header2");
      for (Element timeDetail : timeDetails) {
        if (timeDetail.hasAttr("style")) time = timeDetail.text();
      }

      Elements lessonCellDetails = lessonCell.getElementsByAttribute("jsdate");
      for (Element lessonCellDetail : lessonCellDetails) {

        String date = lessonCellDetail.attr("jsdate");
        int index = 0;
        sameLesson = 0;

        for (Element subject :
            lessonCellDetail.getElementsByAttributeValue("class", "lesson-subject")) {

          if (subject == null || subject.text() == null || subject.text().length() <= 0) {
            // No lesson scheduled
            continue;
          }

          Date start = format.parse(date + " " + time.substring(0, time.indexOf("-") - 1));
          if ((l = s.getLessonByNumber(start, number)) == null) {

            if (BuildConfig.DEBUG)
              Log.d("GshisHTMLParser", TS.get() + " getLessons() not found in db, will insert");

            l = new Lesson();
            sameLesson = 0;

            l.setStart(start);
            l.setStop(
                format.parse(date + " " + time.substring(time.indexOf("-") + 2, time.length())));
            l.setFormId(subject.attr("id"));
            l.setFormText(subject.text());
            l.setTeacher(
                lessonCellDetail
                    .getElementsByAttributeValue("class", "lesson-teacher")
                    .get(sameLesson)
                    .text());
            l.setNumber(number);

            s.addLesson(l);

          } else {

            if (BuildConfig.DEBUG)
              Log.d("GshisHTMLParser", TS.get() + " getLessons() found in db, will update");

            l.setFormId(subject.attr("id"));

            if (lPrev != null && lPrev.getStart().equals(start) && lPrev.getNumber() == number) {

              if (BuildConfig.DEBUG)
                Log.d(
                    "GshisHTMLParser",
                    TS.get()
                        + " getLessons() dup = "
                        + subject.text()
                        + " index = "
                        + index
                        + " sameLesson = "
                        + sameLesson);

              sameLesson++;

              if (!lPrev.getFormText().equals(subject.text()))
                l.setFormText(fixDuplicateString(subject.text(), lPrev.getFormText(), sameLesson));

              String teacher =
                  lessonCellDetail
                      .getElementsByAttributeValue("class", "lesson-teacher")
                      .get(index)
                      .text();

              if (!lPrev.getTeacher().equals(teacher))
                l.setTeacher(fixDuplicateString(teacher, lPrev.getTeacher(), sameLesson));

            } else {

              l.setNumber(number);
              l.setFormText(subject.text());
              l.setTeacher(
                  lessonCellDetail
                      .getElementsByAttributeValue("class", "lesson-teacher")
                      .get(index)
                      .text());
            }

            l.update();
          }

          lPrev = l;
          index++;
        }
      }
    }
  }