]> git.armaanb.net Git - bettersearch.git/blob - bettersearch.rkt
Add basic web server stuff
[bettersearch.git] / bettersearch.rkt
1 #lang racket
2
3 (require json)
4 (require net/url)
5
6 (require "blacklist.rkt")
7
8 (define (member-match? itm lst)
9   (ormap (lambda (i)
10            (regexp-match? (regexp i) itm))
11          lst))
12
13 (define (get-results query)
14 (define engine (string->url
15                  "https://search.trom.tf/search?q=facebook&format=json"))
16 (define response (get-pure-port engine))
17 (define json-raw (port->string response))
18 (close-input-port response)
19
20 (define json
21   (with-input-from-string
22     json-raw
23     (lambda ()
24       (read-json))))
25
26 ; Parse and filter results
27 ; TODO: replace this with tail-call recursion and return instead of printing
28 (for-each (lambda (i)
29             (define result-title (hash-ref i 'title ""))
30             (define result-url (url-host (string->url (hash-ref i 'url ""))))
31             (define result-content (hash-ref i 'content ""))
32
33             (unless (member-match? result-url blacklist)
34               (writeln result-title)
35               (writeln result-url)
36               (writeln result-content)
37               (writeln "")
38
39               ))
40           (hash-ref json 'results))
41 )