All Projects → SebastiaanKlippert → go-soda

SebastiaanKlippert / go-soda

Licence: MIT license
Socrata Open Data API (SODA) GET client for Golang

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to go-soda

data-analysis-using-python
Data Analysis Using Python: A Beginner’s Guide Featuring NYC Open Data
Stars: ✭ 81 (+102.5%)
Mutual labels:  socrata, socrata-open-data-api
awesome-yaml
YAML awesomeness
Stars: ✭ 36 (-10%)
Mutual labels:  opendata
coronavirus-dresden
Collects official SARS-CoV-2 infection statistics published by the city of Dresden.
Stars: ✭ 19 (-52.5%)
Mutual labels:  opendata
mango
Core utility library & data connectors designed for simpler usage in Scala
Stars: ✭ 41 (+2.5%)
Mutual labels:  concurrent
gini
A fast SAT solver
Stars: ✭ 139 (+247.5%)
Mutual labels:  concurrent
homebridge-airrohr
HomeBridge module for the DIY luftdaten.info particulates sensor. See http://luftdaten.info how to build your own
Stars: ✭ 48 (+20%)
Mutual labels:  opendata
2017-wmata-ridership-data
Intraday ridership data from Washington Metro Area Transit Authority for 2009 and 2017 inaugurations and the Women's March.
Stars: ✭ 15 (-62.5%)
Mutual labels:  opendata
rhdx
R package to interact with the Humanitarian Data Exchange portal - http://dickoa.gitlab.io/rhdx/
Stars: ✭ 20 (-50%)
Mutual labels:  opendata
opendata
Finland national open data portal (avoindata.fi) source code.
Stars: ✭ 27 (-32.5%)
Mutual labels:  opendata
django-calaccess-raw-data
A Django app to download, extract and load campaign finance and lobbying activity data from the California Secretary of State's CAL-ACCESS database
Stars: ✭ 61 (+52.5%)
Mutual labels:  opendata
fdnssearch
Swiftly search FDNS datasets from Rapid7 Open Data
Stars: ✭ 19 (-52.5%)
Mutual labels:  opendata
effector-reeffect
Concurrent effects for Effector ☄️
Stars: ✭ 56 (+40%)
Mutual labels:  concurrent
talepy
📚Coordinate "transactions" across a number of services in python
Stars: ✭ 20 (-50%)
Mutual labels:  concurrent
practice
Java并发编程与高并发解决方案:http://coding.imooc.com/class/195.html Java开发企业级权限管理系统:http://coding.imooc.com/class/149.html
Stars: ✭ 39 (-2.5%)
Mutual labels:  concurrent
goroutines
provides utilities to perform common tasks on goroutines
Stars: ✭ 19 (-52.5%)
Mutual labels:  concurrent
coletores
Coletores de dados sobre remunerações do sistema de justiça brasileiro
Stars: ✭ 18 (-55%)
Mutual labels:  opendata
Covid19arData
Data COVID-19 Argentina actualizada y en formatos abiertos.
Stars: ✭ 51 (+27.5%)
Mutual labels:  opendata
java-multithread
Códigos feitos para o curso de Multithreading com Java, no canal RinaldoDev do YouTube.
Stars: ✭ 24 (-40%)
Mutual labels:  concurrent
open-geoscience-repository
Open geoscience datasets available in open databases from Google Drive, SEG Wiki, and US DoE Geothermal Data Repository OpenEi
Stars: ✭ 83 (+107.5%)
Mutual labels:  opendata
municipios-br
Dados em formato aberto sobre municípios e unidades federativas do Brasil.
Stars: ✭ 58 (+45%)
Mutual labels:  opendata

GoDoc Build & test codecov Go Report Card

go-soda

Socrata Open Data API (SODA) GET client for Golang

SODAGopherLove

For SODA docs see http://dev.socrata.com

Features

This is a simple client for get requests only. The client provides basic structs for querying and filtering the database. Although all operations are supported most are just provided as a string to allow for all kind of complex queries.

