github.com/h00s/goseismic

Library for receiving (near) realtime notifications about earthquakes using websockets


License
MIT
Install
go get github.com/h00s/goseismic

Documentation

goseismic

Travis CI Build Status

goseismic is library for receiving (near) realtime notifications about earthquakes using websockets from SeismicPortal. Using goseismic, received JSON message is parsed to goseismic.Event and sent to channel when an event is inserted or updated. Depending on the event, you can use bots, push notification etc. to further process the information.

Installation

go get -u github.com/h00s/goseismic

Usage

Information about earthquake events are sent in JSON thru websockets. This is example of one received event:

{
  "action":"create",
  "data":{
    "geometry":{
      "type":"Point",
      "coordinates":[
        -121.2,
        36.6,
        -4.0
      ]
    },
    "type":"Feature",
    "id":"20201230_0000082",
    "properties":{
      "lastupdate":"2020-12-30T08:47:00.0Z",
      "magtype":"md",
      "evtype":"ke",
      "lon":-121.2,
      "auth":"NC",
      "lat":36.6,
      "depth":4.0,
      "unid":"20201230_0000082",
      "mag":2.4,
      "time":"2020-12-30T08:45:29.9Z",
      "source_id":"934165",
      "source_catalog":"EMSC-RTS",
      "flynn_region":"CENTRAL CALIFORNIA"
    }
  }
}

Possible values for action are created or updated depending if it's new event or update on one of the previous events.

Received events are parsed and sent to Seismic.Events channel which you can read and further process. This is simple example how to receive events and display them (check example/main.go for comments):

package main

import (
	"log"
	"os"
	"os/signal"

	"github.com/h00s/goseismic"
)

func main() {
	s := goseismic.NewSeismic()
	s.Connect()
	defer s.Disconnect()

	interrupt := make(chan os.Signal, 1)
	signal.Notify(interrupt, os.Interrupt)

	for {
		select {
		case e := <-s.Events:
			log.Println(e)
		case <-interrupt:
			return
		}
	}
}