def parse(self, response):
        results = response.body_as_unicode()
        locations = json.loads(results)

        for data in locations:
            properties = {
                'ref': data['location']['id'],
                'name': data['location']['name'],
                'lat': data['location']['latitude'],
                'lon': data['location']['longitude'],
                'addr_full': data['location']['street_address'],
                'city': data['location']['locality'],
                'state': data['location']['region'],
                'postcode': data['location']['postal_code'],
                'phone': data['location']['phone'],
                'website': 'https://www.potbelly.com/stores/%s' % data['location']['id'],
            }

            hours = json.loads(data['location']['meta']['open_hours'])
            if hours:
                oh = OpeningHours()
                for d, v in hours.items():
                    for r in v:
                        open_time = r['opens_at']
                        close_time = r['closes_at']
                        oh.add_range(d[:2], open_time, close_time, '%H:%M:%S')
                properties['opening_hours'] = oh.as_opening_hours()

            yield GeojsonPointItem(**properties)
    def parse_hours(self, data):
        """
        Eg:
        {
            "MonHours": "4:00PM-10:00PM",
            "TueHours": "4:00PM-10:00PM",
            "WedHours": "4:00PM-10:00PM",
            "ThuHours": "4:00PM-10:00PM",
            "FriHours": "4:00PM-11:00PM",
            "SatHours": "11:00AM-11:00PM",
            "SunHours": "11:00AM-10:00PM"
        }
        :param hours:
        :return:
        """
        hours = OpeningHours()
        for k, v in DAY_MAPPING.items():
            open, close = data[k].split('-')
            if not open or not close:
                continue
            hours.add_range(day=v,
                            open_time=self.convert_to_24hr(open),
                            close_time=self.convert_to_24hr(close))

        return hours.as_opening_hours()
Exemple #3
0
    def parse_hours(self, hours):
        opening_hours = OpeningHours()

        for hour in hours:
            opening_hours.add_range(day=DAY_MAPPING[hour["dayOfWeek"]],
                                    open_time=hour["opens"],
                                    close_time=hour["closes"])

        return opening_hours.as_opening_hours()
Exemple #4
0
    def parse_hours(self, hours):
        opening_hours = OpeningHours()

        for hour in hours:
            opening_hours.add_range(day=hour["dayOfWeek"].split('/')[-1][0:2],
                                    open_time=hour["opens"],
                                    close_time=hour["closes"])

        return opening_hours.as_opening_hours()
Exemple #5
0
    def parse_hours(self, hours):
        opening_hours = OpeningHours()
        for hour in hours:
            day, open_time, close_time = hour.split('|')
            opening_hours.add_range(day=day[:2],
                                    open_time=open_time,
                                    close_time=close_time)

        return opening_hours.as_opening_hours()
Exemple #6
0
    def parse_hours(self, hours):
        opening_hours = OpeningHours()

        for hour in hours:
            opening_hours.add_range(day=DAY_MAPPING[hour["dayOfWeek"]],
                                    open_time=hour["opens"],
                                    close_time=hour["closes"])

        return opening_hours.as_opening_hours()
Exemple #7
0
    def parse_hours(self, hours):
        opening_hours = OpeningHours()

        for item in hours:
            opening_hours.add_range(day=item["dayOfWeek"][:2],
                                    open_time=item["opens"],
                                    close_time=item["closes"])

        return opening_hours.as_opening_hours()
 def parse_hours(self, response):
     tbl = response.css('.holiday_hours_tbl')[-1].xpath('./tbody//text()')
     vals = [s for s in tbl.extract() if s.strip()]
     opening_hours = OpeningHours()
     for day, span in zip(*[iter(vals)] * 2):
         day = day[:2]
         open_time, close_time = span.split(" to ")
         opening_hours.add_range(day, open_time, close_time, "%I:%M %p")
     return opening_hours.as_opening_hours()
