-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdump-dolt-calendar.rkt
66 lines (53 loc) · 2.2 KB
/
dump-dolt-calendar.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#lang racket/base
(require db
gregor
racket/cmdline
racket/string
racket/system)
(define base-folder (make-parameter "/var/tmp/dolt/earnings"))
(define as-of-date (make-parameter (~t (today) "yyyy-MM-dd")))
(define db-user (make-parameter "user"))
(define db-name (make-parameter "local"))
(define db-pass (make-parameter ""))
(command-line
#:program "racket dump-dolt-calendar.rkt"
#:once-each
[("-b" "--base-folder") folder
"Base dolt folder. Defaults to /var/tmp/dolt/earnings"
(base-folder folder)]
[("-d" "--date") date
"Final date for history retrieval. Defaults to today"
(as-of-date date)]
[("-n" "--db-name") name
"Database name. Defaults to 'local'"
(db-name name)]
[("-p" "--db-pass") password
"Database password"
(db-pass password)]
[("-u" "--db-user") user
"Database user name. Defaults to 'user'"
(db-user user)])
(define dbc (postgresql-connect #:user (db-user) #:database (db-name) #:password (db-pass)))
; earnings-calendar
(system (string-append "cd " (base-folder) "; /usr/local/bin/dolt sql -q \"delete from earnings_calendar where date >= '" (as-of-date) "'\";"))
(define earnings-calendar-file (string-append (base-folder) "/earnings-calendar-" (as-of-date) ".csv"))
(call-with-output-file* earnings-calendar-file
(λ (out)
(displayln "act_symbol,date,when" out)
(for-each (λ (row)
(displayln (string-join (vector->list row) ",") out))
(query-rows dbc "
select
act_symbol::text,
date::text,
coalesce(\"when\"::text, '')
from
zacks.earnings_calendar
where
date >= $1::text::date
"
(as-of-date))))
#:exists 'replace)
(system (string-append "cd " (base-folder) "; /usr/local/bin/dolt table import -u earnings_calendar earnings-calendar-" (as-of-date) ".csv"))
(system (string-append "cd " (base-folder) "; /usr/local/bin/dolt add earnings_calendar; "
"/usr/local/bin/dolt commit -m 'earnings_calendar " (as-of-date) " update'; /usr/local/bin/dolt push --silent"))