Giter Site home page Giter Site logo

capparselib's Introduction

capparselib

Coverage Status Build Status

This module parses and 'normalizes' alerts sent using the Common Alerting Protocol. It currently can handle XML in CAP1.1 and CAP1.2 format, and supports ATOM feeds.

This module originally returned an 'Event' object, but now simply returns a dictionary. It currently does not lookup geocode items or any other items, but please make a request if you want sample code to do this ([email protected]). Alert validation via signatures is also not supported, yet.

Installation

You can install it from source with:

$ python setup.py install

You can also install it directly with pip:

$ pip install capparselib

Usage

Basic usage includes (from the source directory):

>>> from capparselib.parsers import CAPParser
>>> f = r'test/data/weather.cap'
>>> src = open(f, 'r').read()
>>> alert_list = CAPParser(src).as_dict()

The CAPParser class returns a list of alerts, which are each a dictionary of items according to a hopefully logical mapping of fields. For instance, fields with names 'headline' (CAP1.2) and 'title' (CAP1.1) are both renamed to 'cap_headline'. Using the above basic usage example, you can then access fields as needed:

>>> alert = alert_list[0]
>>> alert['cap_sender']
    '[email protected]'
>>> alert.keys()
    ['cap_scope', 'cap_sender', 'cap_note', 'cap_status',
    'cap_id', 'cap_message_type', 'cap_sent', 'cap_info']
>>> alert['cap_info'].keys()
    ['cap_area', 'cap_sender', 'cap_expires', 'cap_severity',
    'cap_event', 'cap_certainty', 'cap_urgency', 'cap_event_code',
    'cap_effective', 'cap_description', 'cap_parameter', 'cap_headline',
    'cap_instruction', 'cap_category']
>>> alert['cap_info']['cap_severity']
    'Severe'

If you want to try another CAP parser, take a look at 'cap-alerts', located at: https://code.google.com/p/cap-alerts/

Or RCAP, for Ruby, located here: https://github.com/farrel/RCAP

capparselib's People

Contributors

kelvinn avatar pyup-bot avatar

Watchers

August Tu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.