Install

Just go get it

go get -u github.com/SebastiaanKlippert/go-soda

GetRequest

The default GetRequest struct is not safe for use in multiple goroutines, create one for each goroutine or use the OffsetGetRequest.

OffsetGetRequest

The OffsetGetRequest is a wrapper around the GetRequest and provides an easy offset counter to get loads of data. It can be shared by multiple goroutines to get your data a lot faster.

Metadata

For each GetRequest you can request metadata (using a separate API call). The metadata contains info about the dataset like creation and update times, licensing info and advanced column info.

sodareq := soda.NewGetRequest("https://data.ct.gov/resource/y6p2-px98", "")
metadata, err := sodareq.Metadata.Get()

GetRequest sample

See the test file for more examples.

func QuerySample() {

	sodareq := soda.NewGetRequest("https://data.ct.gov/resource/y6p2-px98", "")

	//count all records
	count, err := sodareq.Count()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(count)
	
	//get dataset last updated time
	modified, err := sodareq.Modified()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(modified)	

	//list all fields/columns
	fields, err := sodareq.Fields()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(fields)

	//get some JSON data using a complex query
	sodareq.Format = "json"
	sodareq.Query.Select = []string{"farm_name", "category", "item", "zipcode"}
	sodareq.Query.Where = `lower(farm_name) like '%sun%farm%' AND (item in('Radishes', 
	  'Cucumbers') OR lower(item) like '%flower%')`
	sodareq.Query.Limit = 1000
	sodareq.Query.AddOrder("farm_name", soda.DirAsc)
	sodareq.Query.AddOrder("category", soda.DirDesc)

	//count this result first
	querycount, err := sodareq.Count()
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(querycount)

	//get the results
	resp, err := sodareq.Get()
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	rawresp, _ := ioutil.ReadAll(resp.Body)
	fmt.Println(string(rawresp))
}

func JSONSample() {

	sodareq := soda.NewGetRequest("https://data.ct.gov/resource/y6p2-px98", "")

	//get some JSON data
	sodareq.Format = "json"
	sodareq.Filters["item"] = "Radishes"
	sodareq.Query.Limit = 10

	resp, err := sodareq.Get()
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	results := make([]map[string]interface{}, 0)
	err = json.NewDecoder(resp.Body).Decode(&results)
	if err != nil {
		log.Fatal(err)
	}

	//Process data here
	for _, r := range results {
		fmt.Println(r["farm_name"], r["item"])
	}
}

func CSVSample() {
	sodareq := soda.NewGetRequest("https://data.ct.gov/resource/y6p2-px98", "")
	sodareq.Format = "csv"
	sodareq.Filters["item"] = "Radishes"
	sodareq.Query.Limit = 10

	resp, err := sodareq.Get()
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()

	//Process data here
	csvreader := csv.NewReader(resp.Body)
	for {
		record, err := csvreader.Read()
		if err == io.EOF {
			break
		}
		if err != nil {
			log.Fatal(err)
		}
		fmt.Println(record)
	}
}

OffsetGetRequest sample

Get all data in batches of 2000 rows using 4 goroutines

func GetAllData() error {

	gr := soda.NewGetRequest("https://data.ct.gov/resource/y6p2-px98", "")
	gr.Format = "json"
	gr.Query.AddOrder("zipcode", soda.DirAsc)

	ogr, err := soda.NewOffsetGetRequest(gr)
	if err != nil {
		return err
	}

	for i := 0; i < 4; i++ {

		ogr.Add(1)
		go func() {
			defer ogr.Done()

			for {
				resp, err := ogr.Next(2000)
				if err == soda.ErrDone {
					break
				}
				if err != nil {
					log.Fatal(err)
				}

				results := make([]map[string]interface{}, 0)
				err = json.NewDecoder(resp.Body).Decode(&results)
				resp.Body.Close()
				if err != nil {
					log.Fatal(err)
				}
				//Process your data
			}
		}()

	}
	ogr.Wait()

	return nil
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].