]> git.armaanb.net Git - bettersearch.git/blobdiff - bettersearch.rkt
Add basic web server stuff
[bettersearch.git] / bettersearch.rkt
index 81c6f5311b285066af3042296f7c00bbb8a40734..f3acf79eee4fbcc116c41a5697d7f3e53e8d69e8 100644 (file)
@@ -5,6 +5,12 @@
 
 (require "blacklist.rkt")
 
+(define (member-match? itm lst)
+  (ormap (lambda (i)
+          (regexp-match? (regexp i) itm))
+        lst))
+
+(define (get-results query)
 (define engine (string->url
                 "https://search.trom.tf/search?q=facebook&format=json"))
 (define response (get-pure-port engine))
     (lambda ()
       (read-json))))
 
-; Convert results to net/url format
+; Parse and filter results
+; TODO: replace this with tail-call recursion and return instead of printing
 (for-each (lambda (i)
-           (define result-url (string->url (hash-ref i 'url)))
-           (unless (member (url-host result-url) blacklist)
-             (writeln (url-host result-url))))
+           (define result-title (hash-ref i 'title ""))
+           (define result-url (url-host (string->url (hash-ref i 'url ""))))
+           (define result-content (hash-ref i 'content ""))
+
+           (unless (member-match? result-url blacklist)
+             (writeln result-title)
+             (writeln result-url)
+             (writeln result-content)
+             (writeln "")
+
+             ))
          (hash-ref json 'results))
+)