Exemple #9
0
    def parse_hours(self, hours):
        opening_hours = OpeningHours()
        for hour in hours:
            day, hours = re.search(r'([a-z]{2})\s(.*)', hour, re.IGNORECASE).groups()
            if hours == 'Closed':
                continue
            open_time, close_time = hours.split('-')
            opening_hours.add_range(day, open_time=open_time, close_time=close_time)

        return opening_hours.as_opening_hours()
Exemple #10
0
    def parse_hours(self, hours):
        opening_hours = OpeningHours()
        for day, times in hours.items():
            if day == "default":
                continue
            opening_hours.add_range(day=DAYS[day],
                                    open_time=times[0]["start"],
                                    close_time=times[-1]["end"])

        return opening_hours.as_opening_hours()
Exemple #11
0
 def parse_hours(self, hours_json):
     opening_hours = OpeningHours()
     for date in hours_json:
         day = date["day"][:2].capitalize()
         for interval in date["intervals"]:
             start_hr, start_min = divmod(interval["start"], 100)
             end_hr, end_min = divmod(interval["end"], 100)
             opening_hours.add_range(day, f"{start_hr}:{start_min}",
                                     f"{end_hr}:{end_min}")
     return opening_hours.as_opening_hours()
    def parse_hours(self, hours):
        opening_hours = OpeningHours()
        for hour in hours:
            day = hour['dayOfWeek'].replace('http://schema.org/', '')
            opening_hours.add_range(day=DAY_MAPPING[day],
                                    open_time=hour["opens"],
                                    close_time=hour["closes"],
                                    time_format='%H:%M:%S')

        return opening_hours.as_opening_hours()
Exemple #13
0
 def parse_hours(self, hours):
     opening_hours = OpeningHours()
     for hour in hours:
         if hour['openingHour'] == 'CLOSED':
             continue
         opening_hours.add_range(day=hour['day'][:2],
                                 open_time=hour["openingHour"],
                                 close_time=hour["closingHour"],
                                 time_format='%I:%M %p')
     return opening_hours.as_opening_hours()
Exemple #14
0
    def parse_hours(self, store_hours):
        opening_hours = OpeningHours()
        for record in store_hours:
            if record['open']:
                opening_hours.add_range(day=DAY_MAPPING[record['dayOfWeek']],
                                        open_time=record['fromTime'],
                                        close_time=record['toTime'],
                                        time_format='%H:%M')

        return opening_hours.as_opening_hours()
Exemple #15
0
    def parse_hours(self, elements):
        opening_hours = OpeningHours()

        for item in elements:
            day, open_time, close_time = re.search(
                r'([a-z]{3}):.([0-9:\sAPM]+)\s-\s([0-9:\sAPM]+)', item, flags=re.IGNORECASE).groups()
            opening_hours.add_range(day=day[0:2],
                                    open_time=datetime.datetime.strptime(open_time, '%I:%M %p').strftime('%H:%M'),
                                    close_time=datetime.datetime.strptime(close_time, '%I:%M %p').strftime('%H:%M'))
        return opening_hours.as_opening_hours()
    def parse_hours(self, open_hours):
        opening_hours = OpeningHours()
        location_hours = re.findall(r'([a-zA-Z]*)\s(.*?)\s-\s(.*?)\s', open_hours)

        for weekday in location_hours:
            opening_hours.add_range(day=weekday[0],
                                    open_time=weekday[1],
                                    close_time=weekday[2])

        return opening_hours.as_opening_hours()
Exemple #17
0
    def parse_hours(self, hours: list) -> OpeningHours:
        opening_hours = OpeningHours()
        for group in hours:
            try:
                day, open_time, close_time = re.search(OPEN_STREET_MAP_OPENING_HOURS_SINGLE_DAY_REGEX, group).groups()
                opening_hours.add_range(day, open_time, close_time)
            except AttributeError:
                continue

        return opening_hours
