summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmaan Bhojwani <me@armaanb.net>2021-11-27 16:57:25 -0500
committerArmaan Bhojwani <me@armaanb.net>2021-11-27 16:57:25 -0500
commitfe973842759bbe6c13952e53f9ae9775454d8b35 (patch)
tree7e3b43138d97eb30d7a26146575d82ad88636fc6
parent50fd113f77b184baada5ba0aba933ef76c83fbb9 (diff)
downloadbettersearch-fe973842759bbe6c13952e53f9ae9775454d8b35.tar.gz
Add basic web server stuff
-rw-r--r--README3
-rw-r--r--bettersearch.rkt24
-rw-r--r--blacklist.rkt11
-rw-r--r--server.rkt35
4 files changed, 66 insertions, 7 deletions
diff --git a/README b/README
new file mode 100644
index 0000000..88e5c09
--- /dev/null
+++ b/README
@@ -0,0 +1,3 @@
+Web search that sucks a little bit less
+
+https://search.armaanb.net
diff --git a/bettersearch.rkt b/bettersearch.rkt
index 81c6f53..f3acf79 100644
--- a/bettersearch.rkt
+++ b/bettersearch.rkt
@@ -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))
@@ -17,9 +23,19 @@
(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))
+)
diff --git a/blacklist.rkt b/blacklist.rkt
index 3791a38..4374c06 100644
--- a/blacklist.rkt
+++ b/blacklist.rkt
@@ -4,13 +4,18 @@
(define blacklist
'(
- ; social_media
- "www.facebook.com"
+ ; Social Media
"facebook.com"
"instagram.com"
+ "reddit.com"
+ "tiktok.com"
"twitter.com"
- ; "stackexchange"
+ ; Video Hosting
+ "youtube.com"
+ "vimeo.com"
+
+ ; Stack Exchange
"askubuntu.com"
"blogoverflow.com"
"mathoverflow.net"
diff --git a/server.rkt b/server.rkt
new file mode 100644
index 0000000..7f7562f
--- /dev/null
+++ b/server.rkt
@@ -0,0 +1,35 @@
+#lang racket
+
+(require web-server/servlet)
+(require web-server/formlets)
+(require web-server/servlet-env)
+
+(require "bettersearch.rkt")
+
+(define-values (dispatch generate-url)
+ (dispatch-rules
+ [("") do-index]
+ [("search") do-search]
+ ))
+
+(define (do-search req)
+ (define binds (request-bindings req))
+ (define query (if
+ (exists-binding? 'q binds)
+ (extract-binding/single 'q binds)
+ ""))
+
+ (if (non-empty-string? query)
+ (response/xexpr `(html
+ (h1 "Search results")
+ (fetch-results query)
+ ))
+ (response/xexpr `(html
+ (h1 "ho")
+ ))
+ )
+ )
+
+(serve/servlet dispatch
+ #:command-line? #t
+ #:servlet-regexp #rx"")