cnnfag

package module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2021 License: MIT Imports: 9 Imported by: 0

README

cnn-fear-and-greed-parse Go Reference example workflow

Golang package to fetch and parse data from https://money.cnn.com/data/fear-and-greed/

Usage example:

package main

import (
	"encoding/json"
	"fmt"
	CNNParse "github.com/wildsurfer/cnn-fear-and-greed-parse"
)

func main() {
	result, err := CNNParse.Parse()
	if err != nil {
		panic(err)
	}

	b, _ := json.Marshal(result)
	fmt.Println(string(b))
}
Output
{
  "imageUrl":"http://markets.money.cnn.com/Marketsdata/uploadhandler/z748f7c0aza9d607b00bf84c6a8b0283e2745ded10.png",
  "now":{
    "value":44,
    "text":"Fear"
  },
  "previousClose":{
    "value":44,
    "text":"Fear"
  },
  "oneWeekAgo":{
    "value":49,
    "text":"Neutral"
  },
  "oneMonthAgo":{
    "value":48,
    "text":"Neutral"
  },
  "oneYearAgo":{
    "value":25,
    "text":"Extreme Fear"
  },
  "lastUpdateDate":"2020-03-30T15:50:00-05:00"
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyField = errors.New("at least one field is empty")
View Source
var ErrHTTPNon200 = errors.New("http status code isn't 200")
View Source
var ErrImgLoadNon200 = errors.New("image download failed, non 200 response code")
View Source
var ErrReadingBytes = errors.New("reading image bytes failed")

Functions

This section is empty.

Types

type Result

type Result struct {
	ImageURL       string          `json:"imageUrl"`
	Now            ResultValueText `json:"now"`
	PreviousClose  ResultValueText `json:"previousClose"`
	OneWeekAgo     ResultValueText `json:"oneWeekAgo"`
	OneMonthAgo    ResultValueText `json:"oneMonthAgo"`
	OneYearAgo     ResultValueText `json:"oneYearAgo"`
	LastUpdateDate time.Time       `json:"lastUpdateDate"`
}

func Parse

func Parse() (Result, error)

Parse is the only method you need to get data from CNN's Fear & Greed page.

func (*Result) GetImageBytes added in v1.1.0

func (r *Result) GetImageBytes() ([]byte, error)

GetImageBytes gets image in bytes.

type ResultValueText

type ResultValueText struct {
	Value int    `json:"value"`
	Text  string `json:"text"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL