Ejemplo n.º 1
0
    def get_events(self):
        events_json = self.get_events_json()
        branch_locations = self.get_branch_locations_list()
        nonbranch_locations = self.get_nonbranch_locations_list()

        events = []
        for event in events_json:
            details = event['definition']
            branch_location_id = details['branch_location_id']
            # Determine if branch or non-branch event
            if branch_location_id == None:
                non_branch_location_id = details['non_branch_location_id']
                location = nonbranch_locations[non_branch_location_id]
            else:
                location = branch_locations[branch_location_id]

            try:
                date, start_time = details['start'].split('T')
                end_time = details['end'].split('T')[1]
            except ValueError:
                # Assume event is all day if no time is supplied
                date = details['start']
                start_time = end_time = 'All Day'

            # Don't show cancelled or full events
            if details['is_cancelled'] == True or event['is_full'] == True:
                continue

            events.append(
                Event.from_dict(
                    self.time_utils.old_date_format, {
                        'organization':
                        'Chicago Public Library',
                        'title':
                        details['title'],
                        'description':
                        DataUtils.remove_html(details['description']),
                        'address':
                        self.get_address_string(location),
                        'date':
                        date,
                        'start_time':
                        start_time,
                        'end_time':
                        end_time,
                        'url':
                        f'{self.base_url}/{event["id"]}',
                        'price':
                        0.0,
                        'category':
                        Category.LIBRARY
                    }))

        ScraperData.add_data(events)
Ejemplo n.º 2
0
 def get_full_date(xpath_result):
     result = []
     current_month = ''
     for text in xpath_result.data:
         text = DataUtils.remove_html(text)
         # Month names are all greater than 2 characters
         # Days of the month are all 2 characters or fewer
         if len(text) > 2:
             current_month = text
         else:
             result.append(f'{text} {current_month}')
     return EventFieldData(xpath_result.item, result)
Ejemplo n.º 3
0
    def from_dict(cls, event_dict, date_format=''):
        event = cls()
        event.set_time_format(date_format)

        time_data = Event.create_time_data()
        time_data_set = False
        for key, value in event_dict.items():
            value = DataUtils.remove_html(value)
            if key in time_data:
                time_data[key] = value
                time_data_set = True
            else:
                event[key] = value
        if time_data_set:
            event['time_data'] = time_data
        return event
Ejemplo n.º 4
0
 def remove_html(self, remove_all_whitespace=False):
     self.data = DataUtils.remove_html(self.data, remove_all_whitespace)
     return self
Ejemplo n.º 5
0
 def remove_html(self):
     self.data = DataUtils.remove_html(self.data)
     return self