Exemple #18
0
    def parse_hours(self, hours):
        opening_hours = OpeningHours()
        hours = hours.split(',')
        for hour in hours:
            day, open_hour, open_minute, close_hour, close_minute = hour.split(':')
            opening_hours.add_range(day=DAY_MAPPING[day],
                                    open_time="{}:{}".format(open_hour, open_minute),
                                    close_time="{}:{}".format(close_hour, close_minute),
                                    time_format='%H:%M')

        return opening_hours.as_opening_hours()
Exemple #19
0
    def process_hours(self, hours):
        output = OpeningHours()
        for day, data in hours.items():
            day_fmted = day[0].upper() + day[1].lower()
            hours_data = data.get('openIntervals')
            if not hours_data:
                continue
            hours_data = hours_data[0]
            output.add_range(day_fmted, hours_data['start'], hours_data['end'])

        return output.as_opening_hours()
Exemple #20
0
    def parse_hours(self, store_info):
        opening_hours = OpeningHours()
        for day in DAY_MAPPING:
            opening_hours.add_range(
                day=DAY_MAPPING[day],
                open_time=store_info[f'opensAt{day}'],
                close_time=store_info[f'closesAt{day}'],
                time_format='%H:%M'
            )

        return opening_hours.as_opening_hours()
    def parse_hours(self, response):
        days = response.xpath('//meta[@property="business:hours:day"]/@content').extract()
        start_times = response.xpath('//meta[@property="business:hours:start"]/@content').extract()
        end_times = response.xpath('//meta[@property="business:hours:end"]/@content').extract()

        opening_hours = OpeningHours()
        for day, open_time, close_time in zip(days, start_times, end_times):
            opening_hours.add_range(day=DAY_MAPPING[day],
                                    open_time=open_time,
                                    close_time=close_time)
        return opening_hours.as_opening_hours()
    def parse_hours(self, lis):
        o = OpeningHours()

        for day in DAY_MAPPING:
            d = day.title()[:2]

            if lis[day]['label'] == '0000 - 0000':
                continue

            o.add_range(d, lis[day]['openTime'], lis[day]['closeTime'])
        return o.as_opening_hours()
Exemple #23
0
    def parse_hours(self, hours):

        opening_hours = OpeningHours()
        for i in range(0, len(hours), 2):
            day = hours[i]
            open_time, close_time = hours[i+1].split('-')
            opening_hours.add_range(day=day[:2],
                                    open_time=open_time.strip(),
                                    close_time=close_time.strip(),
                                    time_format='%I:%M %p')
        return opening_hours.as_opening_hours()
Exemple #24
0
    def parse_hours(self, hours):
        o = OpeningHours()

        for h in hours:
            try:
                day, open, close = re.search(r'(.{2})\s([\d:]+)-([\d:]+)', h).groups()
                o.add_range(day, open_time=open, close_time=close, time_format='%H:%M')
            except AttributeError:
                continue

        return o.as_opening_hours()
def parse_hours(hours_json):
    opening_hours = OpeningHours()

    for spec in hours_json:
        for day in spec['dayOfWeek']:
            opening_hours.add_range(day=DAY_MAPPING[day],
                                    open_time=remove_seconds(spec['opens']),
                                    close_time=adjust_closing_time(
                                        remove_seconds(spec['closes'])))

    return opening_hours.as_opening_hours()
Exemple #26
0
    def store_hours(self, store_hours):
        opening_hours = OpeningHours()

        for day, hours in zip(DAY_MAPPING, store_hours):
            open_time, close_time = hours.split('-')
            opening_hours.add_range(day=day,
                                    open_time=open_time.strip(),
                                    close_time=close_time.strip(),
                                    time_format='%I:%M %p')

        return opening_hours.as_opening_hours()
Exemple #27
0
    def parse_hours(self, hours):
        opening_hours = OpeningHours()

        for weekday in hours:
            day = DAY_MAPPING[weekday["day"]]
            open_time = weekday["open"]
            if open_time == "Closed":
                continue
            close_time = weekday["open"]
            opening_hours.add_range(day=day, open_time=open_time, close_time=close_time, time_format='%I:%M %p')
        return opening_hours.as_opening_hours()
