filter-pastes: use command-line; default is trial and case-insensitive

This commit is contained in:
pasterack 2016-01-05 15:00:18 -05:00
parent 70601a6330
commit 0fcd089549

View File

@ -16,6 +16,7 @@
; deletes pastes satisfying the given regexp pattern ; deletes pastes satisfying the given regexp pattern
(define (delete-pastes/pat pat #:trial? [trial? #f]) (define (delete-pastes/pat pat #:trial? [trial? #f])
(define count 0) (define count 0)
(define ci-pat (pregexp (string-append "(?i:" pat ")")))
(printf "searching for pastes with pattern: ~a" pat) (printf "searching for pastes with pattern: ~a" pat)
(when trial? (printf " (trial)")) (when trial? (printf " (trial)"))
(printf "\n") (printf "\n")
@ -23,7 +24,7 @@
(when (and (string=? (TYPE k) "hash") (HEXISTS k 'code)) ; valid paste (when (and (string=? (TYPE k) "hash") (HEXISTS k 'code)) ; valid paste
(define paste-contents (HGET/str k 'code)) (define paste-contents (HGET/str k 'code))
(define paste-dir (build-path "tmp" (bytes->path k))) (define paste-dir (build-path "tmp" (bytes->path k)))
(when (regexp-match pat paste-contents) (when (regexp-match ci-pat paste-contents)
(printf "deleting paste: ~a\n" k) (printf "deleting paste: ~a\n" k)
; (displayln paste-contents) ; (displayln paste-contents)
(when (directory-exists? paste-dir) (when (directory-exists? paste-dir)
@ -35,29 +36,34 @@
(set! count (add1 count))))) (set! count (add1 count)))))
(printf "deleted ~a pastes matching pattern ~a\n" count pat)) (printf "deleted ~a pastes matching pattern ~a\n" count pat))
(define pats (define default-pats
'("[Aa]mex" '("amex"
"[Vv]isa" "visa"
"[Mm]astercard" "mastercard"
"[Dd]iscover" "discover"
"rapidgator" "rapidgator"
"turbobit" "turbobit"
"[Bb]itcoin" "bitcoin"
"[Pp]ay[Pp]al" "paypal"
"Western Union" "Western Union"
"Money Gram" "Money Gram"
"[Ww][Mm][Zz]" "wmz"
"[Cc][Vv][Vv]" "cvv"
"Web Money" "Web Money"
"Perfect Money")) "Perfect Money"
"torrent"
"hacked"
"accounts"
"premium"))
(module+ main (module+ main
(define args (current-command-line-arguments)) (define trial-mode (make-parameter #t))
(cond (define pats
[(= 1 (vector-length args)) (command-line
(define pat (vector-ref args 0)) #:once-each
(delete-pastes/pat pat)] [("--delete") "Do the deletions (default is trial mode)"
[else (trial-mode #f)]
(displayln "no args, using default") #:args args
(if (null? args) default-pats args)))
(for ([p pats]) (for ([p pats])
(delete-pastes/pat p))])) (delete-pastes/pat p #:trial? (trial-mode))))