Переглянути джерело

Use package for financisto

Innocenty Enikeew 11 роки тому
батько
коміт
b4dd5eae47
3 змінених файлів з 19 додано та 7 видалено
  1. 12 5
      src/financisto.lisp
  2. 5 1
      src/locations.lisp
  3. 2 1
      timeliner.asd

+ 12 - 5
src/financisto.lisp

@@ -1,3 +1,9 @@
+(in-package :cl-user)
+(defpackage #:timeliner.financisto
+  (:use :cl #:timeliner.utils :cl-mongo)
+  (:export #:import-financisto-events))
+(in-package #:timeliner.financisto)
+
 (defvar *financisto-backup-path* #P"/home/enikesha/Documents/backups/financisto/")
 
 (defun find-last-backup ()
@@ -44,14 +50,14 @@
          (from-decimals (expt 10d0 (parse-integer (getf from-currency :decimals))))
          (from-amount (/ (parse-integer (getf e :from-amount)) from-decimals))
          (from-balance (/ (gethash (parse-integer (getf from-account :-id)) balances 0) from-decimals))
-         (spend (< from-amount 0))         
+         (spend (< from-amount 0))
          (original-currency (gethash (parse-integer (getf e :original-currency-id)) currencies))
          (original-from-amount (and original-currency
                                     (/ (parse-integer (getf e :original-from-amount))
                                        (expt 10d0 (parse-integer (getf original-currency :decimals))))))
          (payee (gethash (parse-integer (getf e :payee-id)) (gethash "payee" db)))
          (category (gethash (parse-integer (getf e :category-id)) (gethash "category" db)))
-         
+
          (to-account (gethash (parse-integer (getf e :to-account-id)) accounts))
          (to-currency (and to-account (gethash (parse-integer (getf to-account :currency-id)) currencies)))
          (to-decimals (and to-account (expt 10d0 (parse-integer (getf to-currency :decimals)))))
@@ -90,7 +96,7 @@
                                       (getf to-account :currency-id)))
                           (abs to-amount))
                      (getf to-currency :symbol)
-                     to-balance (getf to-currency :symbol)                    
+                     to-balance (getf to-currency :symbol)
                      (getf e :note))
                     (format
                      nil "~A ~$~A~:[~*~;~:* (~$~A)~] ~A ~A~@[ for ~A~]~@[ at ~A~]~@[ (~A)~]. Balance ~$~A"
@@ -135,7 +141,7 @@
           (kv "note" (getf e :note))
           financisto)))))
 
-(defun financisto-import ()
+(defun import-financisto-events ()
   (let* ((filename (find-last-backup))
          (db (load-backup filename))
          (transactions (sort (loop for entity being the hash-values of (gethash "transactions" db)
@@ -163,7 +169,8 @@
                (if (and existing-doc (= new-ts (cl-mongo::raw
                                                 (get-element "ts" existing-doc))))
                    (get-element "loc" existing-doc)
-                   (point->doc (find-location-at new-ts))))
+                   (timeliner.locations:point->doc
+                    (timeliner.locations:find-location-at new-ts))))
            new-doc)
           (if existing-doc
               (progn

+ 5 - 1
src/locations.lisp

@@ -1,6 +1,10 @@
 (in-package :cl-user)
 (defpackage #:timeliner.locations
-  (:use :cl #:timeliner.utils :cl-mongo))
+  (:use :cl #:timeliner.utils :cl-mongo)
+  (:export
+   #:import-location-events
+   #:find-location-at
+   #:point->doc))
 (in-package #:timeliner.locations)
 
 

+ 2 - 1
timeliner.asd

@@ -46,7 +46,8 @@ THE SOFTWARE.
                :restas
                :parenscript
                :css-lite
-               :sqlite)
+               :sqlite
+               :gzip-stream)
   :components ((:module "src"
                 :components
                 ((:file "utils")