Exemple #28
0
    def parse_hours(self, hours):
        opening_hours = OpeningHours()

        for hour in hours:
            day, open_close = hour.split(' ')
            open_time, close_time = open_close.split('-')
            opening_hours.add_range(day=day,
                                    open_time=open_time,
                                    close_time=close_time,
                                    time_format='%H:%M')
        return opening_hours.as_opening_hours()
Exemple #29
0
    def parse_hours(self, hours):
        opening_hours = OpeningHours()
        for hour, day in zip(hours, DAYS):
            if hour == 'Closed':
                continue
            hour = json.loads(hour)
            opening_hours.add_range(day,
                                    open_time=hour["open"],
                                    close_time=hour["close"])

        return opening_hours.as_opening_hours()
Exemple #30
0
    def parse_hours(self, hours):
        opening_hours = OpeningHours()

        for day in DAYS:
            open_time, close_time = hours.split('to')
            opening_hours.add_range(day=day,
                                    open_time=("".join(open_time).strip()),
                                    close_time=("".join(close_time).strip()),
                                    time_format="%H:%M%p")

        return opening_hours.as_opening_hours()
Exemple #31
0
    def opening_hours(self, hours):
        opening_hours = OpeningHours()

        for hour in hours:
            day = re.search(r'.org\/(.{2})', hour['dayOfWeek']).group(1)
            start = re.search(r'^(.*):', hour['opens']).group(1)
            end = re.search(r'^(.*):', hour['closes']).group(1)

            opening_hours.add_range(day=day, open_time=start, close_time=end)

        return opening_hours.as_opening_hours()
Exemple #32
0
    def parse_hours(self, hours):

        opening_hours = OpeningHours()
        for i in range(0, len(hours), 2):
            day = hours[i]
            open_time, close_time = hours[i+1].split('-')
            opening_hours.add_range(day=day[:2],
                                    open_time=open_time.strip(),
                                    close_time=close_time.strip(),
                                    time_format='%I:%M %p')
        return opening_hours.as_opening_hours()
Exemple #33
0
    def parse_hours(self, hours):
        opening_hours = OpeningHours()

        for elem in hours:
            day, open_time, close_time = re.search(
                r'([A-Za-z]+)\s([\d:]+)\s-\s([\d:]+)', elem).groups()
            opening_hours.add_range(day=day[:2],
                                    open_time=open_time,
                                    close_time=close_time)

        return opening_hours.as_opening_hours()
Exemple #34
0
 def parse_hours(self, hours):
     "1,1030,2200;2,1030,2200;3,1030,2200;4,1030,2200;5,1030,2300;6,1030,2300;7,1030,2200;"
     opening_hours = OpeningHours()
     if hours:
         days = [day for day in hours.split(';') if day]
         for day in days:
             day, from_hr, to_hr = day.split(',')
             opening_hours.add_range(day=NUMBER_DAY[day],
                                     open_time=from_hr,
                                     close_time=to_hr,
                                     time_format='%H%M')
     return opening_hours.as_opening_hours()
Exemple #35
0
    def parse_hours(self, hours):
        opening_hours = OpeningHours()

        for hour in hours:
            try:
                opening_hours.add_range(day=hour["dayOfWeek"][0][:2],
                                        open_time=hour["opens"],
                                        close_time=hour["closes"])
            except:
                continue  # closed or no time range given

        return opening_hours.as_opening_hours()
Exemple #36
0
    def parse_hours(self, store_hours):
        opening_hours = OpeningHours()
        if store_hours is None:
            return

        for store_day in store_hours:
            opening_hours.add_range(
                day=DAY_MAPPING[store_day['weekday'].strip()],
                open_time=store_day['open_from'],
                close_time=store_day['open_until'],
                time_format='%H:%M')
        return opening_hours.as_opening_hours()
Exemple #37
0
    def parse_hours(self, days):
        opening_hours = OpeningHours()
        days = json.loads(days)

        for day in days:
            if not day["intervals"]:
                continue
            opening_hours.add_range(day=DAY_MAPPING[day["day"]],
                                    open_time=str(day["intervals"][0]["start"]),
                                    close_time=str(day["intervals"][0]["end"]),
                                    time_format="%H%M")

        return opening_hours.as_opening_hours()
Exemple #38
0
    def normalize_hours(self, hours):
        o = OpeningHours()

        for hour in hours:
            if hour.get('holidayHoursIsRegular') == False:
                continue

            short_day = hour['day'].title()[:2]

            for r in hour['intervals']:
                open_time = '%04d' % r['start']
                close_time = '%04d' % r['end']

                o.add_range(short_day, open_time, close_time, '%H%M')

        return o.as_opening_hours()
    def parse_store(self, response):

        elem = response.xpath('//div[contains(@class, "our-hospitals-location")]')

        script_body = ' '.join(elem.xpath('.//script/text()').extract())
        match = re.search(r'.*google.maps.LatLng\(([0-9.-]+),\s([0-9.-]+)\)', script_body)

        lat, lon = match.groups()

        # use last 3 elements of the store url as unique identifier (store number does not appear to be unique)
        ref = "_".join(urllib.parse.urlsplit(response.url).path.split('/')[-3:])

        number = elem.xpath('//div[@class="vcard"]/p[@id="hospitalAddressHospitalNumber"]/text()').extract_first()
        number = re.search(r'Hospital\sNumber:\s+(\d+)', number).group(1)

        properties = {
            'name': elem.xpath('//div[@class="vcard"]/p[@class="fn"]/text()').extract_first(),
            'addr_full': elem.xpath('//div[@class="vcard"]/span[@class="street-address"]/text()').extract_first(),
            'phone': elem.xpath('//div[@class="vcard"]/p[@id="hospitalAddressPhone"]/text()').extract_first(),
            'city': elem.xpath('//div[@class="vcard"]/span[@class="region"]/text()').extract_first(),
            'state': elem.xpath('//div[@class="vcard"]/span[@class="state"]/text()').extract_first(),
            'postcode': elem.xpath('//div[@class="vcard"]/span[@class="postal-code"]/text()').extract_first(),
            'ref': ref,
            'website': response.url,
            'lat': lat,
            'lon': lon,
            'extras': {
                'number': number
            }
        }

        days = elem.xpath('//div[@class="hours"]/div[contains(@class, "day")]/@content').extract()
        opening_hours = OpeningHours()

        for d in days:
            match = re.search(r'([A-Za-z]{2})\s([\d:]+)-([\d:]+)', d)
            if match:
                day, open, close = match.groups()
                opening_hours.add_range(day=day, open_time=open, close_time=close)

        hours = opening_hours.as_opening_hours()

        if hours and hours != 'Mo-Su ':
            properties['opening_hours'] = hours

        yield GeojsonPointItem(**properties)
Exemple #40
0
    def parse_hours(self, hours):
        o = OpeningHours()
        for h in hours:
            day = DAY_MAPPING[h['DayNumber']]
            open = h['Range'].get('Open')
            close = h['Range'].get('Close')
            if h['IsOpenedAllDay']:
                open = '0:00'
                close = '23:59'
            elif h['IsClosedAllDay']:
                continue

            if open and close:
                o.add_range(day=day,
                            open_time=open,
                            close_time=close)
        return o.as_opening_hours()
def test_twentyfour_seven():
    o = OpeningHours()
    o.add_range('Mo', '0:00', '23:59')
    o.add_range('Tu', '0:00', '23:59')
    o.add_range('We', '0:00', '23:59')
    o.add_range('Th', '0:00', '23:59')
    o.add_range('Fr', '0:00', '23:59')
    o.add_range('Sa', '0:00', '23:59')
    o.add_range('Su', '0:00', '23:59')

    assert o.as_opening_hours() == '24/7'
