Example #1
0
def get_yoga_pod(local_time):
    current_day = strftime('%a', local_time)
    next_day = util.next_day(local_time.tm_wday)
    current_time = util.time_str2float(strftime('%I:%M %p', local_time))
    time_regex = r'(1?[0-9]:[0-5][0-9] [A|P]M)'
    class_regex = r'filterable (\w*)'
    url = 'http://www.healcode.com/widgets/schedules/print/dq55683k9o'

    response = urllib2.urlopen(url)
    line = response.readline()

    class_list = []
    while not ('hc_day' in line and current_day in line):
        line = response.readline()

    while True:
        line = response.readline()
        if 'filterable' in line and 'cancelled' not in line:
            class_name = re.findall(class_regex, line)[0]
            class_name = ' '.join([s.title() for s in class_name.split('_')])
            line = response.readline()
            times = re.findall(time_regex, line)
            class_time = util.time_str2float(times[0])
            if class_time >= current_time:
                class_list.append({'class_name': class_name,
                                   'start_time': times[0].lower(),
                                   'end_time':   times[1].lower()})
        if len(class_list) >= MAX_NUM_CLASSES:
            break
        if 'hc_day' in line and next_day in line:
            break
    return {'studio_name': 'Yoga Pod',
            'class_list': class_list,
            'link': 'http://yogapodcommunity.com/boulder/schedule'}
Example #2
0
    def update(self):
        date = self.range[0]
        days = (self.range[1] - self.range[0]).days + 1
        rows = int(math.ceil(float(days) / 7.0))
        cols = days
        today = datetime.date(*time.localtime(time.time())[:3])
        if days > 7:
            cols = int(math.ceil(float(days) / float(rows)))

        # Update the timeline.
        self.timeline.set_visible(rows == 1)

        # Show captions for the day.
        if cols == 7 or rows == 1:
            for child in self.day_captions.get_children():
                self.day_captions.remove(child)
            for col in range(cols):
                this_date = self.range[0] + datetime.timedelta(col)
                day_name = self.cal.model.get_day_name(this_date)
                text = hippo.CanvasText(
                    text=day_name,
                    xalign=hippo.ALIGNMENT_CENTER,
                    size_mode=hippo.CANVAS_SIZE_ELLIPSIZE_END)
                self.day_captions.add(text, col, col + 1, 0, 1)
                self.day_captions.set_column_expand(col, True)
            self.day_captions.set_visible(True)
        else:
            self.day_captions.set_visible(False)

        # Update the grid.
        self.grid.set_size(rows, cols)
        for row in range(rows):
            self.grid.set_row_expand(row, True)
        for child in self.grid.get_children():
            child.set_active(self.is_active(date))
            child.set_show_title(rows != 1)
            child.set_show_rulers(rows == 1)
            child.set_selected(date == self.selected)
            child.set_highlighted(date == today)
            child.set_date(date)
            child.update()
            date = util.next_day(date)

        if rows == 1:
            self.update_one_row()
        else:
            self.update_multi_row()
Example #3
0
    def update(self):
        date  = self.range[0]
        days  = (self.range[1] - self.range[0]).days + 1
        rows  = int(math.ceil(float(days) / 7.0))
        cols  = days
        today = datetime.date(*time.localtime(time.time())[:3])
        if days > 7:
            cols = int(math.ceil(float(days) / float(rows)))

        # Update the timeline.
        self.timeline.set_visible(rows == 1)

        # Show captions for the day.
        if cols == 7 or rows == 1:
            for child in self.day_captions.get_children():
                self.day_captions.remove(child)
            for col in range(cols):
                this_date = self.range[0] + datetime.timedelta(col)
                day_name  = self.cal.model.get_day_name(this_date)
                text      = hippo.CanvasText(text      = day_name,
                                             xalign    = hippo.ALIGNMENT_CENTER,
                                             size_mode = hippo.CANVAS_SIZE_ELLIPSIZE_END)
                self.day_captions.add(text, col, col + 1, 0, 1)
                self.day_captions.set_column_expand(col, True)
            self.day_captions.set_visible(True)
        else:
            self.day_captions.set_visible(False)

        # Update the grid.
        self.grid.set_size(rows, cols)
        for row in range(rows):
            self.grid.set_row_expand(row, True)
        for child in self.grid.get_children():
            child.set_active(self.is_active(date))
            child.set_show_title(rows != 1)
            child.set_show_rulers(rows == 1)
            child.set_selected(date == self.selected)
            child.set_highlighted(date == today)
            child.set_date(date)
            child.update()
            date = util.next_day(date)

        if rows == 1:
            self.update_one_row()
        else:
            self.update_multi_row()
Example #4
0
 def on_key_press_event(self, widget, event):
     date = self.get_selected()
     if event.keyval == 65362:    # Up
         self.select(util.previous_week(date))
         self.emit('day-selected', date, event)
     elif event.keyval == 65364:  # Down
         self.select(util.next_week(date))
         self.emit('day-selected', date, event)
     elif event.keyval == 65361:  # Left
         self.select(util.previous_day(date))
         self.emit('day-selected', date, event)
     elif event.keyval == 65363:  # Right
         self.select(util.next_day(date))
         self.emit('day-selected', date, event)
     elif event.keyval == 65293:  # Enter
         if not self.emit('day-activate', date, event):
             self.set_range(self.RANGE_WEEK)
     return True
Example #5
0
def get_yoga_workshop(local_time):
    next_day = util.next_day(local_time.tm_wday)
    current_time = util.time_str2float(strftime("%I:%M %p", local_time))
    time_regex = r'(1?[0-9]:[0-5][0-9]) – +(1?[0-9]:[0-5][0-9]) ([a|p]m)'
    class_regex = r'<div class="class_type">([\w\s-]*)</div>'

    query_args = {'callback': 'jQuery20207575509008020163_1378411104645',
                  '_': '1378411104646'}
    url = 'http://ws.yogaworkshop.com/cal?' + urllib.urlencode(query_args)

    paren_regex = r'\((.*)\)'
    response = urllib2.urlopen(url).read()
    data = re.findall(paren_regex, response)[0]
    data = json.loads(data)

    class_list = []
    data_rows = data['html'].split('\n')
    for i, line in enumerate(data_rows):
        times = re.findall(time_regex, line)
        if times:
            times = times[0]
            time_str = ' '.join([str(times[0]), str(times[2]).upper()])
            class_time = util.time_str2float(time_str)
            if class_time >= current_time:
                class_line = data_rows[i + 2]
                class_name = re.findall(class_regex, class_line)[0]
                start_time = ' '.join([str(times[0]), str(times[2])])
                end_time   = ' '.join([str(times[1]), str(times[2])])
                class_list.append({'class_name': class_name,
                                   'start_time': start_time,
                                   'end_time':   end_time})
        if len(class_list) >= MAX_NUM_CLASSES:
            break
        if next_day in line:
            break
    return {'studio_name': 'Yoga Workshop',
            'class_list': class_list,
            'link': 'http://yogaworkshop.com/schedule/class-schedule'}