cmd

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Copyright © 2022 NAME HERE <EMAIL ADDRESS>

Index

Constants

This section is empty.

Variables

View Source
var (
	Output       string
	StrStartTime string
	StrEndTime   string
	Debug        bool
)
View Source
var DownloadCmd = &cobra.Command{
	Use:   "download",
	Short: "Downloads historical insider data",
	Long: `Downloads historical insider data from Finansinspektions insynsregister. 
It will download data split daily for each day. Todays date will be all available data up until the execution time.
`,
	RunE: func(cmd *cobra.Command, args []string) error {
		logger := utils.NewLogger()
		startTime, err := time.Parse("2006-01-02", StrStartTime)
		if err != nil {
			return err
		}
		endTime := time.Now()
		if StrEndTime != "" {
			endTime, err = time.Parse("2006-01-02", StrEndTime)
			if err != nil {
				return err
			}
		}
		client := insider.NewClient(insider.WithDebug(Debug))

		tomorrow := time.Date(endTime.Year(), endTime.Month(), endTime.Day(), 0, 0, 0, 0, endTime.Location()).AddDate(0, 0, 1)
		for curr := startTime; curr.Before(tomorrow); curr = curr.AddDate(0, 0, 1) {
			output := fmt.Sprintf("%s/%s.csv", Output, curr.Format("2006-01-02"))
			logger.With(zap.Time("date", curr), zap.String("output", output)).Info("downloading file")
			t, err := client.GetTransactions(curr)
			if err != nil {
				logger.Fatal(err)
			}
			err = utils.SaveAsCSV(output, t)
			if err != nil {
				logger.Error(err)
			}
		}
		return nil
	},
}

DownloadCmd represents the download command

View Source
var RootCmd = &cobra.Command{
	Use:   "finansinspektionen",
	Short: "CLI tool for finansinspektionen",
	Long: `CLI tool for handling of data from finansinspektionen


go-finansinspektionen download --output=download -s 2020-01-01`,
}

RootCmd represents the base command when called without any subcommands

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the RootCmd.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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