Exemple #42
0
    def parse_hours(self, items):
        opening_hours = OpeningHours()

        for day in items:
            open_time = day["Open"]
            close_time = day["Close"]
            if close_time == 'Closed' or open_time == 'Closed':
                continue
            elif close_time == 'Open 24 Hrs' or open_time == 'Open 24 Hrs':
                open_time = '12:00 AM'
                close_time = '12:00 AM'
            elif close_time == 'Open for Special Events':
                continue

            opening_hours.add_range(day=day["Day"][:2],
                                    open_time=open_time,
                                    close_time=close_time,
                                    time_format='%I:%M %p')
        return opening_hours.as_opening_hours()
Exemple #43
0
    def parse_hours(self, elements):
        opening_hours = OpeningHours()

        days = elements.xpath('//span[@itemprop="dayOfWeek"]/text()').extract()
        today = (set(day_mapping) - set(days)).pop()
        days.remove('TODAY')
        days.insert(0,today)
        open_hours = elements.xpath('//div[@class="store-hours"]/time[@itemprop="opens"]/@content').extract()
        close_hours = elements.xpath('//div[@class="store-hours"]/time[@itemprop="closes"]/@content').extract()

        store_hours = dict((z[0],list(z[1:])) for z in zip(days, open_hours, close_hours))

        for day, hours in store_hours.items():
            if 'CLOSED' in hours:
                continue
            opening_hours.add_range(day=day_mapping[day],
                                    open_time=convert_24hour(hours[0]),
                                    close_time=convert_24hour(hours[1]))
        return opening_hours.as_opening_hours()
Exemple #44
0
    def parse_hours(self, elements):
        opening_hours = OpeningHours()

        for elem in elements:
            day = elem.xpath('.//td[@class="c-location-hours-details-row-day"]/text()').extract_first()
            intervals = elem.xpath('.//td[@class="c-location-hours-details-row-intervals"]')

            if intervals.xpath('./text()').extract_first() == "Closed":
                continue
            if intervals.xpath('./span/text()').extract_first() == "Open 24 hours":
                opening_hours.add_range(day=DAY_MAPPING[day],
                                        open_time='0:00',
                                        close_time='23:59')
            else:
                start_time = elem.xpath(
                    './/span[@class="c-location-hours-details-row-intervals-instance-open"]/text()').extract_first()
                end_time = elem.xpath(
                    './/span[@class="c-location-hours-details-row-intervals-instance-close"]/text()').extract_first()
                opening_hours.add_range(day=DAY_MAPPING[day],
                                        open_time=datetime.datetime.strptime(start_time, '%H:%M %p').strftime('%H:%M'),
                                        close_time=datetime.datetime.strptime(end_time, '%H:%M %p').strftime('%H:%M'))
        return opening_hours.as_opening_hours()
Exemple #45
0
    def parse(self, response):
        shops = json.loads(response.text)

        for shop in shops['records']:
            o = OpeningHours()
            for d, ranges in shop['hoursOfOperation'].items():
                for r in ranges:
                    o.add_range(d[:2], r[0], r[1])

            yield GeojsonPointItem(
                website=shop['website'],
                ref=shop['branch'],
                opening_hours=o.as_opening_hours(),
                phone=shop['phone'],
                addr_full=shop['address'],
                postcode=shop['postalCode'],
                city=shop['city'],
                state=shop['province'],
                country=shop['country'],
                lat=shop['geo'][1],
                lon=shop['geo'][0],
            )
Exemple #46
0
    def parse_hours(self, days):
        opening_hours = OpeningHours()
        for day in days:
            day = day.strip('\n ')
            if not day:
                continue
            parts = day.split(':')
            weekday = parts[0]
            hours = ":".join(parts[1:])
            try:
                open, close = hours.split('-')
                if (not open.strip()) or (open.strip() == 'Closed'):
                    continue
                if close.strip() in ('24:00', '23:59'):  # two oddball banks
                    continue
                opening_hours.add_range(day=weekday[:2],
                                        open_time="{} AM".format(open.strip()),
                                        close_time="{} PM".format(close.strip()),
                                        time_format="%I:%M %p")
            except:
                continue

        return opening_hours.as_opening_hours()
    def parse_store(self, response):
        properties = {
            'ref': response.url,
            'lat': response.xpath('//div[@class="map-container"]/div/@data-latitude').extract_first(),
            'lon': response.xpath('//div[@class="map-container"]/div/@data-longitude').extract_first(),
            'phone': response.xpath('//a[@class="phone-link"]/span/text()').extract_first(),
            'addr_full': response.xpath('//span[@itemprop="streetAddress"]/text()').extract_first().strip(),
            'name': response.xpath('//meta[@itemprop="name legalName"]/@content').extract_first(),
            'city': response.xpath('//span[@itemprop="addressLocality"]/text()').extract_first()[:-1],
            'state': response.xpath('//span[@itemprop="addressRegion"]/text()').extract_first().strip(),
            'postcode': response.xpath('//span[@itemprop="postalCode"]/text()').extract_first().strip(),
        }

        o = OpeningHours()
        for h in response.css('#LocalMapAreaOpenHourBanner li.h-day'):
            day = h.xpath('em/span/text()').extract_first().strip()[:2]
            day_range = h.xpath('em/text()').extract_first().strip(':').strip()
            open_time, close_time = day_range.split(' - ')

            o.add_range(day, open_time, close_time, '%I:%M %p')
        properties['opening_hours'] = o.as_opening_hours()

        yield GeojsonPointItem(**properties)
Exemple #48
0
    def parse_hours(self, elem):
        days = elem.xpath('.//dt/text()').extract()
        hours = elem.xpath('.//dd/text()').extract()

        opening_hours = OpeningHours()
        for d, h in zip(days, hours):
            day = DAY_MAPPING[d.replace(':', '')]
            try:
                open_time, close_time = h.split('-')
            except ValueError:
                continue
            if ':' in open_time:
                open_time = datetime.datetime.strptime(open_time, '%I:%M%p').strftime('%H:%M')
            else:
                open_time = datetime.datetime.strptime(open_time, '%I%p').strftime('%H:%M')

            if ':' in close_time:
                close_time = datetime.datetime.strptime(close_time, '%I:%M%p').strftime('%H:%M')
            else:
                close_time = datetime.datetime.strptime(close_time, '%I%p').strftime('%H:%M')

            opening_hours.add_range(day=day, open_time=open_time, close_time=close_time)

        return opening_hours.as_opening_hours()
Exemple #49
0
    def parse_hours(self, hours):
        "Sun - Sat 7:00 AM - 10:00 PM"
        opening_hours = OpeningHours()
        hours = [h.strip() for h in hours.split(';')]

        for hour in hours:
            if hour == "Sun - Sat open 24 hrs":
                return "24/7"
            range_match = re.search(r'([A-Za-z]{3})\s-\s([A-Za-z]{3})\s([\d:\sAMP]+)\s-\s([\d:\sAMP]+)', hour)
            if range_match:
                start_day, end_day, start_time, end_time = range_match.groups()
            else:
                single_match = re.search(r'([A-Za-z]{3})\s([\d:\sAMP]+)\s-\s([\d:\sAMP]+)', hour)
                if not single_match:
                    continue
                start_day, start_time, end_time = single_match.groups()
                end_day = start_day

            for day in DAYS[DAYS.index(start_day):DAYS.index(end_day)+1]:
                opening_hours.add_range(day=DAY_MAPPING[day],
                                        open_time=start_time.strip(),
                                        close_time=end_time.strip(),
                                        time_format='%I:%M %p')
        return opening_hours.as_opening_hours()
    def parse_hours(self, elements):

        opening_hours = OpeningHours()
        location_hours = elements.xpath('//div[@class="c-location-hours-details-wrapper js-location-hours"]/@data-days').extract_first()
        location_hours = json.loads(location_hours)

        for weekday in location_hours:
            if not weekday['intervals']:
                continue

            open_time = str(weekday['intervals'][0]['start'])
            open_time = open_time[0:2]+":"+open_time[2:4]

            close_time = str(weekday['intervals'][0]['end'])
            if close_time in {'0','0000','2400'}:
                close_time = "23:59"
            else:
                close_time = close_time[0:2]+":"+close_time[2:4]

            opening_hours.add_range(day = day_mapping[weekday['day']],
                                    open_time = open_time,
                                    close_time = close_time)

        return opening_hours.as_opening_hours()
