Пример #1
0
def process_file(filename):
    event = None
    try:
        url = f'{BASE_URL}/{filename}'
        resp = client.get(url)
        text = resp.text.replace('\r', '')
        lines = text.split('\n')
        if 'ACUS01' not in lines[1]:
            return None
        risk = ''
        risk_block = lines[11:]
        for line in risk_block:
            if not line.strip():
                break
            risk += f' {line}'
        risk = risk[4:]
        while risk[-1] == '.':
            risk = risk[:-1]
        event = {
            'img_url': 'https://www.spc.noaa.gov/products/outlook/day1otlk.gif',
            'subject': risk,
            'ts': ingest.get_ts_from_bulletin(lines[7]),
            'type': 'swo',
            'url': url,
        }
    except:
        logging.warning(traceback.format_exc())
    return event
Пример #2
0
def process_file(filename):
    event = None
    try:
        url = f'{BASE_URL}/{filename}'
        resp = client.get(url)
        text = resp.text.replace('\r', '')
        lines = text.split('\n')
        wfo = lines[2][3:]
        for line in lines:
            if 'TIME...MOT' in line:
                splits = line.strip().split(' ')
                lat = int(splits[-2]) / 100
                lon = (int(splits[-1]) / 100) * -1
                point = (lon, lat)
                break
        nearest = ingest.get_nearest(point, cities_tree, cities)

        event = {
            'geo': {
                'point': point,
                'city': nearest[0],
                'st': nearest[1],
                'distance': nearest[2],
                'bearing': nearest[4]
            },
            'ts': ingest.get_ts_from_bulletin(lines[9]),
            'type': 'svr',
            'url': url,
            'wfo': wfo,
        }
    except:
        logging.warn(traceback.format_exc())
    return event
Пример #3
0
def process_file(filename):
    event = None
    try:
        url = f'{BASE_URL}/{filename}'
        resp = client.get(url)
        text = resp.text.replace('\r', '')
        emergency = 'TORNADO EMERGENCY' in text
        lines = text.split('\n')
        emergency_text = ''
        if emergency:
            for line in lines:
                if 'TORNADO EMERGENCY' in line:
                    emergency_text = line.strip().replace('.', '')
        wfo = lines[2][3:]
        text = lines[14].strip()
        for line in lines[15:]:
            if not line.strip():
                break
            text += line
        text = text.replace('  ', ' ')
        while text[-1] == '.':
            text = text[:-1]
        for line in lines:
            if 'TIME...MOT' in line:
                splits = line.strip().split(' ')
                lat = int(splits[-2]) / 100
                lon = (int(splits[-1]) / 100) * -1
                point = (lon, lat)
                break
        nearest = ingest.get_nearest(point, cities_tree, cities)

        event = {
            'geo': {
                'point': point,
                'city': nearest[0],
                'st': nearest[1],
                'distance': nearest[2],
                'bearing': nearest[4]
            },
            'emergency': emergency,
            'subject': text,
            'ts': ingest.get_ts_from_bulletin(lines[9]),
            'type': 'tor',
            'url': url,
            'wfo': wfo,
        }
        if emergency_text:
            event['subject2'] = emergency_text
    except:
        logging.warning(traceback.format_exc())
    return event
Пример #4
0
def process_file(filename):
    print(filename)
    event = None
    try:
        url = f'{BASE_URL}/{filename}'
        resp = client.get(url)
        text = resp.text.replace('\r', '')
        if 'HAS CANCELLED' in text:
            return event
        pds = 'THIS IS A PARTICULARLY DANGEROUS SITUATION' in text
        lines = text.split('\n')
        area = None
        for line in lines:
            if len(line) and line[0] == '*':
                if area is not None:
                    break
                else:
                    area = line.strip()
            elif area is not None:
                area += f'{line},'
        while '  ' in area:
            area = area.replace('  ', ' ')
        while area[-1] == ',':
            area = area[:-1]
        area = area.replace('* Tornado Watch ', '')
        area = area.replace('* Severe Thunderstorm Watch ', '')
        watch_id = lines[7].split(' ')[-1]
        if len(watch_id) == 2:
            watch_id = f'00{watch_id}'
        elif len(watch_id) == 3:
            watch_id = f'0{watch_id}'
        event = {
            'img_url':
            f'https://www.spc.noaa.gov/products/watch/{datetime.now().year}/ww{watch_id}_radar_init.gif',
            'pds': pds,
            'subject': f'{lines[7]} {area}',
            'ts': ingest.get_ts_from_bulletin(lines[9]),
            'type': 'sel',
            'url': url,
        }
    except:
        logging.warning(traceback.format_exc())
    return event
Пример #5
0
def process_filename(filename):
    try:
        events = []
        url = f'{LSR_URL}/{filename}'
        resp = client.get(url)
        lines = [line for line in resp.text.split('\n') if line.strip()]
        in_body = False
        first_line = None
        second_line = None
        remark_lines = []
        tz_code = lines[5].split(' ')[2]

        for line in lines:
            if '..REMARKS..' in line:
                in_body = True
                continue
            if in_body:
                if '&&' in line:
                    in_body = False
                    parsed_first_line = parse_first_line(first_line)
                    hazard = parsed_first_line['hazard']

                    if hazard in TRACKED_HAZARDS:
                        is_tornado = hazard == 'TORNADO'
                        parsed_second_line = parse_second_line(second_line, is_tornado)
                        time = f'{parsed_second_line["date"]} {parsed_first_line["time"]}'
                        report_ts = lsr_time_to_epoch(time, tz_code)
                        ts = ingest.get_ts_from_bulletin(lines[5].strip())
                        delta_minutes = int((ts - report_ts) / 60)
                        if delta_minutes > MINUTES_THRESHOLD:
                            continue
                        report = {
                            'hazard': hazard,
                            'source': parsed_second_line['source'],
                            'mag': parsed_second_line['mag'],
                            'measured': parsed_second_line['measured'],
                            'ts': report_ts,
                            'units': parsed_second_line['units'],
                        }
                        point = parsed_first_line['coords']
                        nearest = ingest.get_nearest(point, cities_tree, cities)
                        event = {
                            'geo': {
                                'point': point,
                                'city': nearest[0],
                                'st': nearest[1],
                                'distance': nearest[2],
                                'bearing': nearest[4]
                            },
                            'report': report,
                            'ts': ts,
                            'type': 'lsr',
                            'url': url,
                        }
                        events.append(event)
                    first_line = None
                    second_line = None
                    remark_lines = []
                elif not first_line:
                    first_line = line
                elif not second_line:
                    second_line = line
                else:
                    remark_lines.append(line)
    except Exception as e:
        print(e)
        logging.warning(traceback.format_exc())
        return None
    return events