mlisp/debug.lisp

69 lines
2.8 KiB
Common Lisp

(print "Debug starts")
; define a function `fact` that takes an argument `n`
; (defun fact (n)
; (if (<= n 1)
; 1
; (* n (fact (- n 1)))
; ))
; (print (fact 5))
; (define json_list (read-json "{\"k1\":\"v1\", \"k2\":42, \"k3\":[\"a\",123,true,false,null]}"))
; (print json_list)
; (for x json_list
; (print x))
; nefunguje - api.nasdaq.com
;(define nasdaq_headers (quote (("Accept" "application/json, text/plain, */*") ("Connection" "keep-alive") ("Origin" "https://www.nasdaq.com/") ("User-Agent" "Mozilla/5.0 (Windows NT 10.0)"))))
;(define json_list2 (read-json (read-url "https://api.nasdaq.com/api/calendar/dividends/?date=2021-02-01" nasdaq_headers)))
; (for x json_list2
; (print x))
;; (include "tmp/example.lisp")
;; (print "sorted: " (qs '(10 9 8 7 6 5 4 3 2 1)))
; (define csv (read-file "tmp/data.csv"))
; (define csv_list (parse-csv csv))
; (for x csv_list
; (print x))
;; (define web_page (read-url "https://query1.finance.yahoo.com/v7/finance/download/FDX?period1=1581272585&period2=1612894985&interval=1d&events=history&includeAdjustedClose=true"))
;; (print web_page)
;; (define fdx_list (parse-csv (index web_page 1)))
;; (print fdx_list)
(define curl "curl -H \"Accept: application/json, text/plain, */*\" -H \"Origin: https://www.nasdaq.com/\" -H \"User-Agent: Mozilla/5.0 (Windows NT 10.0)\" https://api.nasdaq.com/api/calendar/dividends/?date=2021-02-01 2>/dev/null")
(define curl_out (system-cmd curl))
(define json_list (read-json (last curl_out)))
;(print json_list)
(define data (first json_list))
;(print data)
;(print (index data 1)) ; druhy prvek
(define calendar (index data 1))
;(print calendar)
(define calendar_data (index (index calendar 0) 1))
;(print calendar_data)
(define header (index (index calendar_data 0) 1))
;(print header)
(define rows (index (index calendar_data 1) 1))
;(print rows)
(for e rows
; (("announcement_Date" "01/07/2021") ("companyName" "Itau Unibanco Banco Holding SA") ("dividend_Ex_Date" "02/01/2021") ("dividend_Rate" 0.003) ("indicated_Annual_Dividend" 0.033) ("payment_Date" "03/11/2021") ("record_Date" "02/02/2021") ("symbol" "ITUB"))
(define symbol (second (first (filter (lambda (x) (= (first x) "symbol")) e))))
(define divrate (second (first (filter (lambda (x) (= (first x) "dividend_Rate")) e))))
(define adate (second (first (filter (lambda (x) (= (first x) "announcement_Date")) e))))
(define name (second (first (filter (lambda (x) (= (first x) "companyName")) e))))
(define edate (second (first (filter (lambda (x) (= (first x) "dividend_Ex_Date")) e))))
(define pdate (second (first (filter (lambda (x) (= (first x) "payment_Date")) e))))
(define rdate (second (first (filter (lambda (x) (= (first x) "record_Date")) e))))
(print symbol edate pdate divrate)
)
(print "Debug ends")