def test_two_ranges():
    o = OpeningHours()
    o.add_range('Mo', '07:00', '17:00')
    o.add_range('Tu', '07:00', '17:00')
    o.add_range('We', '07:00', '17:00')

    o.add_range('Fr', '08:00', '17:00')
    o.add_range('Sa', '08:00', '17:00')

    assert o.as_opening_hours() == "Mo-We 07:00-17:00; Fr-Sa 08:00-17:00"
def test_mixed_ranges():
    o = OpeningHours()
    o.add_range('Mo', '08:00', '17:00')
    o.add_range('Tu', '08:00', '17:00')
    o.add_range('We', '09:00', '18:00')
    o.add_range('Th', '09:00', '18:00')
    o.add_range('Fr', '07:00', '17:00')
    o.add_range('Su', '09:00', '17:00')

    assert o.as_opening_hours() == "Mo-Tu 08:00-17:00; We-Th 09:00-18:00; Fr 07:00-17:00; Su 09:00-17:00"
def test_closed_sunday():
    o = OpeningHours()
    o.add_range('Mo', '07:00', '17:00')
    o.add_range('Tu', '07:00', '17:00')
    o.add_range('We', '07:00', '17:00')
    o.add_range('Th', '07:00', '17:00')
    o.add_range('Fr', '07:00', '17:00')
    o.add_range('Sa', '07:00', '17:00')

    assert o.as_opening_hours() == "Mo-Sa 07:00-17:00"
def test_closed_tuesday():
    o = OpeningHours()
    o.add_range('Mo', '07:00', '17:00')
    o.add_range('We', '07:00', '17:00')
    o.add_range('Th', '07:00', '17:00')
    o.add_range('Fr', '07:00', '17:00')
    o.add_range('Sa', '07:00', '17:00')
    o.add_range('Su', '07:00', '17:00')

    assert o.as_opening_hours() == "Mo 07:00-17:00; We-Su 07:00-17:00"
Exemple #55
0
    def parse_hours(self, elem):
        opening_hours = OpeningHours()

        day = elem.xpath('.//dt/text()').extract()
        times = elem.xpath('.//dd/text()').extract()

        for day, times in zip(day, times):

            if times == "Closed":
                continue
            start_time, end_time = times.split(' - ')

            if start_time == 'Noon':
                start_time = '12:00 PM'
            if end_time == 'Noon':
                end_time = '12:00 PM'
            if '-' in day:
                days = list(DAY_MAPPING.keys())
                start_day, end_day = day.split(' - ')
                for i in days[days.index(start_day):days.index(end_day) + 1]:
                    opening_hours.add_range(day=DAY_MAPPING[i],
                                            open_time=start_time,
                                            close_time=end_time,
                                            time_format='%I:%M %p')
            elif ',' in day:
                days = list(DAY_MAPPING.keys())
                start_day, end_day = day.split(', ')
                for i in days[days.index(start_day):days.index(end_day) + 1]:
                    opening_hours.add_range(day=DAY_MAPPING[i],
                                            open_time=start_time,
                                            close_time=end_time,
                                            time_format='%I:%M %p')
            else:
                opening_hours.add_range(day=DAY_MAPPING[day],
                                        open_time=start_time,
                                        close_time=end_time,
                                        time_format='%I:%M %p')

        return opening_hours.as_opening_hours()