From 2700cdeea3bf9286a60160b75f91db3100ef825a Mon Sep 17 00:00:00 2001 From: VaclavT Date: Sun, 21 Feb 2021 21:53:45 +0100 Subject: [PATCH] small lisp updates --- .gitignore | 1 + stdlib/stdlib.lisp | 6 ++++++ tmp/divi-dates.lsp | 29 +++++++++++++++-------------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index ff9804d..ab21d4a 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ build ml .DS_Store CMakeFiles +Testing diff --git a/stdlib/stdlib.lisp b/stdlib/stdlib.lisp index 51dbdad..f52c40e 100644 --- a/stdlib/stdlib.lisp +++ b/stdlib/stdlib.lisp @@ -38,6 +38,9 @@ ; return fourth element of list (defun fourth (l) (index l 3)) +; return fifth element of list +(defun fifth (l) (index l 4)) + ; from list of lists creates csv string @@ -61,3 +64,6 @@ rows_str )) + + +(defun setq (var val) (define var val)) \ No newline at end of file diff --git a/tmp/divi-dates.lsp b/tmp/divi-dates.lsp index 2321e9e..dfd8f92 100644 --- a/tmp/divi-dates.lsp +++ b/tmp/divi-dates.lsp @@ -1,4 +1,4 @@ - +; (print (make-csv (divi-dates "2021-02-01"))) (defun divi-dates (date-str) (do (define curl_cmd (+ "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=" date-str " 2>/dev/null")) @@ -13,20 +13,21 @@ (define rows (index (index calendar_data 1) 1)) ; (define csv_list '()) - (define csv_list '("symbol" "ex-date" "pay-date" "div-rate")) - (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 exdate (second (first (filter (lambda (x) (= (first x) "dividend_Ex_Date")) e)))) - (define paydate (second (first (filter (lambda (x) (= (first x) "payment_Date")) e)))) - (define rdate (second (first (filter (lambda (x) (= (first x) "record_Date")) e)))) + (define csv_list '(("symbol" "ex-date" "pay-date" "div-rate"))) + (if (!= 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 exdate (second (first (filter (lambda (x) (= (first x) "dividend_Ex_Date")) e)))) + (define paydate (second (first (filter (lambda (x) (= (first x) "payment_Date")) e)))) + (define rdate (second (first (filter (lambda (x) (= (first x) "record_Date")) e)))) + + (define csv_list (push csv_list (list symbol exdate paydate divrate)))) + '()) - (define csv_list (push csv_list (list symbol exdate paydate divrate)))) csv_list )) - -(print (make-csv (divi-dates "2021-02-01")))