def run(cls, database=DEFAULT_DB_ALIAS, **kwargs): import frepple if cls.filter: filter_and = "and %s " % cls.filter filter_where = "where %s " % cls.filter else: filter_and = "" filter_where = "" with connections[database].chunked_cursor() as cursor: cnt = 0 starttime = time() cursor.execute(''' SELECT calendar_id, startdate, enddate, priority, value, sunday, monday, tuesday, wednesday, thursday, friday, saturday, starttime, endtime, source FROM calendarbucket %s ORDER BY calendar_id, startdate desc ''' % filter_where) prevcal = None for i in cursor: cnt += 1 try: days = 0 if i[5]: days += 1 if i[6]: days += 2 if i[7]: days += 4 if i[8]: days += 8 if i[9]: days += 16 if i[10]: days += 32 if i[11]: days += 64 if i[0] != prevcal: cal = frepple.calendar(name=i[0]) prevcal = i[0] b = frepple.bucket( calendar=cal, start=i[1], end=i[2] if i[2] else datetime(2030, 12, 31), priority=i[3], source=i[14], value=i[4], days=days ) if i[12]: b.starttime = i[12].hour * 3600 + i[12].minute * 60 + i[12].second if i[13]: b.endtime = i[13].hour * 3600 + i[13].minute * 60 + i[13].second + 1 except Exception as e: logger.error("**** %s ****" % e) logger.info('Loaded %d calendar buckets in %.2f seconds' % (cnt, time() - starttime))
def loadCalendarBuckets(self): print('Importing calendar buckets...') cnt = 0 starttime = time() self.cursor.execute(''' SELECT calendar_id, startdate, enddate, priority, value, sunday, monday, tuesday, wednesday, thursday, friday, saturday, starttime, endtime, source FROM calendarbucket %s ORDER BY calendar_id, startdate desc ''' % self.filter_where) prevcal = None for i in self.cursor.fetchall(): cnt += 1 try: days = 0 if i[5]: days += 1 if i[6]: days += 2 if i[7]: days += 4 if i[8]: days += 8 if i[9]: days += 16 if i[10]: days += 32 if i[11]: days += 64 if i[0] != prevcal: cal = frepple.calendar(name=i[0]) prevcal = i[0] b = frepple.bucket(calendar=cal, start=i[1], end=i[2], priority=i[3], source=i[14], value=i[4], days=days) if i[12]: b.starttime = i[12].hour * 3600 + i[12].minute * 60 + i[ 12].second if i[13]: b.endtime = i[13].hour * 3600 + i[13].minute * 60 + i[ 13].second + 1 except Exception as e: print("Error:", e) print('Loaded %d calendar buckets in %.2f seconds' % (cnt, time() - starttime))
def loadCalendarBuckets(self): print('Importing calendar buckets...') cnt = 0 starttime = time() self.cursor.execute(''' SELECT calendar_id, startdate, enddate, priority, value, sunday, monday, tuesday, wednesday, thursday, friday, saturday, starttime, endtime, source FROM calendarbucket %s ORDER BY calendar_id, startdate desc ''' % self.filter_where) prevcal = None for i in self.cursor.fetchall(): cnt += 1 try: days = 0 if i[5]: days += 1 if i[6]: days += 2 if i[7]: days += 4 if i[8]: days += 8 if i[9]: days += 16 if i[10]: days += 32 if i[11]: days += 64 if i[0] != prevcal: cal = frepple.calendar(name=i[0]) prevcal = i[0] b = frepple.bucket( calendar=cal, start=i[1], end=i[2], priority=i[3], source=i[14], value=i[4], days=days ) if i[12]: b.starttime = i[12].hour * 3600 + i[12].minute * 60 + i[12].second if i[13]: b.endtime = i[13].hour * 3600 + i[13].minute * 60 + i[13].second + 1 except Exception as e: print("Error:", e) print('Loaded %d calendar buckets in %.2f seconds' % (cnt, time() - starttime))