Add `--since-last` and `--no-save-date` options to UNIX client
The date a file is parsed is now saved in an xattr, unless --no-save-date (-n) is passed. With this xattr, the user can filter entries with to ones posted since the last parse-date using --since-last (-S).
This commit is contained in:
parent
d1044e0d2b
commit
e21895cbfc
|
@ -261,18 +261,6 @@
|
||||||
new-string))
|
new-string))
|
||||||
|
|
||||||
|
|
||||||
;; List of entries updated/published since last feed parsing
|
|
||||||
;;(define (latest-entries feed-path)
|
|
||||||
;; (let* ([feed (call-with-input-file feed-path read-feed)]
|
|
||||||
;; [xattr-last-update (get-xattr feed-path "user.feedsnake.parsed")]
|
|
||||||
;; [last-update (if xattr-last-update
|
|
||||||
;; (rfc339-string->date xattr-last-update)
|
|
||||||
;; (date->utc-date (make-date 0 0 0 0 01 01 1971)))])
|
|
||||||
;; (set-xattr feed-path "user.feedsnake.parsed"
|
|
||||||
;; (date->rfc339-string (current-date-utc)))
|
|
||||||
;; (entries-since feed last-update)))
|
|
||||||
|
|
||||||
|
|
||||||
;; List of all entries of the feed
|
;; List of all entries of the feed
|
||||||
(define (all-entries feed)
|
(define (all-entries feed)
|
||||||
(car (alist-ref 'entries feed)))
|
(car (alist-ref 'entries feed)))
|
||||||
|
@ -362,8 +350,10 @@
|
||||||
(chicken base) (chicken file) (chicken file posix) (chicken io)
|
(chicken base) (chicken file) (chicken file posix) (chicken io)
|
||||||
(chicken port) (chicken process-context) (chicken process-context posix)
|
(chicken port) (chicken process-context) (chicken process-context posix)
|
||||||
srfi-1 srfi-19
|
srfi-1 srfi-19
|
||||||
|
date-strings
|
||||||
feedsnake feedsnake-helpers
|
feedsnake feedsnake-helpers
|
||||||
getopt-long)
|
getopt-long
|
||||||
|
xattr)
|
||||||
|
|
||||||
|
|
||||||
(define *help-msg*
|
(define *help-msg*
|
||||||
|
@ -388,7 +378,13 @@
|
||||||
(since
|
(since
|
||||||
"Output entries after the given date, in YYYY-MM-DD hh:mm:ss format."
|
"Output entries after the given date, in YYYY-MM-DD hh:mm:ss format."
|
||||||
(single-char #\s)
|
(single-char #\s)
|
||||||
(value (required DATETIME)))))
|
(value (required DATETIME)))
|
||||||
|
(since-last
|
||||||
|
"Output entries dating from the last saved parsing of the file."
|
||||||
|
(single-char #\S))
|
||||||
|
(no-save-date
|
||||||
|
"Don't save the date of this parsing in cache; to avoid influencing since-last."
|
||||||
|
(single-char #\n))))
|
||||||
|
|
||||||
|
|
||||||
;; Prints cli usage to stderr.
|
;; Prints cli usage to stderr.
|
||||||
|
@ -433,7 +429,13 @@
|
||||||
[output-dir (alist-ref 'outdir args)]
|
[output-dir (alist-ref 'outdir args)]
|
||||||
[output (or (alist-ref 'output args) output-dir)]
|
[output (or (alist-ref 'output args) output-dir)]
|
||||||
[template (if output-dir *maildir-template* *mbox-template*)]
|
[template (if output-dir *maildir-template* *mbox-template*)]
|
||||||
[filter (entry-filter args)])
|
[filter (entry-filter feed-pair args)])
|
||||||
|
|
||||||
|
;; Save the parsing date, unless the user doesn't want that
|
||||||
|
(if (not (alist-ref 'no-save-date args))
|
||||||
|
(set-xattr (first feed-pair) "user.feedsnake.parsed"
|
||||||
|
(date->rfc339-string (current-date-utc))))
|
||||||
|
|
||||||
(cond
|
(cond
|
||||||
[output
|
[output
|
||||||
(write-entries-to-file (filter-entries feed filter) template output)]
|
(write-entries-to-file (filter-entries feed filter) template output)]
|
||||||
|
@ -445,18 +447,26 @@
|
||||||
|
|
||||||
|
|
||||||
;; Construct a filter function for feeds, given the script's arguments
|
;; Construct a filter function for feeds, given the script's arguments
|
||||||
(define (entry-filter args)
|
(define (entry-filter feed-pair args)
|
||||||
(let* ([since-string (alist-ref 'since args)]
|
(let* ([since-string (alist-ref 'since args)]
|
||||||
[since (if since-string
|
[since (if since-string
|
||||||
(date->utc-date (string->date since-string "~Y-~m-~d ~H:~M:~S"))
|
(date->utc-date (string->date since-string "~Y-~m-~d ~H:~M:~S"))
|
||||||
#f)]
|
#f)]
|
||||||
[entry-date (lambda (entry)
|
[entry-date (lambda (entry)
|
||||||
(or (alist-car-ref 'updated entry)
|
(or (alist-car-ref 'updated entry)
|
||||||
(alist-car-ref 'published entry)))])
|
(alist-car-ref 'published entry)))]
|
||||||
|
[last-update (or
|
||||||
|
(date->utc-date
|
||||||
|
(rfc339-string->date
|
||||||
|
(get-xattr (first feed-pair) "user.feedsnake.parsed")))
|
||||||
|
(date->utc-date (make-date 0 0 0 0 01 01 1971)))])
|
||||||
(lambda (entry)
|
(lambda (entry)
|
||||||
(if since
|
(cond [since
|
||||||
(date>=? (entry-date entry) since)
|
(date>=? (entry-date entry) since)]
|
||||||
#t))))
|
[(alist-ref 'since-last args)
|
||||||
|
(date>=? (entry-date entry) last-update)]
|
||||||
|
[#t
|
||||||
|
#t]))))
|
||||||
|
|
||||||
|
|
||||||
;; Supposed config root of the user (as per XDG, or simple ~/.config)
|
;; Supposed config root of the user (as per XDG, or simple ~/.config)
|
||||||
|
|
Ŝarĝante…
Reference in New Issue