1. Afriza N. Arief
  2. muis_insert_missing_prayer_times

Commits

Afriza N. Arief  committed 9c2f70e

Handle inserting into totally empty Google Calendar

Instead of checking existing events and inserting some missing prayer time
events, insert prayer time events into a calendar that is completely empty
during the the MUIS Prayer Time period concerned.

  • Participants
  • Parent commits 15cce83
  • Branches default

Comments (0)

Files changed (2)

File calendar-cmdline-sample/src/main/java/cc/co/abuaasiya/muis/Environment.java

View file
    * @return
    */
   public static File getMUISPrayerTimetableTextFile() {
-    return new File("C:/Users/arief/Desktop/Prayer Timetable 2012.txt");
+    return new File("C:/Users/arief/Desktop/Prayer Timetable 2013.txt");
   }
 
   /**

File calendar-cmdline-sample/src/main/java/cc/co/abuaasiya/muis/InsertMissingPrayerTimes.java

View file
                 .setOrderBy("startTime").setTimeMin(timeMin).setTimeMax(timeMax).setMaxResults(500)
                 .setPageToken(pageToken).execute();
         // write(System.out, events);
-        for (Event event : events.getItems()) {
-          if (curPT == null) break;
-          long evSecs = event.getStart().getDateTime().getValue() / 1000;
+        if (events.getItems() != null) {
+          for (Event event : events.getItems()) {
+            if (curPT == null) break;
+            long evSecs = event.getStart().getDateTime().getValue() / 1000;
 
-          // insert missing prayer times
-          while (curPT != null && ptSecs <= evSecs) {
-            if (ptSecs != evSecs) {
+            // insert missing prayer times
+            while (curPT != null && ptSecs <= evSecs) {
+              if (ptSecs != evSecs) {
 
-              System.out.println("=====<<missing>>=====");
-              printPrayerTime(curPT, ptSecs);
-              printEvent(event, evSecs);
+                System.out.println("=====<<missing>>=====");
+                printPrayerTime(curPT, ptSecs);
+                printEvent(event, evSecs);
 
-              batch.addPrayerTime(curPT);
+                batch.addPrayerTime(curPT);
+              }
+
+              curPT = ptIt.hasNext() ? ptIt.next() : null;
+              ptSecs = curPT != null ? curPT.getSeconds() : -1;
             }
 
-            curPT = ptIt.hasNext() ? ptIt.next() : null;
-            ptSecs = curPT != null ? curPT.getSeconds() : -1;
+            // remove duplicate
+            if (evSecs == evSecsOld) {
+              System.out.println("=====<<duplicate>>=====");
+              printEvent(evOld, evSecsOld);
+              printEvent(event, evSecs);
+              batch.remove(event);
+            }
+
+            evOld = event;
+            evSecsOld = evSecs;
           }
-
-          // remove duplicate
-          if (evSecs == evSecsOld) {
-            System.out.println("=====<<duplicate>>=====");
-            printEvent(evOld, evSecsOld);
-            printEvent(event, evSecs);
-            batch.remove(event);
-          }
-
-          evOld = event;
-          evSecsOld = evSecs;
+          System.out.println("=====<<executing>>=====");
+          batch.execute();
         }
-        batch.execute();
         pageToken = events.getNextPageToken();
         if (pageToken == null || pageToken.isEmpty()) {
           break;
       }
       // handle tailing remainder
       while (curPT != null) {
+        for (int n = 0; n < 500 && curPT != null; n++) {
+          System.out.println("=====<<missing>>=====");
+          printPrayerTime(curPT, ptSecs);
 
-        System.out.println("=====<<missing>>=====");
-        printPrayerTime(curPT, ptSecs);
+          batch.addPrayerTime(curPT);
 
-        batch.addPrayerTime(curPT);
-
-        curPT = ptIt.hasNext() ? ptIt.next() : null;
-        ptSecs = curPT != null ? curPT.getSeconds() : -1;
+          curPT = ptIt.hasNext() ? ptIt.next() : null;
+          ptSecs = curPT != null ? curPT.getSeconds() : -1;
+        }
+        System.out.println("=====<<executing>>=====");
+        batch.execute();
       }
     }
+    System.out.println("=====<<executing>>=====");
     batch.execute();
     System.out.println("=====<<finished>>=====");
   }